diff --git a/.cproject b/.cproject new file mode 100644 index 000000000..b7df2348f --- /dev/null +++ b/.cproject @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 000000000..cc3714729 --- /dev/null +++ b/.project @@ -0,0 +1,27 @@ + + + org.eclipse.4diac.forte + + + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..8a2338826 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,221 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, AIT, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Michael Hofmann, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Thomas Strasser, +# * Martin Melik Merkumians +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +PROJECT(FORTE) + +SET(FORTE_BUILDSUPPORT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/buildsupport" CACHE PATH "forte build support directory.") +mark_as_advanced(FORTE_BUILDSUPPORT_DIRECTORY) +#http://www.varsanofiev.com/inside/eclipse_and_windows.htm + +#include forte cmake-functions +INCLUDE(${FORTE_BUILDSUPPORT_DIRECTORY}/forte.cmake) + +####################################################################################### +# Determine how to build FORTE +####################################################################################### +set(FORTE_BUILD_TYPE EXECUTABLE CACHE STRING "Build FORTE as an executable or as a library") +set_property(CACHE FORTE_BUILD_TYPE PROPERTY STRINGS EXECUTABLE STATIC_LIBRARY SHARED_LIBRARY) +mark_as_advanced(FORTE_BUILD_TYPE) + +####################################################################################### +# Determine the loglevel +####################################################################################### +set(FORTE_LOGLEVEL "LOGDEBUG" CACHE STRING "Loglevel to use") +set_property(CACHE FORTE_LOGLEVEL PROPERTY STRINGS LOGDEBUG LOGERROR LOGWARNING LOGINFO NOLOG) + +forte_add_definition("-D${FORTE_LOGLEVEL}") + +SET(FORTE_TRACE_EVENTS ON CACHE BOOL "FORTE will log the events received at and sent from function blocks") +mark_as_advanced(FORTE_TRACE_EVENTS) +if(FORTE_TRACE_EVENTS) +forte_add_definition("-DFORTE_TRACE_EVENTS") +endif(FORTE_TRACE_EVENTS) + +set(FORTE_SUPPORT_QUERY_CMD ON CACHE BOOL "Enable support for the query management commands") +mark_as_advanced(FORTE_SUPPORT_QUERY_CMD) +if(FORTE_SUPPORT_QUERY_CMD) + forte_add_definition("-DFORTE_SUPPORT_QUERY_CMD") +endif(FORTE_SUPPORT_QUERY_CMD) + +###################################################################################### +set(FORTE_SYSTEM_TESTS OFF CACHE BOOL "FORTE System Tests") +if(FORTE_SYSTEM_TESTS) +ENABLE_TESTING() +endif(FORTE_SYSTEM_TESTS) + +####################################################################################### +SET(FORTE_STRINGDICTFIXEDMEMORY OFF CACHE BOOL "FORTE string dict will reallocate memory if necessary when this flag is turned off") +mark_as_advanced(FORTE_STRINGDICTFIXEDMEMORY) + +if(FORTE_STRINGDICTFIXEDMEMORY) + forte_add_definition("-DFORTE_STRING_DICT_FIXED_MEMORY") +endif(FORTE_STRINGDICTFIXEDMEMORY) + +set(FORTE_SUPPORT_BOOT_FILE ON CACHE BOOL "Enable FORTE boot file loading on FORTE start-up") +mark_as_advanced(FORTE_SUPPORT_BOOT_FILE) +if(FORTE_SUPPORT_BOOT_FILE) + forte_add_definition("-DFORTE_SUPPORT_BOOT_FILE") + SET(FORTE_BootfileLocation "" CACHE STRING "Path to the bootfile, if same directory as forte executable leave empty, include trailing '/'!") + mark_as_advanced(FORTE_BootfileLocation) + SET(FORTE_BOOTFILELINEBUFSIZE "300" CACHE STRING "size of the line buffer for reading boot files") +endif(FORTE_SUPPORT_BOOT_FILE) + +set(FORTE_SUPPORT_MONITORING ON CACHE BOOL "Enable FORTE monitoring functionalities") +mark_as_advanced(FORTE_SUPPORT_MONITORING) +if(FORTE_SUPPORT_MONITORING) + forte_add_definition("-DFORTE_SUPPORT_MONITORING") +endif(FORTE_SUPPORT_MONITORING) + +if (WIN32) + if (MSVC) + set(FORTE_ADDITIONAL_CXX_FLAGS "/MP " CACHE STRING "Additional compile flags appended to CMAKE_CXX_FLAGS.") + mark_as_advanced(FORTE_ADDITIONAL_CXX_FLAGS) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FORTE_ADDITIONAL_CXX_FLAGS}") + endif(MSVC) +endif(WIN32) + + + +####################################################################################### +# Add subdirectories +####################################################################################### +ADD_SUBDIRECTORY(src) + + +####################################################################################### +# FORTE Tests +####################################################################################### +set(FORTE_TESTS OFF CACHE BOOL "Build Tests") +set(FORTE_TESTS_LINK_DIRS "" CACHE PATH "Test specific library directories") +set(FORTE_TESTS_INC_DIRS "" CACHE PATH "Test specific include directories") + + +IF(FORTE_TESTS) + enable_testing() + ADD_SUBDIRECTORY(tests) +ENDIF(FORTE_TESTS) + + +ADD_SUBDIRECTORY(systemtests) + +####################################################################################### +# FORTE forte_config.h +####################################################################################### + +SET(FORTE_TicksPerSecond "1000" CACHE STRING "forte sticks per second") +mark_as_advanced(FORTE_TicksPerSecond) + +SET(FORTE_TimeBaseUnitsPerSecond "1000000000" CACHE STRING "Defines the time base in units per second that will be used in the TIME data type, The default value 1000000000 means 1ns") +mark_as_advanced(FORTE_TimeBaseUnitsPerSecond) + +SET(FORTE_EventChainEventListSize "256" CACHE STRING "forte eventchain event list size") +mark_as_advanced(FORTE_EventChainEventListSize) + +SET(FORTE_EventChainExternalEventListSize "10" CACHE STRING "forte eventchain external event list size") +mark_as_advanced(FORTE_EventChainExternalEventListSize) + +SET(FORTE_CommunicationInterruptQueueSize "10" CACHE STRING "forte Communication interrupt queue size") +mark_as_advanced(FORTE_CommunicationInterruptQueueSize) + +SET(FORTE_IPLayerRecvBufferSize "1500" CACHE STRING "FORTE ip layer recv buffer size") +mark_as_advanced(FORTE_IPLayerRecvBufferSize) + +SET(FORTE_MGMCOMMANDPROTOCOL "DEV_MGR" CACHE STRING "forte management command protocol") +set_property(CACHE FORTE_MGMCOMMANDPROTOCOL PROPERTY STRINGS DEV_MGR) +mark_as_advanced(FORTE_MGMCOMMANDPROTOCOL) + +SET(FORTE_MGM_MAX_SUPPOERTED_NAME_HIERACHY "30" CACHE STRING "Max supported hierarchy that can be provided in a management commands") +mark_as_advanced(FORTE_MGM_MAX_SUPPOERTED_NAME_HIERACHY) + +SET(FORTE_STRINGDICTINITIALSTRINGBUFSIZE "8000" CACHE STRING "FORTE string dict's initial string buffer size") +mark_as_advanced(FORTE_STRINGDICTINITIALSTRINGBUFSIZE) + +SET(FORTE_STRINGDICTINITIALMAXNROFSTRINGS "300" CACHE STRING "FORTE string dict's initial max nr of strings") +mark_as_advanced(FORTE_STRINGDICTINITIALMAXNROFSTRINGS) + +if(FORTE_USE_64BIT_DATATYPES) + SET(MAX_TimeBaseUnitsPerSecond 1000000000) +else(FORTE_USE_64BIT_DATATYPES) + SET(MAX_TimeBaseUnitsPerSecond 1000000) +endif(FORTE_USE_64BIT_DATATYPES) + +if(${FORTE_TimeBaseUnitsPerSecond} GREATER ${MAX_TimeBaseUnitsPerSecond}) + MESSAGE("Forced FORTE_TimeBaseUnitsPerSecond to ${MAX_TimeBaseUnitsPerSecond}") + SET(FORTE_TimeBaseUnitsPerSecond ${MAX_TimeBaseUnitsPerSecond}) +endif(${FORTE_TimeBaseUnitsPerSecond} GREATER ${MAX_TimeBaseUnitsPerSecond}) + +forte_add_include_directories(${CMAKE_BINARY_DIR}) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/forte_config.h.in ${CMAKE_BINARY_DIR}/forte_config.new.h) +forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/forte_config.new.h ${CMAKE_BINARY_DIR}/forte_config.h) +file(REMOVE ${CMAKE_BINARY_DIR}/forte_config.new.h) + + +####################################################################################### +# Setup Forte-Executeable with all Functionblocks +####################################################################################### +GET_PROPERTY(SOURCE_CPP GLOBAL PROPERTY FORTE_SOURCE_CPP) +LIST(APPEND SOURCE_FILES_TMP ${SOURCE_CPP}) +GET_PROPERTY(SOURCE_C GLOBAL PROPERTY FORTE_SOURCE_C) +LIST(APPEND SOURCE_FILES_TMP ${SOURCE_C}) + +####################################################################################### +# Setup Forte-Executeable with all Functionblocks +####################################################################################### +GET_PROPERTY(SOURCE_TEST_CPP GLOBAL PROPERTY FORTE_TEST_SOURCE_CPP) +LIST(APPEND SOURCE_FILES_TMP ${SOURCE_TEST_CPP}) + +# Resolve to absolute path, Remove duplicate files, +FOREACH( FBLIB_FILE ${SOURCE_FILES_TMP}) + get_filename_component(mod_fblib_file ${FBLIB_FILE} ABSOLUTE) + STRING(REGEX MATCH ".*stringlist\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) + IF(NOT REGEX_STRINGS) + STRING(REGEX MATCH ".*forteinit\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) + ENDIF(NOT REGEX_STRINGS) + IF(NOT REGEX_STRINGS) + LIST(APPEND SOURCE_FILES ${mod_fblib_file}) + ENDIF() +ENDFOREACH(FBLIB_FILE) +LIST(REMOVE_DUPLICATES SOURCE_FILES) + +####################################################################################### +# Generate stringlist for every source file +####################################################################################### +SET(FORTE_LINKED_STRINGDICT ON CACHE BOOL "FORTE will resolve references to the stringdict at link-stage and not compile-stage. This will reduce compiletime if the stringdict changes.") +mark_as_advanced(FORTE_LINKED_STRINGDICT) + +SET(FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES ON CACHE BOOL "FORTE change the source-files if includes for the generated includes are missing.") +mark_as_advanced(FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES) + +if(FORTE_LINKED_STRINGDICT) + FOREACH( FBLIB_FILE ${SOURCE_FILES}) + # Do not pars stringlist, as these files will be generated + STRING(REGEX MATCH ".*stringlist\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) + IF(NOT REGEX_STRINGS) + STRING(REGEX MATCH ".*forteinit\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) + ENDIF(NOT REGEX_STRINGS) + IF(NOT REGEX_STRINGS) + # Just the File name + STRING(REGEX REPLACE ".*/" "" FBLIB_FILE_NAME ${FBLIB_FILE}) + STRING(REGEX REPLACE "\\." "_gen." FBLIB_FILE_NAME ${FBLIB_FILE_NAME}) + ADD_CUSTOM_COMMAND(OUTPUT ${FORTE_BINARY_DIR}/src_gen/${FBLIB_FILE_NAME} COMMAND ${CMAKE_COMMAND} -DFORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES:STRING="${FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES}" -DFORTE_SOURCE_DIR:STRING="${FORTE_SOURCE_DIR}/src" -DFORTE_BINARY_DIR:STRING="${FORTE_BINARY_DIR}/src_gen" -DFBLIB_FILE:STRING="${FBLIB_FILE}" -P ${FORTE_BUILDSUPPORT_DIRECTORY}/generate_stringlist_include_files.cmake MAIN_DEPENDENCY ${FBLIB_FILE}) + set_source_files_properties(${FORTE_BINARY_DIR}/src_gen/${FBLIB_FILE_NAME} HEADER_FILE_ONLY true) + #list(APPEND DEPENDENCY_FILES ${FORTE_BINARY_DIR}/${FBLIB_FILE_NAME}) + ENDIF(NOT REGEX_STRINGS) + ENDFOREACH(FBLIB_FILE) + # this is a hack; add_custom_target is always run, but we only want to run builds on modified files, maybe only valid for visual studio projects + add_library(forte_stringlist_externals STATIC ${SOURCE_FILES}) + ADD_DEPENDENCIES (forte forte_stringlist_externals) + #ADD_CUSTOM_TARGET(forte_stringlist_externals SOURCES ${SOURCE_FILES}) +endif(FORTE_LINKED_STRINGDICT) diff --git a/COPYING b/COPYING new file mode 100644 index 000000000..efe6672ca --- /dev/null +++ b/COPYING @@ -0,0 +1,220 @@ + +Note "EPL for FORTE Development": +Changes to the FORTE open source code have to be provided under the EPL, whereas +additions to the mentioned software inform of element types according to the +IEC 61499 and/or architecture specific modifications are seen as separate +modules of the mentioned software and can therefore be distributed in +conjunction with the mentioned software under their own license agreement, and +are not derivative works of the mentioned software. + + + +Eclipse Public License - v 1.0 + +THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC +LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM +CONSTITUTES RECIPIENT’S ACCEPTANCE OF THIS AGREEMENT. + +1. DEFINITIONS + +"Contribution" means: + + a) in the case of the initial Contributor, the initial code and + documentation distributed under this Agreement, and + b) in the case of each subsequent Contributor: + + i)changes to the Program, and + + ii)additions to the Program; + + where such changes and/or additions to the Program originate from and are + distributed by that particular Contributor. A Contribution 'originates' from + a Contributor if it was added to the Program by such Contributor itself or + anyone acting on such Contributor’s behalf. Contributions do not include + additions to the Program which: (i) are separate modules of software + distributed in conjunction with the Program under their own license + agreement, and (ii) are not derivative works of the Program. + +"Contributor" means any person or entity that distributes the Program. + +"Licensed Patents " mean patent claims licensable by a Contributor which are +necessarily infringed by the use or sale of its Contribution alone or when +combined with the Program. + +"Program" means the Contributions distributed in accordance with this Agreement. + +"Recipient" means anyone who receives the Program under this Agreement, +including all Contributors. + +2. GRANT OF RIGHTS + +a) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free copyright license to + reproduce, prepare derivative works of, publicly display, publicly perform, + distribute and sublicense the Contribution of such Contributor, if any, and + such derivative works, in source code and object code form. + +b) Subject to the terms of this Agreement, each Contributor hereby grants + Recipient a non-exclusive, worldwide, royalty-free patent license under + Licensed Patents to make, use, sell, offer to sell, import and otherwise + transfer the Contribution of such Contributor, if any, in source code and + object code form. This patent license shall apply to the combination of the + Contribution and the Program if, at the time the Contribution is added by the + Contributor, such addition of the Contribution causes such combination to be + covered by the Licensed Patents. The patent license shall not apply to any + other combinations which include the Contribution. No hardware per se is + licensed hereunder. + +c) Recipient understands that although each Contributor grants the licenses to + its Contributions set forth herein, no assurances are provided by any + Contributor that the Program does not infringe the patent or other + intellectual property rights of any other entity. Each Contributor disclaims + any liability to Recipient for claims brought by any other entity based on + infringement of intellectual property rights or otherwise. As a condition to + exercising the rights and licenses granted hereunder, each Recipient hereby + assumes sole responsibility to secure any other intellectual property rights + needed, if any. For example, if a third party patent license is required to + allow Recipient to distribute the Program, it is Recipient’s responsibility + to acquire that license before distributing the Program. + +d) Each Contributor represents that to its knowledge it has sufficient copyright + rights in its Contribution, if any, to grant the copyright license set forth + in this Agreement. + +3. REQUIREMENTS + +A Contributor may choose to distribute the Program in object code form under its +own license agreement, provided that: + + a) it complies with the terms and conditions of this Agreement; and + + b) its license agreement: + + i) effectively disclaims on behalf of all Contributors all warranties and + conditions, express and implied, including warranties or conditions of + title and non-infringement, and implied warranties or conditions of + merchantability and fitness for a particular purpose; + + ii) effectively excludes on behalf of all Contributors all liability for + damages, including direct, indirect, special, incidental and + consequential damages, such as lost profits; + + iii) states that any provisions which differ from this Agreement are + offered by that Contributor alone and not by any other party; and + + iv) states that source code for the Program is available from such + Contributor, and informs licensees how to obtain it in a reasonable + manner on or through a medium customarily used for software exchange. + +When the Program is made available in source code form: + + a) it must be made available under this Agreement; and + + b) a copy of this Agreement must be included with each copy of the Program. + +Contributors may not remove or alter any copyright notices contained within the +Program. + +Each Contributor must identify itself as the originator of its Contribution, if +any, in a manner that reasonably allows subsequent Recipients to identify the +originator of the Contribution. + +4. COMMERCIAL DISTRIBUTION + +Commercial distributors of software may accept certain responsibilities with +respect to end users, business partners and the like. While this license is +intended to facilitate the commercial use of the Program, the Contributor who +includes the Program in a commercial product offering should do so in a manner +which does not create potential liability for other Contributors. Therefore, if +a Contributor includes the Program in a commercial product offering, such +Contributor ("Commercial Contributor") hereby agrees to defend and indemnify +every other Contributor ("Indemnified Contributor") against any losses, damages +and costs (collectively "Losses") arising from claims, lawsuits and other legal +actions brought by a third party against the Indemnified Contributor to the +extent caused by the acts or omissions of such Commercial Contributor in +connection with its distribution of the Program in a commercial product +offering. The obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In order +to qualify, an Indemnified Contributor must: a) promptly notify the Commercial +Contributor in writing of such claim, and b) allow the Commercial Contributor to +control, and cooperate with the Commercial Contributor in, the defense and any +related settlement negotiations. The Indemnified Contributor may participate in +any such claim at its own expense. + +For example, a Contributor might include the Program in a commercial product +offering, Product X. That Contributor is then a Commercial Contributor. If that +Commercial Contributor then makes performance claims, or offers warranties +related to Product X, those performance claims and warranties are such +Commercial Contributor’s responsibility alone. Under this section, the +Commercial Contributor would have to defend claims against the other +Contributors related to those performance claims and warranties, and if a court +requires any other Contributor to pay any damages as a result, the Commercial +Contributor must pay those damages. + +5. NO WARRANTY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS PROVIDED ON AN +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR +IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, +NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each +Recipient is solely responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its exercise of +rights under this Agreement , including but not limited to the risks and costs +of program errors, compliance with applicable laws, damage to or loss of data, +programs or equipment, and unavailability or interruption of operations. + +6. DISCLAIMER OF LIABILITY + +EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT NOR ANY +CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION LOST +PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +OUT OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS +GRANTED HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +7. GENERAL + +If any provision of this Agreement is invalid or unenforceable under applicable +law, it shall not affect the validity or enforceability of the remainder of the +terms of this Agreement, and without further action by the parties hereto, such +provision shall be reformed to the minimum extent necessary to make such +provision valid and enforceable. + +If Recipient institutes patent litigation against any entity (including a cross- +claim or counterclaim in a lawsuit) alleging that the Program itself (excluding +combinations of the Program with other software or hardware) infringes such +Recipient’s patent(s), then such Recipient’s rights granted under Section 2(b) +shall terminate as of the date such litigation is filed. + +All Recipient’s rights under this Agreement shall terminate if it fails to +comply with any of the material terms or conditions of this Agreement and does +not cure such failure in a reasonable period of time after becoming aware of +such noncompliance. If all Recipient’s rights under this Agreement terminate, +Recipient agrees to cease use and distribution of the Program as soon as +reasonably practicable. However, Recipient’s obligations under this Agreement +and any licenses granted by Recipient relating to the Program shall continue and +survive. + +Everyone is permitted to copy and distribute copies of this Agreement, but in +order to avoid inconsistency the Agreement is copyrighted and may only be +modified in the following manner. The Agreement Steward reserves the right to +publish new versions (including revisions) of this Agreement from time to time. +No one other than the Agreement Steward has the right to modify this Agreement. +The Eclipse Foundation is the initial Agreement Steward. The Eclipse Foundation +may assign the responsibility to serve as the Agreement Steward to a suitable +separate entity. Each new version of the Agreement will be given a distinguishing +version number. The Program (including Contributions) may always be distributed +subject to the version of the Agreement under which it was received. In addition, +after a new version of the Agreement is published, Contributor may elect to +distribute the Program (including its Contributions) under the new version. +Except as expressly stated in Sections 2(a) and 2(b) above, Recipient receives +no rights or licenses to the intellectual property of any Contributor under this +Agreement, whether expressly, by implication, estoppel or otherwise. All rights +in the Program not expressly granted under this Agreement are reserved. + +This Agreement is governed by the laws of the State of New York and the +intellectual property laws of the United States of America. No party to this +Agreement will bring a legal action under this Agreement more than one year +after the cause of action arose. Each party waives its rights to a jury trial in +any resulting litigation. \ No newline at end of file diff --git a/Doxyfile b/Doxyfile new file mode 100644 index 000000000..3e66fa9b1 --- /dev/null +++ b/Doxyfile @@ -0,0 +1,1032 @@ +# Doxyfile 1.4.2-20050421 +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. +PROJECT_NAME = FORTE + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. +PROJECT_NUMBER = 1.0 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. +OUTPUT_DIRECTORY = ./doc/api_doc + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). +#USE_WINDOWS_ENCODING = YES + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. +STRIP_FROM_PATH = ./src + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. +JAVADOC_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. +#DETAILS_AT_TOP = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. +INHERIT_DOCS = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +DISTRIBUTE_GROUP_DOC = NO + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. +TAB_SIZE = 8 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java sources +# only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. +GENERATE_DEPRECATEDLIST = YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. +SHOW_DIRECTORIES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the progam writes to standard output +# is used as the file version. See the manual for examples. +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. +INPUT = ./src + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm +FILE_PATTERNS = *.h *.cpp + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. +REFERENCES_RELATION = YES + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. +GENERATE_TREEVIEW = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_PREDEFINED tags. +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. +PREDEFINED = FORTE_LITTLE_ENDIAN FORTE_USE_64BIT_DATATYPES FORTE_USE_FLOAT_DATATYPES FORTE_USE_LREAL_DATATYPE FORTE_SUPPORT_ARRAYS + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) +HAVE_DOT = YES + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. +UML_LOOK = YES + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. +CALL_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. +#MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. +#MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. +SEARCHENGINE = NO + diff --git a/about.html b/about.html new file mode 100644 index 000000000..36b1354bd --- /dev/null +++ b/about.html @@ -0,0 +1,25 @@ + + + +About + + +

About This Content

+ +

August 31, 2015

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/buildsupport/GCov.cmake b/buildsupport/GCov.cmake new file mode 100644 index 000000000..5ed52f89d --- /dev/null +++ b/buildsupport/GCov.cmake @@ -0,0 +1,49 @@ +#******************************************************************************* +# * Copyright (c) 2014 ACIN and fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Martin Melik-Merkumians, Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +FIND_PROGRAM(GCOV_PATH gcov) +mark_as_advanced(GCOV_PATH) + +FIND_PROGRAM(LCOV_PATH lcov) +mark_as_advanced(LCOV_PATH) + +FIND_PROGRAM(GENHTML_PATH genhtml) +mark_as_advanced(GENHTML_PATH) + +IF(NOT GCOV_PATH) + MESSAGE(FATAL_ERROR "Error: gcov not found") +ENDIF() + +FUNCTION(SETUP_GCOV targetName testRunner outputName) + + IF(NOT LCOV_PATH) + MESSAGE(FATAL_ERROR "Error: lcov not found") + ENDIF() + + IF(NOT GENHTML_PATH) + MESSAGE(FATAL_ERROR "Error: genhtml not found") + ENDIF() + + # Setup target + ADD_CUSTOM_TARGET(${targetName} + ${LCOV_PATH} --directory . --zerocounters + + COMMAND ${testRunner} ${ARGV3} + + COMMAND ${LCOV_PATH} --directory . --capture --gcov-tool ${GCOV_PATH} --output-file ${outputName}.info + COMMAND ${LCOV_PATH} --remove ${outputName}.info 'tests/*' '/usr/*' --output-file ${outputName}.info.cleaned + COMMAND ${GENHTML_PATH} -o ${outputName} ${outputName}.info.cleaned --demangle-cpp --rc lcov_branch_coverage=1 + COMMAND ${CMAKE_COMMAND} -E remove ${outputName}.info ${outputName}.info.cleaned + + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + ) + +ENDFUNCTION() \ No newline at end of file diff --git a/buildsupport/forte.cmake b/buildsupport/forte.cmake new file mode 100644 index 000000000..897407aef --- /dev/null +++ b/buildsupport/forte.cmake @@ -0,0 +1,237 @@ +#******************************************************************************* +# * Copyright (c) 2010 -2014 Profactor GmbH, ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Michael Hofmann, Alois Zoitl, Gerhard Ebenhofer, Matthias Plash, Patrick Smejkal - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +MACRO(forte_add_subdirectory DIRECTORY) + SET(SOURCE_GROUP_BACKUP ${SOURCE_GROUP}) + SET(SOURCE_GROUP ${SOURCE_GROUP}\\${DIRECTORY}) + add_subdirectory(${DIRECTORY}) + SET(SOURCE_GROUP ${SOURCE_GROUP_BACKUP}) +ENDMACRO(forte_add_subdirectory) + +FUNCTION(forte_add_sourcefile_with_path_h) + FOREACH(ARG ${ARGV}) + SET_SOURCE_FILES_PROPERTIES(${ARG} PROPERTIES HEADER_FILE_ONLY TRUE) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_SOURCE_H ${ARG}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_SOURCE_H_GROUP ${SOURCE_GROUP}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_with_path_h) + +FUNCTION(forte_add_sourcefile_with_path_cpp) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_SOURCE_CPP ${ARG}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_SOURCE_CPP_GROUP ${SOURCE_GROUP}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_with_path_cpp) + +FUNCTION(forte_add_sourcefile_with_path_hcpp) + FOREACH(ARG ${ARGV}) + forte_add_sourcefile_with_path_h(${ARG}.h) + forte_add_sourcefile_with_path_cpp(${ARG}.cpp) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_with_path_hcpp) + +FUNCTION(forte_add_sourcefile_h) + FOREACH(ARG ${ARGV}) + forte_add_sourcefile_with_path_h(${CMAKE_CURRENT_SOURCE_DIR}/${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_h) + +FUNCTION(forte_add_sourcefile_with_path_hc) + FOREACH(ARG ${ARGV}) + forte_add_sourcefile_with_path_h(${ARG}.h) + forte_add_sourcefile_with_path_cpp(${ARG}.c) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_with_path_hc) + +FUNCTION(forte_add_sourcefile_hc) + FOREACH(ARG ${ARGV}) + forte_add_sourcefile_with_path_hc(${CMAKE_CURRENT_SOURCE_DIR}/${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_hc) + +FUNCTION(forte_add_sourcefile_c) + FOREACH(ARG ${ARGV}) + forte_add_sourcefile_with_path_c(${CMAKE_CURRENT_SOURCE_DIR}/${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_c) + +FUNCTION(forte_add_sourcefile_with_path_c) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_SOURCE_C ${ARG}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_SOURCE_C_GROUP ${SOURCE_GROUP}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_with_path_c) + +FUNCTION(forte_add_sourcefile_cpp) + FOREACH(ARG ${ARGV}) + forte_add_sourcefile_with_path_cpp(${CMAKE_CURRENT_SOURCE_DIR}/${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_cpp) + +FUNCTION(forte_add_sourcefile_hcpp) + FOREACH(ARG ${ARGV}) + forte_add_sourcefile_with_path_hcpp(${CMAKE_CURRENT_SOURCE_DIR}/${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_sourcefile_hcpp) + +FUNCTION(forte_add_include_directories) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_include_directories) + +FUNCTION(forte_remove_sourcefile_h) + GET_PROPERTY(SOURCE_H GLOBAL PROPERTY FORTE_SOURCE_H) + GET_PROPERTY(SOURCE_H_GROUP GLOBAL PROPERTY FORTE_SOURCE_H_GROUP) + FOREACH(ARG ${ARGV}) + LIST(LENGTH SOURCE_H LIST_LEN) + MATH(EXPR LIST_LEN ${LIST_LEN}-1) + FOREACH(POS RANGE ${LIST_LEN}-1) + LIST(GET SOURCE_H ${POS} FILENAME) + #MESSAGE("ARG: ${ARG}") + #MESSAGE("FILENAME: ${FILENAME}") + STRING(REGEX MATCH ".*/${ARG}$" FOUND ${FILENAME}) + IF(FOUND) + #MESSAGE("Replace at position ${POS}, file ${FILENAME} with ${ARG}") + LIST(REMOVE_AT SOURCE_H ${POS}) + LIST(REMOVE_AT SOURCE_H_GROUP ${POS}) + BREAK() + ENDIF(FOUND) + ENDFOREACH(POS) + ENDFOREACH(ARG) + SET_PROPERTY(GLOBAL PROPERTY FORTE_SOURCE_H ${SOURCE_H}) + SET_PROPERTY(GLOBAL PROPERTY FORTE_SOURCE_H_GROUP ${SOURCE_H_GROUP}) +ENDFUNCTION(forte_remove_sourcefile_h) + +FUNCTION(forte_remove_sourcefile_cpp) + GET_PROPERTY(SOURCE_CPP GLOBAL PROPERTY FORTE_SOURCE_CPP) + GET_PROPERTY(SOURCE_CPP_GROUP GLOBAL PROPERTY FORTE_SOURCE_CPP_GROUP) + FOREACH(ARG ${ARGV}) + LIST(LENGTH SOURCE_CPP LIST_LEN) + MATH(EXPR LIST_LEN ${LIST_LEN}-1) + FOREACH(POS RANGE ${LIST_LEN}-1) + LIST(GET SOURCE_CPP ${POS} FILENAME) + STRING(REGEX MATCH ".*/${ARG}$" FOUND ${FILENAME}) + IF(FOUND) + LIST(REMOVE_AT SOURCE_CPP ${POS}) + LIST(REMOVE_AT SOURCE_CPP_GROUP ${POS}) + BREAK() + ENDIF(FOUND) + ENDFOREACH(POS) + ENDFOREACH(ARG) + SET_PROPERTY(GLOBAL PROPERTY FORTE_SOURCE_CPP ${SOURCE_CPP}) + SET_PROPERTY(GLOBAL PROPERTY FORTE_SOURCE_CPP_GROUP ${SOURCE_CPP_GROUP}) +ENDFUNCTION(forte_remove_sourcefile_cpp) + +FUNCTION(forte_replace_sourcefile_h) + FOREACH(ARG ${ARGV}) + forte_remove_sourcefile_h(${ARG}) + forte_add_sourcefile_h(${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_replace_sourcefile_h) + +FUNCTION(forte_replace_sourcefile_cpp) + FOREACH(ARG ${ARGV}) + forte_remove_sourcefile_cpp(${ARG}) + forte_add_sourcefile_cpp(${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_replace_sourcefile_cpp) + +FUNCTION(forte_add_link_directories) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_LINK_DIRECTORIES ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_link_directories) + +FUNCTION(forte_add_link_library) + FOREACH(ARG ${ARGV}) + set_property(GLOBAL APPEND PROPERTY FORTE_LINK_LIBRARY ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_link_library) + +FUNCTION(forte_add_definition) + FOREACH(ARG ${ARGV}) + set_property(GLOBAL APPEND PROPERTY FORTE_DEFINITION ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_definition) + +FUNCTION(forte_add_link_flags) +FOREACH(ARG ${ARGV}) + set_property(GLOBAL APPEND PROPERTY FORTE_LINK_FLAGS ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_link_flags) + +FUNCTION(forte_add_architecture) + FOREACH(ARG ${ARGV}) + set_property(GLOBAL APPEND PROPERTY FORTE_ARCHITECTURES ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_architecture) + +MACRO(forte_add_network_layer NAME ONOFF CONFIGNAME CLASSNAME FILENAME DISCRIPTION) +# TODO: parse filename from filename + set(FORTE_COM_${NAME} ${ONOFF} CACHE BOOL "${DISCRIPTION}") + IF(FORTE_COM_${NAME}) + FORTE_ADD_SOURCEFILE_HCPP(${FILENAME}) + set_property(GLOBAL APPEND PROPERTY FORTE_LAYER_CLASS ${CLASSNAME}) + set_property(GLOBAL APPEND PROPERTY FORTE_LAYER_CONFIGNAME ${CONFIGNAME}) + set_property(GLOBAL APPEND PROPERTY FORTE_LAYER_FILENAME "${FILENAME}.h") + ENDIF(FORTE_COM_${NAME}) +ENDMACRO(forte_add_network_layer) + +#MACRO(forte_add_module NAME DIRECTORY DISCRIPTION) +# Additional parameters are interpreted as dependencies +MACRO(forte_add_module NAME DISCRIPTION) + set(FORTE_MODULE_${NAME} OFF CACHE BOOL "${DISCRIPTION}") + FOREACH(dependencies ${ARGN}) + if(NOT ${dependencies}) + return() + endif(NOT ${dependencies}) + ENDFOREACH(dependencies) + if(NOT FORTE_MODULE_${NAME}) + return() + endif(NOT FORTE_MODULE_${NAME}) +ENDMACRO(forte_add_module) + + +FUNCTION(forte_create_modules_file FORTE_MODULE_DIR) + INCLUDE(${FORTE_BUILDSUPPORT_DIRECTORY}/generate_modules_cmake_file.cmake) +ENDFUNCTION(forte_create_modules_file) + +FUNCTION(forte_replacefile_if_changed SOURCE DESTINATION) + execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files ${SOURCE} ${DESTINATION} RESULT_VARIABLE test_not_successful OUTPUT_QUIET ERROR_QUIET ) + + IF( test_not_successful) + file(REMOVE ${DESTINATION}) + file(RENAME ${SOURCE} ${DESTINATION}) + ENDIF( test_not_successful) +ENDFUNCTION(forte_replacefile_if_changed SOURCE DESTINATION) + +FUNCTION(forte_add_extension_file) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_EXTENSION_FILES ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_extension_file) + +FUNCTION(forte_add_post_build_command) + FOREACH(ARG ${ARGV}) + set_property(GLOBAL APPEND PROPERTY FORTE_POST_BUILD_COMMAND ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_add_post_build_command) + +## forte_add_test (test_name file_name will_fail) +FUNCTION(forte_add_test arg1 arg2 arg3) + ADD_TEST(NAME ${arg1} COMMAND $) + set_tests_properties ( ${arg1} PROPERTIES TIMEOUT ${arg3}) + FILE(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/${arg2}" file_str) + STRING(REPLACE "\\" "\\\\" file_str ${file_str}) + set_tests_properties (${arg1} PROPERTIES ENVIRONMENT "FORTE_BOOT_FILE=${file_str};FORTE_VCD_FILE=${arg1}.vcd") + SET_TESTS_PROPERTIES(${arg1} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR: T") +ENDFUNCTION(forte_add_test) \ No newline at end of file diff --git a/buildsupport/generate_init.cmake b/buildsupport/generate_init.cmake new file mode 100644 index 000000000..f2274d7fd --- /dev/null +++ b/buildsupport/generate_init.cmake @@ -0,0 +1,120 @@ +#******************************************************************************* +# * Copyright (c) 2011 Profactor GmbH and ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Gerhard Ebenhofer and Ingo Hegny - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +MESSAGE("Generate Initfunction") +MESSAGE("Source Dir: ${FORTE_SOURCE_DIR}") +MESSAGE("Binary Dir: ${FORTE_BINARY_DIR}") +FILE(STRINGS ${CMAKE_BINARY_DIR}/../file_list.txt FILE_NAMES) + +####################################################################################### +# Create Forte-Executeable with all Functionblocks +####################################################################################### + +FOREACH(FILE_NAME ${FILE_NAMES}) + # Do not parse typelib, as it holds the definitions + STRING(REGEX MATCH ".*typelib\\.(cpp|h).*" REGEX_STRINGS ${FILE_NAME}) + IF(NOT REGEX_STRINGS) + STRING(REGEX MATCH ".*forteinit\\.(cpp|h).*" REGEX_STRINGS ${FILE_NAME}) + ENDIF(NOT REGEX_STRINGS) + IF(NOT REGEX_STRINGS) + STRING(REGEX MATCH ".*stringlist\\.(cpp|h).*" REGEX_STRINGS ${FILE_NAME}) + ENDIF(NOT REGEX_STRINGS) + IF(NOT REGEX_STRINGS) + FILE(READ ${FILE_NAME} FILE_CONTENT) + STRING(REGEX MATCHALL "DEFINE_FIRMWARE_DATATYPE\\(([A-Za-z0-9_]*)" REGEX_STRINGS ${FILE_CONTENT}) + IF(REGEX_STRINGS) + string(LENGTH ${FILE_NAME} len) + math(EXPR len ${len}-4) + string(SUBSTRING ${FILE_NAME} 0 ${len} OUTSTR) + list(APPEND datatypeIncludeStringBuf ${OUTSTR}) + FOREACH(STR ${REGEX_STRINGS}) + string(LENGTH ${STR} len) + math(EXPR len ${len}-25) + string(SUBSTRING ${STR} 25 ${len} OUTSTR) + list(APPEND datatypeFunctionStringBuf ${OUTSTR}) + ENDFOREACH(STR) + ENDIF(REGEX_STRINGS) + STRING(REGEX MATCHALL "DEFINE_FIRMWARE_FB\\(([A-Za-z0-9_]*)" REGEX_STRINGS ${FILE_CONTENT}) + IF(REGEX_STRINGS) + string(LENGTH ${FILE_NAME} len) + math(EXPR len ${len}-4) + string(SUBSTRING ${FILE_NAME} 0 ${len} OUTSTR) + list(APPEND fbIncludeStringBuf ${OUTSTR}) + FOREACH(STR ${REGEX_STRINGS}) + string(LENGTH ${STR} len) + math(EXPR len ${len}-19) + string(SUBSTRING ${STR} 19 ${len} OUTSTR) + list(APPEND fbFunctionStringBuf ${OUTSTR}) + ENDFOREACH(STR) + ENDIF(REGEX_STRINGS) + STRING(REGEX MATCHALL "DEFINE_GENERIC_FIRMWARE_FB\\(([A-Za-z0-9_]*)" REGEX_STRINGS ${FILE_CONTENT}) + IF(REGEX_STRINGS) + string(LENGTH ${FILE_NAME} len) + math(EXPR len ${len}-4) + string(SUBSTRING ${FILE_NAME} 0 ${len} OUTSTR) + list(APPEND fbIncludeStringBuf ${OUTSTR}) + FOREACH(STR ${REGEX_STRINGS}) + string(LENGTH ${STR} len) + math(EXPR len ${len}-27) + string(SUBSTRING ${STR} 27 ${len} OUTSTR) + list(APPEND fbFunctionStringBuf ${OUTSTR}) + ENDFOREACH(STR) + ENDIF(REGEX_STRINGS) + ENDIF(NOT REGEX_STRINGS) +ENDFOREACH(FILE_NAME) + +list(SORT datatypeFunctionStringBuf) +list(REMOVE_DUPLICATES datatypeFunctionStringBuf) +SET(DATATYPE_FUNCTION_STRING "") +FOREACH(STR ${datatypeFunctionStringBuf}) + SET(DATATYPE_FUNCTION_STRING "${DATATYPE_FUNCTION_STRING} CIEC_${STR}::dummyInit();\n") +ENDFOREACH(STR) + +list(SORT datatypeIncludeStringBuf) +list(REMOVE_DUPLICATES datatypeIncludeStringBuf) +SET(DATATYPE_INCLUDE_STRING "") +FOREACH(STR ${datatypeIncludeStringBuf}) + SET(DATATYPE_INCLUDE_STRING "${DATATYPE_INCLUDE_STRING}#include <${STR}.h>\n") +ENDFOREACH(STR) + +list(SORT fbFunctionStringBuf) +list(REMOVE_DUPLICATES fbFunctionStringBuf) +SET(FB_FUNCTION_STRING "") +FOREACH(STR ${fbFunctionStringBuf}) + SET(FB_FUNCTION_STRING "${FB_FUNCTION_STRING} ${STR}::dummyInit();\n") +ENDFOREACH(STR) + +list(SORT fbIncludeStringBuf) +list(REMOVE_DUPLICATES fbIncludeStringBuf) +SET(FB_INCLUDE_STRING "") +FOREACH(STR ${fbIncludeStringBuf}) + SET(FB_INCLUDE_STRING "${FB_INCLUDE_STRING}#include <${STR}.h>\n") +ENDFOREACH(STR) + +CONFIGURE_FILE(${FORTE_SOURCE_DIR}/src/forteinit.cpp.in ${FORTE_BINARY_DIR}/forteinit_new.cpp) +CONFIGURE_FILE(${FORTE_SOURCE_DIR}/src/forteinit.h.in ${FORTE_BINARY_DIR}/forteinit_new.h) + +# only copy files if different +execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files ${FORTE_BINARY_DIR}/forteinit_new.cpp ${FORTE_BINARY_DIR}/forteinit.cpp RESULT_VARIABLE test_not_successful_cpp OUTPUT_QUIET ERROR_QUIET ) +execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files ${FORTE_BINARY_DIR}/forteinit_new.h ${FORTE_BINARY_DIR}/forteinit.h RESULT_VARIABLE test_not_successful_h OUTPUT_QUIET ERROR_QUIET ) + +IF(test_not_successful_cpp) + file(REMOVE ${FORTE_BINARY_DIR}/forteinit.cpp) + file(RENAME ${FORTE_BINARY_DIR}/forteinit_new.cpp ${FORTE_BINARY_DIR}/forteinit.cpp) +ENDIF(test_not_successful_cpp) + +IF(test_not_successful_h) + file(REMOVE ${FORTE_BINARY_DIR}/forteinit.h) + file(RENAME ${FORTE_BINARY_DIR}/forteinit_new.h ${FORTE_BINARY_DIR}/forteinit.h) +ENDIF(test_not_successful_h) + +file(REMOVE ${FORTE_BINARY_DIR}/forteinit_new.cpp) +file(REMOVE ${FORTE_BINARY_DIR}/forteinit_new.h) diff --git a/buildsupport/generate_modules_cmake_file.cmake b/buildsupport/generate_modules_cmake_file.cmake new file mode 100644 index 000000000..2e5caf95a --- /dev/null +++ b/buildsupport/generate_modules_cmake_file.cmake @@ -0,0 +1,44 @@ +#******************************************************************************* +# * Copyright (c) 2011 Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Michael Hofmann - initial API and implementation and/or initial documentation +# *******************************************************************************/ +FILE(GLOB_RECURSE FILES_FOUND "${FORTE_MODULE_DIR}/*CMakeLists.txt") + +FOREACH(FILE ${FILES_FOUND}) + string(REPLACE "${FORTE_MODULE_DIR}" "" MODULE_NAME ${FILE}) + STRING(REGEX MATCH "^/([^/]*)/CMakeLists.txt$" MODULE_NAME ${MODULE_NAME}) + IF(MODULE_NAME) + string(REPLACE "/CMakeLists.txt" "" MODULE_NAME "${MODULE_NAME}") + string(REPLACE "/" "" MODULE_NAME "${MODULE_NAME}") + LIST(APPEND MODULE_LIST ${MODULE_NAME}) + ENDIF(MODULE_NAME) +ENDFOREACH(FILE) + +#MESSAGE("GLOBBING: ${MODULE_LIST2}" ) +#MESSAGE("GLOBBING: ${MODULE_LIST}" ) + + + +SET(WRITE_FILE "") +FOREACH(MODULE ${MODULE_LIST}) + SET(WRITE_FILE "${WRITE_FILE}SET(SOURCE_GROUP_BACKUP \"\${SOURCE_GROUP}\")\n") + SET(WRITE_FILE "${WRITE_FILE}SET(SOURCE_GROUP \"\${SOURCE_GROUP}/${MODULE}\")\n") + SET(WRITE_FILE "${WRITE_FILE}ADD_SUBDIRECTORY(\"\${FORTE_MODULE_DIR}${MODULE}\")\n") + SET(WRITE_FILE "${WRITE_FILE}SET(SOURCE_GROUP \"\${SOURCE_GROUP_BACKUP}\")\n") +ENDFOREACH(MODULE) + +file(WRITE ${CMAKE_BINARY_DIR}/src/modules/CMakeLists_new.txt ${WRITE_FILE}) + +execute_process( COMMAND ${CMAKE_COMMAND} -E compare_files ${CMAKE_BINARY_DIR}/src/modules/CMakeLists_new.txt ${CMAKE_BINARY_DIR}/src/modules/CMakeLists.txt RESULT_VARIABLE test_not_successful OUTPUT_QUIET ERROR_QUIET ) + +IF(test_not_successful) + file(REMOVE ${CMAKE_BINARY_DIR}/src/modules/CMakeLists.txt) + file(RENAME ${CMAKE_BINARY_DIR}/src/modules/CMakeLists_new.txt ${CMAKE_BINARY_DIR}/src/modules/CMakeLists.txt) +ENDIF( test_not_successful) +file(REMOVE ${CMAKE_BINARY_DIR}/src/modules/CMakeLists_new.txt) \ No newline at end of file diff --git a/buildsupport/generate_stringlist.cmake b/buildsupport/generate_stringlist.cmake new file mode 100644 index 000000000..caf98999f --- /dev/null +++ b/buildsupport/generate_stringlist.cmake @@ -0,0 +1,126 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2014 Profactor GmbH, ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Michael Hofmann, Alois Zoitl, Ingo Hegny, Gerhard Ebenhofer, Matthias Plasch - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +MESSAGE(Generate Stringlist) +MESSAGE("Source Dir: ${FORTE_SOURCE_DIR}") +MESSAGE("Binary Dir: ${FORTE_BINARY_DIR}") +FILE(STRINGS ${FORTE_BINARY_DIR}/file_list.txt FBLIB_STRUCT) + + +if(EXISTS ${FORTE_BINARY_DIR}/file_test_list.txt) + Message("adding testlist") + FILE(STRINGS ${FORTE_BINARY_DIR}/file_test_list.txt FBLIB_TEST_STRUCT) + + LIST(APPEND FBLIB_STRUCT ${FBLIB_TEST_STRUCT}) + LIST(REMOVE_DUPLICATES FBLIB_STRUCT) +endif() + +####################################################################################### +# Create Forte-Executeable with all Functionblocks +####################################################################################### + +LIST(LENGTH FBLIB_STRUCT len) + +list(APPEND ErrorStringBuf " ") + +set(LENGTH_COUNT 0) +FOREACH(FBLIB_FILE ${FBLIB_STRUCT}) + # Do not pars stringlist, as these files will be generated + STRING(REGEX MATCH ".*stringlist\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) + IF(NOT REGEX_STRINGS) + STRING(REGEX MATCH ".*forteinit\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) + ENDIF(NOT REGEX_STRINGS) + IF(NOT REGEX_STRINGS) + FILE(READ ${FBLIB_FILE} FILE_STRING) + STRING(REGEX MATCHALL "g_nStringId([A-Za-z0-9_]*)" REGEX_STRINGS ${FILE_STRING}) + STRING(REGEX MATCHALL "g_nStringId([0-9][A-Za-z0-9_]*)" REGEX_STRINGS_ERROR ${FILE_STRING}) + + FOREACH(STR ${REGEX_STRINGS}) + string(LENGTH ${STR} len) + math(EXPR len ${len}-11) + string(SUBSTRING ${STR} 11 ${len} OUTSTR) + list(APPEND scm_acConstStringBuf ${OUTSTR}) + ENDFOREACH(STR) + + FOREACH(STR_ERR ${REGEX_STRINGS_ERROR}) + list(APPEND ErrorStringBuf "#ERROR Invalid Name used! \n//" ${FBLIB_FILE}:${STR_ERR}) + ENDFOREACH(STR_ERR) + + ENDIF(NOT REGEX_STRINGS) +ENDFOREACH(FBLIB_FILE) + +list(REMOVE_DUPLICATES ErrorStringBuf) + +list(REMOVE_ITEM scm_acConstStringBuf "NextFreeId") +list(SORT scm_acConstStringBuf) +list(REMOVE_DUPLICATES scm_acConstStringBuf) +SET(STRINGLIST_H "") +SET(STRINGLIST_CPP "") +FOREACH(STR ${scm_acConstStringBuf}) + string(LENGTH ${STR} len) + math(EXPR len ${len}+1) # \0 is only one character + list(APPEND scm_aunIdList ${LENGTH_COUNT}) + SET(STRINGLIST_H "${STRINGLIST_H}const CStringDictionary::TStringId g_nStringId${STR} = ${LENGTH_COUNT};\n") + SET(STRINGLIST_CPP "${STRINGLIST_CPP}extern const CStringDictionary::TStringId g_nStringId${STR} = ${LENGTH_COUNT};\n") + math(EXPR LENGTH_COUNT ${LENGTH_COUNT}+${len}) +ENDFOREACH(STR) +list(LENGTH scm_aunIdList NUMOFCONSTSTRINGS) + +IF(FORTE_LINKED_STRINGDICT) + SET(STRINGLIST_H) + SET(STRINGLIST_H "${STRINGLIST_H}extern const CStringDictionary::TStringId g_nStringIdNextFreeId;\n") + SET(STRINGLIST_H "${STRINGLIST_H}extern const unsigned int cg_nNumOfConstStrings;\n") + SET(STRINGLIST_CPP "${STRINGLIST_CPP}extern const CStringDictionary::TStringId g_nStringIdNextFreeId = ${LENGTH_COUNT};\n") + SET(STRINGLIST_CPP "${STRINGLIST_CPP}extern const unsigned int cg_nNumOfConstStrings = ${NUMOFCONSTSTRINGS};\n") +ELSE(FORTE_LINKED_STRINGDICT) + SET(STRINGLIST_CPP) + SET(STRINGLIST_H "\n${STRINGLIST_H}const CStringDictionary::TStringId g_nStringIdNextFreeId = ${LENGTH_COUNT};\n") + SET(STRINGLIST_H "${STRINGLIST_H}const unsigned int cg_nNumOfConstStrings = ${NUMOFCONSTSTRINGS};\n") +ENDIF(FORTE_LINKED_STRINGDICT) + + +SET(scm_aunIdList_Str "") +SET(FIRST TRUE) +FOREACH(NUM ${scm_aunIdList}) + if(FIRST) + SET(scm_aunIdList_Str "${scm_aunIdList_Str}${NUM}") + SET(FIRST FALSE) + ELSE(FIRST) + SET(scm_aunIdList_Str "${scm_aunIdList_Str}, ${NUM}") + ENDIF(FIRST) +ENDFOREACH(NUM) + +SET(scm_acConstStringBuf_Str "") +IF(WIN32) + string(LENGTH "1" len) + math(EXPR cnt ${len}) +ENDIF(WIN32) +FOREACH(STR ${scm_acConstStringBuf}) + SET(scm_acConstStringBuf_Str "${scm_acConstStringBuf_Str}${STR}\\0") + IF(WIN32) + string(LENGTH ${scm_acConstStringBuf_Str} len) + math(EXPR lenRest ${len}) + math(EXPR bytes ${cnt}*15000) + IF(${lenRest} GREATER ${bytes}) + SET(scm_acConstStringBuf_Str "${scm_acConstStringBuf_Str}\" \"") + math(EXPR cnt ${cnt}+1) + ENDIF(${lenRest} GREATER ${bytes}) + ENDIF(WIN32) +ENDFOREACH(STR) + +CONFIGURE_FILE(${FORTE_SOURCE_DIR}/stringlist.h.in ${FORTE_BINARY_DIR}/stringlist_new.h) +CONFIGURE_FILE(${FORTE_SOURCE_DIR}/stringlist.cpp.in ${FORTE_BINARY_DIR}/stringlist_new.cpp) + +# only copy files if different +execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FORTE_BINARY_DIR}/stringlist_new.h ${FORTE_BINARY_DIR}/stringlist.h OUTPUT_QUIET ERROR_QUIET ) +execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FORTE_BINARY_DIR}/stringlist_new.cpp ${FORTE_BINARY_DIR}/stringlist.cpp OUTPUT_QUIET ERROR_QUIET ) +file(REMOVE ${FORTE_BINARY_DIR}/stringlist_new.h) +file(REMOVE ${FORTE_BINARY_DIR}/stringlist_new.cpp) diff --git a/buildsupport/generate_stringlist_include_files.cmake b/buildsupport/generate_stringlist_include_files.cmake new file mode 100644 index 000000000..1c4be01a4 --- /dev/null +++ b/buildsupport/generate_stringlist_include_files.cmake @@ -0,0 +1,108 @@ +#******************************************************************************* +# * Copyright (c) 2012 Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Michael Hofmann - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +# Just the File name + +#GET_FILENAME_COMPONENT(FBLIB_FILE_WO_PATH ${FBLIB_FILE} NAME_WE) +STRING(REGEX REPLACE ".*/" "" FBLIB_FILE_WO_PATH ${FBLIB_FILE}) +STRING(REGEX REPLACE "\\.cpp" ".h" FBLIB_FILE_WO_PATH_H ${FBLIB_FILE_WO_PATH}) +STRING(REGEX REPLACE "\\." "_gen." FBLIB_FILE_NAME ${FBLIB_FILE_WO_PATH}) + +STRING(REGEX MATCH ".*stringlist\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) +IF(NOT REGEX_STRINGS) +STRING(REGEX MATCH ".*forteinit\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) +ENDIF(NOT REGEX_STRINGS) +IF(NOT REGEX_STRINGS) + FILE(READ ${FBLIB_FILE} FILE_STRING) + STRING(REGEX MATCHALL "g_nStringId([A-Za-z0-9_]*)" REGEX_STRINGS ${FILE_STRING}) + STRING(REGEX MATCHALL "g_nStringId([0-9][A-Za-z0-9_]*)" REGEX_STRINGS_ERROR ${FILE_STRING}) + + + # Remove already defined externals, those will be generated #defines in the sourcecode + STRING(REGEX MATCHALL "(DEFINE_GENERIC_FIRMWARE_FB|DEFINE_FIRMWARE_DATATYPE)[(]([A-Za-z0-9_]*)" REGEX_STRINGS_CODE_DEFINED ${FILE_STRING}) + IF(REGEX_STRINGS_CODE_DEFINED) + STRING(REGEX REPLACE "(DEFINE_GENERIC_FIRMWARE_FB|DEFINE_FIRMWARE_DATATYPE)[(]" "" REGEX_STRINGS_CODE_DEFINED ${REGEX_STRINGS_CODE_DEFINED}) + ENDIF(REGEX_STRINGS_CODE_DEFINED) + + # remove template connections + # Do not pars stringlist, as these files will be generated + STRING(REGEX MATCH "conn\\.h" REGEX_TEMPLATE ${FBLIB_FILE_WO_PATH}) + IF(NOT REGEX_TEMPLATE) + IF(FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES) + ## CConnection::genConPortIdTemplate to GENERATE_CONNECTION_PORT_ID_2_ARG + STRING(REGEX MATCHALL "CConnection::genConPortIdTemplate<([A-Za-z0-9_,\t ]*)>::value" REGEX_TO_REPLACE "${FILE_STRING}") + IF(REGEX_TO_REPLACE) + FOREACH(ELEMENT ${REGEX_TO_REPLACE}) + MESSAGE("${ELEMENT}") + STRING(REPLACE "CConnection::genConPortIdTemplate<" "GENERATE_CONNECTION_PORT_ID_2_ARG(" NEW_ELEMENT "${ELEMENT}") + STRING(REPLACE ">::value" ")" NEW_ELEMENT "${NEW_ELEMENT}") + MESSAGE("${NEW_ELEMENT}") + STRING(REPLACE "${ELEMENT}" "${NEW_ELEMENT}" FILE_STRING "${FILE_STRING}") + FILE(WRITE ${FBLIB_FILE} "${FILE_STRING}") + ENDFOREACH(ELEMENT) + ENDIF(REGEX_TO_REPLACE) + ## CConnection::genConPortIdSingleTemplate to GENERATE_CONNECTION_PORT_ID_2_ARG + STRING(REGEX MATCHALL "CConnection::genConPortIdSingleTemplate<([A-Za-z0-9_\t ]*)>::value" REGEX_TO_REPLACE "${FILE_STRING}") + IF(REGEX_TO_REPLACE) + FOREACH(ELEMENT ${REGEX_TO_REPLACE}) + MESSAGE("${ELEMENT}") + STRING(REPLACE "CConnection::genConPortIdSingleTemplate<" "GENERATE_CONNECTION_PORT_ID_1_ARG(" NEW_ELEMENT "${ELEMENT}") + STRING(REPLACE ">::value" ")" NEW_ELEMENT "${NEW_ELEMENT}") + MESSAGE("${NEW_ELEMENT}") + STRING(REPLACE "${ELEMENT}" "${NEW_ELEMENT}" FILE_STRING "${FILE_STRING}") + FILE(WRITE ${FBLIB_FILE} "${FILE_STRING}") + ENDFOREACH(ELEMENT) + ENDIF(REGEX_TO_REPLACE) + ENDIF(FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES) + ENDIF(NOT REGEX_TEMPLATE) + + list(REMOVE_DUPLICATES REGEX_STRINGS) + list(REMOVE_ITEM REGEX_STRINGS "g_nStringId${REGEX_STRINGS_CODE_DEFINED}") + # Sanity check for old files + STRING(REGEX MATCHALL "#include \"${FBLIB_FILE_NAME}\"" REGEX_STRINGS_MISSING_INCLUDE ${FILE_STRING}) + IF(REGEX_STRINGS) + IF(NOT REGEX_STRINGS_MISSING_INCLUDE) + IF(FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES) + MESSAGE(WARNING "${FBLIB_FILE}: Missing include statement. #include \"${FBLIB_FILE_NAME}\". Will be autogenerated") + MESSAGE("${FBLIB_FILE_WO_PATH_H}") + STRING(REGEX REPLACE "#include \"${FBLIB_FILE_WO_PATH_H}\"" "#include \"${FBLIB_FILE_WO_PATH_H}\"\n#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP\n#include \"${FBLIB_FILE_NAME}\"\n#endif" FILE_STRING "${FILE_STRING}") + FILE(WRITE ${FBLIB_FILE} "${FILE_STRING}") + ELSE(FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES) + MESSAGE(FATAL_ERROR "${FBLIB_FILE}: Missing include statement, add: #include \"${FBLIB_FILE_NAME}\". Not generating stringdict-externals file") + RETURN() + ENDIF(FORTE_MODIFY_SOURCES_ON_MISSING_GENERATED_INCLUDES) + ENDIF(NOT REGEX_STRINGS_MISSING_INCLUDE) + ENDIF(REGEX_STRINGS) + + SET(scm_acLocalConstStringBuf "") + FOREACH(STR ${REGEX_STRINGS}) + string(LENGTH ${STR} len) + math(EXPR len ${len}-11) + string(SUBSTRING ${STR} 11 ${len} OUTSTR) + list(APPEND scm_acLocalConstStringBuf ${OUTSTR}) + ENDFOREACH(STR) + + SET(${FBLIB_FILE}_externals "") + list(SORT scm_acLocalConstStringBuf) + list(REMOVE_DUPLICATES scm_acLocalConstStringBuf) + FOREACH(STR IN LISTS scm_acLocalConstStringBuf) + set(${FBLIB_FILE}_externals "${${FBLIB_FILE}_externals} extern const CStringDictionary::TStringId g_nStringId${STR};\n") + ENDFOREACH(STR) + + #IF(NOT (${FBLIB_FILE}_externals STREQUAL "")) + #create generated file + CONFIGURE_FILE(${FORTE_SOURCE_DIR}/gen_include.cpp.in ${FORTE_BINARY_DIR}/${FBLIB_FILE_NAME}_new) + # only copy files if different + execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${FORTE_BINARY_DIR}/${FBLIB_FILE_NAME}_new ${FORTE_BINARY_DIR}/${FBLIB_FILE_NAME} OUTPUT_QUIET ERROR_QUIET ) + file(REMOVE ${FORTE_BINARY_DIR}/${FBLIB_FILE_NAME}_new) + #ENDIF(NOT (${FBLIB_FILE}_externals STREQUAL "")) + +ENDIF(NOT REGEX_STRINGS) \ No newline at end of file diff --git a/buildsupport/toolchains/toolchain-m1.cmake b/buildsupport/toolchains/toolchain-m1.cmake new file mode 100644 index 000000000..94a40be18 --- /dev/null +++ b/buildsupport/toolchains/toolchain-m1.cmake @@ -0,0 +1,31 @@ +INCLUDE (CMakeForceCompiler) + +SET(CMAKE_SYSTEM_NAME generic) +SET(CMAKE_SYSTEM_VERSION 1) + +SET(M1_CUTILS "C:/bachmann/SolutionCenter/V1.70Release/cutils/GnuTools-4.1.2" CACHE PATH "Bachmann M1 CUTILS Directory") +message(${M1_CUTILS}) +# specify the cross compiler +CMAKE_FORCE_C_COMPILER(${M1_CUTILS}/bin/i386-wrs-vxworks-gcc.exe GNU) +CMAKE_FORCE_CXX_COMPILER(${M1_CUTILS}/bin/i386-wrs-vxworks-c++.exe GNU) + + +# for libraries and headers in the target directories +SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/../GnuTools/target/h) +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/include/befc) +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/include/c++/4.1.2) +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/include/c++/4.1.2/i386-wrs-vxworks) +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/lib/gcc/i386-wrs-vxworks/4.1.2/include) +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/i386-wrs-vxworks/sys-include) +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/i386-wrs-vxworks/sys-include/wrn/coreip) +SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_INCLUDE_DIRECTORIES ${M1_CUTILS}/../mcsdk/msys/inc) + + + +#set(FORTE_LITTLE_ENDIAN OFF CACHE INTERNAL BOOL) +#set(FORTE_BIG_ENDIAN ON CACHE INTERNAL BOOL) + +ADD_DEFINITIONS(-Wall -march=pentium -nostdinc -O0 -fno-builtin -fno-defer-pop -D_POSIX_THREAD_ATTR_STACKSIZE -DCPU_FAMILY=I80X86 -ggdb) diff --git a/buildsupport/wago_pfc200/forte_wago.in b/buildsupport/wago_pfc200/forte_wago.in new file mode 100644 index 000000000..f6b09e718 --- /dev/null +++ b/buildsupport/wago_pfc200/forte_wago.in @@ -0,0 +1,18 @@ +## SECTION=project_specific + +config FORTE_WAGO + bool + prompt "forte_wago" + select HOST_CMAKE + help + FIXME + +if FORTE_WAGO + +config FORTE_WAGO_TRUNK + bool + prompt "use trunk" + help + Build trunk instead of latest release. + +endif diff --git a/buildsupport/wago_pfc200/forte_wago.make b/buildsupport/wago_pfc200/forte_wago.make new file mode 100644 index 000000000..bf2dbb517 --- /dev/null +++ b/buildsupport/wago_pfc200/forte_wago.make @@ -0,0 +1,85 @@ +# Copyright (C) 2014 4DIAC +# +# See CREDITS for details about who has contributed to this project. +# +# For further information about the PTXdist project and license conditions +# see the README file. +# + +# +# We provide this package +# +PACKAGES-$(PTXCONF_FORTE_WAGO) += forte_wago + +# +# Paths and names +# +ifdef PTXCONF_FORTE_WAGO_TRUNK +FORTE_WAGO_VERSION := trunk +else +FORTE_WAGO_VERSION := 1.6.2 +endif +FORTE_WAGO := forte_wago-$(FORTE_WAGO_VERSION) +FORTE_WAGO_URL := file:/// +FORTE_WAGO_DIR := $(BUILDDIR)/$(FORTE_WAGO) +FORTE_WAGO_LICENSE := Eclipse Public License + +# ---------------------------------------------------------------------------- +# Get +# ---------------------------------------------------------------------------- + +$(FORTE_WAGO_SOURCE): + @$(call targetinfo) + @$(call get, FORTE_WAGO) + +# ---------------------------------------------------------------------------- +# Prepare +# ---------------------------------------------------------------------------- + +#FORTE_WAGO_CONF_ENV := $(CROSS_ENV) + +# +# cmake +# +FORTE_WAGO_CONF_TOOL := cmake +FORTE_WAGO_CONF_OPT := $(CROSS_CMAKE_USR) -DFORTE_COM_ETH:BOOL=ON -DFORTE_COM_FBDK:BOOL=ON -DFORTE_COM_LOCAL:BOOL=ON -DFORTE_ARCHITECTURE:STRING=Posix -DFORTE_MODULE_CONVERT:BOOL=ON -DFORTE_TRACE_EVENTS:BOOL=OFF -DFORTE_MODULE_WagoKbus=ON +# +# ---------------------------------------------------------------------------- +# Target-Install +# ---------------------------------------------------------------------------- + +$(STATEDIR)/forte_wago.targetinstall: + @$(call targetinfo) + + @$(call install_init, forte_wago) + @$(call install_fixup, forte_wago, PRIORITY, optional) + @$(call install_fixup, forte_wago, SECTION, base) + @$(call install_fixup, forte_wago, AUTHOR, "4DIAC Consortium") + @$(call install_fixup, forte_wago, DESCRIPTION, missing) + +# # +# # example code:; copy all binaries +# # + + @for i in $(shell cd $(FORTE_WAGO_PKGDIR) && find bin sbin usr/bin usr/sbin -type f); do \ + $(call install_copy, forte_wago, 0, 0, 0755, -, /$$i); \ + done + +# # +# # FIXME: add all necessary things here +# # + + @$(call install_finish, forte_wago) + + @$(call touch) + +# ---------------------------------------------------------------------------- +# Clean +# ---------------------------------------------------------------------------- +forte_wago_clean: + rm -rf $(STATEDIR)/forte_wago.* +#$(STATEDIR)/forte_wago.clean: +# @$(call targetinfo) +# @$(call clean_pkg, FORTE_WAGO) + +# vim: syntax=make diff --git a/doc/coding_rules/forte_coding_rules.pdf b/doc/coding_rules/forte_coding_rules.pdf new file mode 100644 index 000000000..f81b2b308 Binary files /dev/null and b/doc/coding_rules/forte_coding_rules.pdf differ diff --git a/doc/coding_rules/src/forte_coding_rules.tcp b/doc/coding_rules/src/forte_coding_rules.tcp new file mode 100644 index 000000000..772994d64 --- /dev/null +++ b/doc/coding_rules/src/forte_coding_rules.tcp @@ -0,0 +1,12 @@ +[FormatInfo] +Type=TeXnicCenterProjectInformation +Version=4 + +[ProjectInfo] +MainFile=forte_coding_rules.tex +UseBibTeX=0 +UseMakeIndex=0 +ActiveProfile=LaTeX => PDF +ProjectLanguage=de +ProjectDialect=DE + diff --git a/doc/coding_rules/src/forte_coding_rules.tex b/doc/coding_rules/src/forte_coding_rules.tex new file mode 100644 index 000000000..42bcfcf81 --- /dev/null +++ b/doc/coding_rules/src/forte_coding_rules.tex @@ -0,0 +1,364 @@ +%******************************************************************************* +% * Copyright (c) 2007 - 2015 Profactor GmbH, ACIN, fortiss GmbH +% * All rights reserved. This program and the accompanying materials +% * are made available under the terms of the Eclipse Public License v1.0 +% * which accompanies this distribution, and is available at +% * http://www.eclipse.org/legal/epl-v10.html +% * +% * Contributors: +% * Gerhard Ebenhofer, Thomas Strasser, Alois Zoitl - initial API and implementation and/or initial documentation +% *******************************************************************************/ + +\documentclass[final,a4paper,10pt, oneside]{article} +\usepackage[latin1]{inputenc} + +\usepackage{a4wide} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% important definitions at the beginning +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + + +\title{Coding Rules for \emph{FORTE}\footnote{Framework for Distributed Industrial Automation and Control---Run-Time Environment}} +\author{Alois Zoitl, alil\@@users.sf.net \and Rene Smodic, smodic\@@acin.tuwien.ac.at} +\date{May 18, 2010} + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Links +\usepackage{ifpdf} +\ifpdf + \usepackage[pdftex, colorlinks, pdfstartview=FitH, plainpages=false, pdfpagelabels]{hyperref} + \pdfcompresslevel=9 +\else + \usepackage[dvipdfm, colorlinks]{hyperref} +\fi + +\hypersetup{colorlinks, linkcolor=black, filecolor=black, urlcolor=black, citecolor=black, pdftitle={Coding Rules for FORTE},pdfauthor={Alois Zoitl, Smodic Rene}} + +% Font +\usepackage{mathpazo} + +\usepackage[centerlast,small,bf]{caption2} %zentriert, kleiner als fliesstext, fett (gilt nur fuer 'Abbildung x:') + +% Figures +\usepackage[dvips]{graphicx} + +% Listings +\usepackage{listings} +\lstset{language=C++} +\lstset{commentstyle=\textit} +\lstset{linewidth=\textwidth} +\lstset{basicstyle=\scriptsize} + + + +\begin{document} + +\maketitle + +\tableofcontents + +\section{Comments} +A sufficient amount of comments has to be written. There are never too many comments, whereas invalid comments are worse than none --- thus +invalid comments have to be removed from the source code. Comments have to be written in English. + +\begin{quote} +Comments for class, function, \ldots~ definitions have to follow the conventions of \emph{Doxygen} to allow the automated generation of documentation for the sourcecode. +\end{quote} + +For documenting the implementation it is allowed to indicate Single-line +comments with \verb|//| ahead of the command or in the same line right after the command. All other comments have to be located ahead of the +command or block. Generally comments have to be tagged with \verb|//| to allow the temporarily commenting out of code with \verb|/*...*/|. +Comments have to be meaningful, to describe to program and to be up to date. + + +\subsection{File Headers} +Every source-file must contain a file header as follows: +\begin{lstlisting}[frame=trbl]{} +/******************************************************************************* + * Copyright (c) 2007 4DIAC - consortium. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + ******************************************************************************* +\end{lstlisting} +An example for the file header used in an full header file is given in Appendix~\ref{subsec:FileHeader} of this document. + +\subsection{Keywords} +The following Keywords should be used in the source code to mark special comments: +\begin{itemize} + \item \textbf{TODO:} For comments about possible or needed extensions + \item \textbf{FIXME:} To be used for comments about potential (or known) bugs +\end{itemize} + +\section{Datatypes} +For the \emph{FORTE}-development we distinguish between three main kinds of data types: +\begin{enumerate} +\item Standard C++ data types: + +These data types should be used in all places where no special demands on the used data +type are required. Especially for standard integers the \verb=int= or \verb=unsigned int= +should be considered, +as these are on most machines the fastest and often also smaller assembler code is produced. + +\item IEC 61131-3 data types: + +\emph{FORTE} provides a set of classes resembling the data types defined in IEC 61131-3. These classes can be found in the \verb|src/core/datatypes| directory. The class names are the IEC 61131-3 data type name prefixed with \verb=CIEC_=. They are used for the FB interfaces and for internal variables of Basic FBs. There they are also used for the transition conditions and the algorithms. When using these data types one should be aware about the overhead involved in them. + +\item Data types of given size: + +Table~\ref{tab:datatypes} contains the definitions of important standard data types. This is done to ensure a machine independent definition of the bit-width of the standard data types. For \emph{FORTE}-development these definitions are in the file: \verb|src/arch/datatypes.h| +\end{enumerate} + +\begin{table}[ht] + \centering + \caption{Size constrained data types for \emph{FORTE}-development} \label{tab:datatypes} + \begin{tabular}{lll} + defined data type & bit-width / description\\ + \hline + TForteByte & 8 bit unsigned\\ + TForteWord & 16 bit unsigned \\ + TForteDWord & 32 bit unsigned \\ + TForteInt8 & 8 bit signed \\ + TForteInt16 & 16 bit signed \\ + TForteInt32 & 32 bit signed \\ + TForteUInt8 & 8 bit unsigned \\ + TForteUInt16 & 16 bit unsigned \\ + TForteUInt32 & 32 bit unsigned \\ + TForteFloat & single precission IEEE float (32 bit) \\ + TForteDFloat & double precission IEEE float (64 bit) + \end{tabular} +\end{table} + +\section{Naming of Identifiers} +Every identifier has to be named in English. +The first character of an identifier must not contain underscores (there are some compiler directives which start with underscores and this could lead to conflicts). +Mixed case letters (i.e. camel-case) have to be used and the appropriate prefixes have to be inserted where necessary. + + +\subsection{Variables} +Variables have to be named self explanatory. The names have to be provided with the appropriate prefixes and they have to start with an uppercase letter. In case of combining prefixes, the use of ranges, arrays, pointer, enumerations, or structures is at first, followed by basic data types or object prefixes. The only exception are loop variables (thereby the use of i, j, k is allowed). Only one variable declaration per line is allowed. Pointer operators at the declaration have to be located in front of the variable (not after the type identifier). If possible initializations have to be done directly at the declaration. + +\textbf{Global non constant variables are prohibited!} + +\subsection{Prefixes} +The following prefixes have to be applied to identifiers:\\ +\begin{tabular}{ll} +&\\ +\textbf{Type Definitions} & \textbf{Scope} \\ +\begin{tabular}{ll} +S& for structures \\ +C& for class\\ +I& for interface\\ +E& for enum\\ +T& for types (e.g. typedef in C++)\\ +&\\ +&\\ +\end{tabular} & + +\begin{tabular}{ll} +m & for member variables of classes\\ +cm & for a constant member\\ +%g & for global variables\\ +s & for static variables\\ +pa & for function parameters\\ +sm & static member\\ +scm & static constant member\\ +cg & for a global constant\\ +\end{tabular} \vspace{5mm}\\ + +\end{tabular} + +\noindent +Optionally also more detailed type information can be given with the variable name: + +\begin{tabular}{ll} +\textbf{Variable Types} & \textbf{Basic Data Types} \\ +\begin{tabular}{ll} +a & for arrays\\ +p & for pointers\\ +r & for references\\ +en & for enumerations\\ +st & for structures\\ +\end{tabular} & + +\begin{tabular}{ll} +c & for characters \\ +b & for booleans\\ +n & for integers\\ +f & for all floating point numbers\\ +\end{tabular} \vspace{1mm}\\ + +\textbf{Objects} & \\ +\begin{tabular}{ll} +o & for meaningless objects\\ +lst & for list objects\\ +v & for vector objects\\ +s & for string objects\\ +\end{tabular} &\\ +&\\ +\end{tabular} + +\noindent If these optional type prefixes are used an \_ has to be inserted between scope prefix and the optional type prefix in order to increase readability. + +\paragraph{Examples} +\begin{quote} +\verb|class CFunctionBlock;|\\ +\verb|int nNumber;|\\ +\verb|int *pnNumber = &nNumber;|\\ +\verb|char cKey;|\\ +\verb|bool g_bIsInitialized;|\\ +\verb|float m_fPi = 3.1415;|\\ +\verb|int anNumbers[10];|\\ +\end{quote} + + +\subsection{Constants} + With C++ it is prohibited to declare constants with the \#define statement (const has to be used instead). + A prefix cm, scm, or cg, depending on the cope of the constant should be used. + Never ever use ``magic numbers'' +(e.g. \verb|if (x == 3){...}|). Instead use constants. + + + + +\section{Classes} +In addition to the type--prefix the class identifiers have to start with a capital letter. +\subsection{Class Structure} + The declaration of the class content has to be done in the following order: +\begin{enumerate} +\item Public +\item Protected +\item Private +\end{enumerate} + +\subsection{Functions/Methods} +Function-- and method--identifiers have to start with a lower case letter. Functions with a return value of a Boolean type should have a name which points to the result (relate the name to the more likely result) and the name should start with the prefix ''is``. Set and get methods have to start with the appropriate prefix. Methods which are not modifying the state of the object have to be declared as a const method (keyword const). + +\subsection{Parameters} +Parameters which are keeping their value within a method have to be declared as const parameters. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Code Formatting} +\subsection{Indentation} +The tabulator width has to be set to 2. Instead of tabulator characters spaces have to inserted (usually there is an option for this in the IDE called: ``replace tabs''). +A new block has to be started at the same line as its initial statement. +An example is given in the appendix \ref{subsec:IndentionAndBlocks} of this document. + +\subsection{Blocks} +The left parenthesis of a block has to be in the same line as the construct. +The right parenthesis has to be in an own line. + +Single-line if statemtens are not allowed. +Parenthesis have to be used for all if, else, else if, for, while statments even when they contain only a single statement. + +An example how to format blocks is given in the appendix \ref{subsec:IndentionAndBlocks} of this document. + +\subsection{if-Statements} +Within if-statements you should consider the following rules: +\begin{itemize} +\item Put constants in if-expression on the left side. If you are missing on \verb|=| or a \verb|!| in a + comparison it will result in a compile error (e.g., \verb|if(if(cgMaxElements == mElements){|). +\item Put spaces around your operators (e.g., \verb|if(0 < i){|) +\item If you have several expressions in an if put parenthesis around each of them in order to avoid + ambiguous interpretation of the compiler (e.g., \verb|if((0 < i) && (5 > i)){|). + +\end{itemize} + + +\subsection{Eclipse} +For users of the IDE Eclipse with the CDT plugin we provide a style file that correctly formats your code to this rules. The file can be found in FORTE's main directory and is called \verb=fortestyle.xml=. This file can be imported into your FORTE project under the Menu Project/Properties and there in the tree element C/C++ General/Code Style. With the FORTE style file you can simple correctly format your file by pressing \verb=++f=. + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Exceptions for IEC 61499 Elements} + +\subsection{Naming of IEC 61499 Objects} + +All identifiers corresponding to IEC 61499 objecets (ressources) should be named as defined +in the IEC 61499 Standard. So they are execepted from the rules in sections 3 to 6. This has two advantages: +\begin{itemize} +\item No parsing/substitution of names in the code files is needed +\item It helps to differentiate between "runtime-code" and "user-code" +\end{itemize} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Performance and Size Considerations} + + + +\subsection{Function Inlining} +Our experience showed that functions shorter than 4 to 3 line should be inlined. This nearly always reduces the size of FORTE and therefore should increase its performance. However your mileage may vary. So please use it wisely and make tests and measurements + + +\subsection{Local Static Variables} +Local static variables can be rather helpful for implementing certain features. However be warned that they may have side effects. First of all modern C++ compilers will add code from \verb=libsupc++.a= which will protect them against multi threaded access. Depending on other features you use from the standard C++ library this can result in several kilobytes of binary image size increase. The compiler flag \verb=-fno-threadsafe-statics= can help here. But be warned that you may run in trouble with this flag. + +Currently FORTE is using just one local static variable, namely in the singleton pattern. For these it is safe to use the \verb=-fno-threadsafe-statics= flag. And because of other optimizations done to remove the standard lib parts this will significantly reduce your image size. + +Summarizing this short excursus better think twice before using a local static variable. FORTE will try to avoid them and future version will very likely not use them any more and so should you. + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\appendix +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\section{Examples} +\subsection{File Header} \label{subsec:FileHeader} + +\begin{lstlisting}[frame=trbl]{} +/******************************************************************************* + * Copyright (c) 2007 4DIAC - consortium. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + ******************************************************************************* +#ifndef _FILENAME_H_ +#define _FILENAME_H_ + +//! short class description +/*! long class description + */ +class CFooSpace { + public: + //! short description + int foo(void); /*!< long description + */ + protected: + //! short description + void bar(void); /*!> long description + */ + private: + //! short member var description + int m_nIsBar; /*!> long description + */ +}; + +#endif +\end{lstlisting} + +\newpage +\subsection{Indention and Blocks} \label{subsec:IndentionAndBlocks} +\begin{lstlisting}[frame=trbl]{} +int CFooSpace::foo(void){ + if(m_nIsBar){ + bar(); + return 1; + } + else { + megaBar(); + } + + if(!m_nIsBar){ + notBar(); + } + + return 0; +} +\end{lstlisting} + +\end{document} \ No newline at end of file diff --git a/doc/coding_rules/src/forte_coding_rules.tps b/doc/coding_rules/src/forte_coding_rules.tps new file mode 100644 index 000000000..a598f95b6 --- /dev/null +++ b/doc/coding_rules/src/forte_coding_rules.tps @@ -0,0 +1,38 @@ +[FormatInfo] +Type=TeXnicCenterProjectSessionInformation +Version=2 + +[SessionInfo] +ActiveTab=0 +FrameCount=1 +ActiveFrame=0 + +[Frame0] +Columns=1 +Rows=1 +Flags=2 +ShowCmd=3 +MinPos.x=-1 +MinPos.y=-1 +MaxPos.x=-4 +MaxPos.y=-23 +NormalPos.left=22 +NormalPos.top=25 +NormalPos.right=849 +NormalPos.bottom=513 +Class=CLatexEdit +Document=forte_coding_rules.tex + +[Frame0_Row0] +cyCur=609 +cyMin=10 + +[Frame0_Col0] +cxCur=1300 +cxMin=10 + +[Frame0_View0,0] +Cursor.row=95 +Cursor.column=11 +TopSubLine=90 + diff --git a/epl-v10.html b/epl-v10.html new file mode 100644 index 000000000..3998fcebe --- /dev/null +++ b/epl-v10.html @@ -0,0 +1,261 @@ + + + + + + +Eclipse Public License - Version 1.0 + + + + + + +

Eclipse Public License - v 1.0

+ +

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS +AGREEMENT.

+ +

1. DEFINITIONS

+ +

"Contribution" means:

+ +

a) in the case of the initial Contributor, the initial +code and documentation distributed under this Agreement, and

+

b) in the case of each subsequent Contributor:

+

i) changes to the Program, and

+

ii) additions to the Program;

+

where such changes and/or additions to the Program +originate from and are distributed by that particular Contributor. A +Contribution 'originates' from a Contributor if it was added to the +Program by such Contributor itself or anyone acting on such +Contributor's behalf. Contributions do not include additions to the +Program which: (i) are separate modules of software distributed in +conjunction with the Program under their own license agreement, and (ii) +are not derivative works of the Program.

+ +

"Contributor" means any person or entity that distributes +the Program.

+ +

"Licensed Patents" mean patent claims licensable by a +Contributor which are necessarily infringed by the use or sale of its +Contribution alone or when combined with the Program.

+ +

"Program" means the Contributions distributed in accordance +with this Agreement.

+ +

"Recipient" means anyone who receives the Program under +this Agreement, including all Contributors.

+ +

2. GRANT OF RIGHTS

+ +

a) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free copyright license to reproduce, prepare derivative works +of, publicly display, publicly perform, distribute and sublicense the +Contribution of such Contributor, if any, and such derivative works, in +source code and object code form.

+ +

b) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free patent license under Licensed Patents to make, use, sell, +offer to sell, import and otherwise transfer the Contribution of such +Contributor, if any, in source code and object code form. This patent +license shall apply to the combination of the Contribution and the +Program if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to be covered +by the Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder.

+ +

c) Recipient understands that although each Contributor +grants the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility to +secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow Recipient +to distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program.

+ +

d) Each Contributor represents that to its knowledge it +has sufficient copyright rights in its Contribution, if any, to grant +the copyright license set forth in this Agreement.

+ +

3. REQUIREMENTS

+ +

A Contributor may choose to distribute the Program in object code +form under its own license agreement, provided that:

+ +

a) it complies with the terms and conditions of this +Agreement; and

+ +

b) its license agreement:

+ +

i) effectively disclaims on behalf of all Contributors +all warranties and conditions, express and implied, including warranties +or conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose;

+ +

ii) effectively excludes on behalf of all Contributors +all liability for damages, including direct, indirect, special, +incidental and consequential damages, such as lost profits;

+ +

iii) states that any provisions which differ from this +Agreement are offered by that Contributor alone and not by any other +party; and

+ +

iv) states that source code for the Program is available +from such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for software +exchange.

+ +

When the Program is made available in source code form:

+ +

a) it must be made available under this Agreement; and

+ +

b) a copy of this Agreement must be included with each +copy of the Program.

+ +

Contributors may not remove or alter any copyright notices contained +within the Program.

+ +

Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution.

+ +

4. COMMERCIAL DISTRIBUTION

+ +

Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and +indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") +arising from claims, lawsuits and other legal actions brought by a third +party against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In +order to qualify, an Indemnified Contributor must: a) promptly notify +the Commercial Contributor in writing of such claim, and b) allow the +Commercial Contributor to control, and cooperate with the Commercial +Contributor in, the defense and any related settlement negotiations. The +Indemnified Contributor may participate in any such claim at its own +expense.

+ +

For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages.

+ +

5. NO WARRANTY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable laws, +damage to or loss of data, programs or equipment, and unavailability or +interruption of operations.

+ +

6. DISCLAIMER OF LIABILITY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+ +

7. GENERAL

+ +

If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further action +by the parties hereto, such provision shall be reformed to the minimum +extent necessary to make such provision valid and enforceable.

+ +

If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of the +date such litigation is filed.

+ +

All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of time +after becoming aware of such noncompliance. If all Recipient's rights +under this Agreement terminate, Recipient agrees to cease use and +distribution of the Program as soon as reasonably practicable. However, +Recipient's obligations under this Agreement and any licenses granted by +Recipient relating to the Program shall continue and survive.

+ +

Everyone is permitted to copy and distribute copies of this +Agreement, but in order to avoid inconsistency the Agreement is +copyrighted and may only be modified in the following manner. The +Agreement Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other than the +Agreement Steward has the right to modify this Agreement. The Eclipse +Foundation is the initial Agreement Steward. The Eclipse Foundation may +assign the responsibility to serve as the Agreement Steward to a +suitable separate entity. Each new version of the Agreement will be +given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version +of the Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives no +rights or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved.

+ +

This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No party +to this Agreement will bring a legal action under this Agreement more +than one year after the cause of action arose. Each party waives its +rights to a jury trial in any resulting litigation.

+ + + + \ No newline at end of file diff --git a/forte_config.h.in b/forte_config.h.in new file mode 100644 index 000000000..43eb31cd2 --- /dev/null +++ b/forte_config.h.in @@ -0,0 +1,92 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Martin Melik Merkumians, Ingo Hegny, Michael Hofmann + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +#undef IN +#undef OUT + + +#include + +/*!Define the number of times the CTimerHandler will be called per second. + * + * FORTE will use this information to calculate time values. + */ +const TForteUInt32 cg_nForteTicksPerSecond = ${FORTE_TicksPerSecond}; + +/*! \brief Defines the time base in units per second that will be used in the TIME data type + * + * The default value will be 1 000 000 000, which means that the time bas is 1 ns. + * For Smaller devices which do not use 64 bit datatypes a time base of 1000 (i.e., 1ms) + * or 1000000 (i.e., 1micro s) may be suitable. + */ +#define FORTE_TIME_BASE_UNITS_PER_SECOND ${FORTE_TimeBaseUnitsPerSecond} + + +/*! Define the initial size of the event chain list used in the event chain execution thread. + * + */ +const unsigned int cg_nEventChainEventListSize = ${FORTE_EventChainEventListSize}; + + +/*! Define the initial size of the event chain's external event list. + */ +const unsigned int cg_nEventChainExternalEventListSize = ${FORTE_EventChainExternalEventListSize}; + + +/*! Defines the number of pending communication messages can be handled by a communication function block + * + */ +const unsigned int cg_unCommunicationInterruptQueueSize = ${FORTE_CommunicationInterruptQueueSize}; + + +/*! Buffer size in bytes to be used by the ip layer as receive buffer. + * + */ +const unsigned int cg_unIPLayerRecvBufferSize = ${FORTE_IPLayerRecvBufferSize}; + +/*! \brief Define the management encapsulation protocol + * + * Currently two protocols are supported: + * # DEV_MGR for FBDK compliant XML encoded commands + * # WBXML_DEV_MGR for WAP Binary XML encoded commands + */ +#define FORTE_MGM_COMMAND_PROTOCOL ${FORTE_MGMCOMMANDPROTOCOL} + +//! Max supported hierarchy that can be provided in a management commands +#define FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY ${FORTE_MGM_MAX_SUPPOERTED_NAME_HIERACHY} + +/*! \brief FORTE string dict's initial string buffer size + * + * Depending on the FORTE_STRING_DICT_FIXED_MEMORY flag the string dict will reallocate if necessary. + */ +const TForteUInt32 cg_unStringDictInitialStringBufSize = ${FORTE_STRINGDICTINITIALSTRINGBUFSIZE}; + +/*! \brief FORTE string dict's initial max nr of strings + * + * Depending on the FORTE_STRING_DICT_FIXED_MEMORY flag the string dict will reallocate if necessary. + */ +const TForteUInt32 cg_unStringDictInitialMaxNrOfStrings = ${FORTE_STRINGDICTINITIALMAXNROFSTRINGS}; + + +#ifdef FORTE_SUPPORT_BOOT_FILE + +/*!Define the path to the Bootfile + */ +#define FORTE_BOOT_FILE_LOCATION "${FORTE_BootfileLocation}forte.fboot" + +const unsigned int cg_unBootFileLineBufSize = ${FORTE_BOOTFILELINEBUFSIZE}; + +#endif + +#endif diff --git a/fortestyle.xml b/fortestyle.xml new file mode 100644 index 000000000..892ca4d38 --- /dev/null +++ b/fortestyle.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/notice.html b/notice.html new file mode 100644 index 000000000..c3d34c3c2 --- /dev/null +++ b/notice.html @@ -0,0 +1,107 @@ + + + + + +Eclipse Foundation Software User Agreement + + + +

Eclipse Foundation Software User Agreement

+

April 9, 2014

+ +

Usage Of Content

+ +

THE ECLIPSE FOUNDATION MAKES AVAILABLE SOFTWARE, DOCUMENTATION, INFORMATION AND/OR OTHER MATERIALS FOR OPEN SOURCE PROJECTS + (COLLECTIVELY "CONTENT"). USE OF THE CONTENT IS GOVERNED BY THE TERMS AND CONDITIONS OF THIS AGREEMENT AND/OR THE TERMS AND + CONDITIONS OF LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW. BY USING THE CONTENT, YOU AGREE THAT YOUR USE + OF THE CONTENT IS GOVERNED BY THIS AGREEMENT AND/OR THE TERMS AND CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR + NOTICES INDICATED OR REFERENCED BELOW. IF YOU DO NOT AGREE TO THE TERMS AND CONDITIONS OF THIS AGREEMENT AND THE TERMS AND + CONDITIONS OF ANY APPLICABLE LICENSE AGREEMENTS OR NOTICES INDICATED OR REFERENCED BELOW, THEN YOU MAY NOT USE THE CONTENT.

+ +

Applicable Licenses

+ +

Unless otherwise indicated, all Content made available by the Eclipse Foundation is provided to you under the terms and conditions of the Eclipse Public License Version 1.0 + ("EPL"). A copy of the EPL is provided with this Content and is also available at http://www.eclipse.org/legal/epl-v10.html. + For purposes of the EPL, "Program" will mean the Content.

+ +

Content includes, but is not limited to, source code, object code, documentation and other files maintained in the Eclipse Foundation source code + repository ("Repository") in software modules ("Modules") and made available as downloadable archives ("Downloads").

+ +
    +
  • Content may be structured and packaged into modules to facilitate delivering, extending, and upgrading the Content. Typical modules may include plug-ins ("Plug-ins"), plug-in fragments ("Fragments"), and features ("Features").
  • +
  • Each Plug-in or Fragment may be packaged as a sub-directory or JAR (Java™ ARchive) in a directory named "plugins".
  • +
  • A Feature is a bundle of one or more Plug-ins and/or Fragments and associated material. Each Feature may be packaged as a sub-directory in a directory named "features". Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of the Plug-ins + and/or Fragments associated with that Feature.
  • +
  • Features may also include other Features ("Included Features"). Within a Feature, files named "feature.xml" may contain a list of the names and version numbers of Included Features.
  • +
+ +

The terms and conditions governing Plug-ins and Fragments should be contained in files named "about.html" ("Abouts"). The terms and conditions governing Features and +Included Features should be contained in files named "license.html" ("Feature Licenses"). Abouts and Feature Licenses may be located in any directory of a Download or Module +including, but not limited to the following locations:

+ +
    +
  • The top-level (root) directory
  • +
  • Plug-in and Fragment directories
  • +
  • Inside Plug-ins and Fragments packaged as JARs
  • +
  • Sub-directories of the directory named "src" of certain Plug-ins
  • +
  • Feature directories
  • +
+ +

Note: if a Feature made available by the Eclipse Foundation is installed using the Provisioning Technology (as defined below), you must agree to a license ("Feature Update License") during the +installation process. If the Feature contains Included Features, the Feature Update License should either provide you with the terms and conditions governing the Included Features or +inform you where you can locate them. Feature Update Licenses may be found in the "license" property of files named "feature.properties" found within a Feature. +Such Abouts, Feature Licenses, and Feature Update Licenses contain the terms and conditions (or references to such terms and conditions) that govern your use of the associated Content in +that directory.

+ +

THE ABOUTS, FEATURE LICENSES, AND FEATURE UPDATE LICENSES MAY REFER TO THE EPL OR OTHER LICENSE AGREEMENTS, NOTICES OR TERMS AND CONDITIONS. SOME OF THESE +OTHER LICENSE AGREEMENTS MAY INCLUDE (BUT ARE NOT LIMITED TO):

+ + + +

IT IS YOUR OBLIGATION TO READ AND ACCEPT ALL SUCH TERMS AND CONDITIONS PRIOR TO USE OF THE CONTENT. If no About, Feature License, or Feature Update License is provided, please +contact the Eclipse Foundation to determine what terms and conditions govern that particular Content.

+ + +

Use of Provisioning Technology

+ +

The Eclipse Foundation makes available provisioning software, examples of which include, but are not limited to, p2 and the Eclipse + Update Manager ("Provisioning Technology") for the purpose of allowing users to install software, documentation, information and/or + other materials (collectively "Installable Software"). This capability is provided with the intent of allowing such users to + install, extend and update Eclipse-based products. Information about packaging Installable Software is available at http://eclipse.org/equinox/p2/repository_packaging.html + ("Specification").

+ +

You may use Provisioning Technology to allow other parties to install Installable Software. You shall be responsible for enabling the + applicable license agreements relating to the Installable Software to be presented to, and accepted by, the users of the Provisioning Technology + in accordance with the Specification. By using Provisioning Technology in such a manner and making it available in accordance with the + Specification, you further acknowledge your agreement to, and the acquisition of all necessary rights to permit the following:

+ +
    +
  1. A series of actions may occur ("Provisioning Process") in which a user may execute the Provisioning Technology + on a machine ("Target Machine") with the intent of installing, extending or updating the functionality of an Eclipse-based + product.
  2. +
  3. During the Provisioning Process, the Provisioning Technology may cause third party Installable Software or a portion thereof to be + accessed and copied to the Target Machine.
  4. +
  5. Pursuant to the Specification, you will provide to the user the terms and conditions that govern the use of the Installable + Software ("Installable Software Agreement") and such Installable Software Agreement shall be accessed from the Target + Machine in accordance with the Specification. Such Installable Software Agreement must inform the user of the terms and conditions that govern + the Installable Software and must solicit acceptance by the end user in the manner prescribed in such Installable Software Agreement. Upon such + indication of agreement by the user, the provisioning Technology will complete installation of the Installable Software.
  6. +
+ +

Cryptography

+ +

Content may contain encryption software. The country in which you are currently may have restrictions on the import, possession, and use, and/or re-export to + another country, of encryption software. BEFORE using any encryption software, please check the country's laws, regulations and policies concerning the import, + possession, or use, and re-export of encryption software, to see if this is permitted.

+ +

Java and all Java-based trademarks are trademarks of Oracle Corporation in the United States, other countries, or both.

+ + diff --git a/setup_digime74.sh b/setup_digime74.sh new file mode 100644 index 000000000..ee59e0515 --- /dev/null +++ b/setup_digime74.sh @@ -0,0 +1,6 @@ +#!/bin/sh +echo "----------------------------------------------------------------------------" +echo "BUILD-SYSTEM was switched from automake to cmake" +echo "----------------------------------------------------------------------------" +echo "" +echo "run cmake or cmake-gui to set up development environment" \ No newline at end of file diff --git a/setup_phycoreat91.sh b/setup_phycoreat91.sh new file mode 100644 index 000000000..ee59e0515 --- /dev/null +++ b/setup_phycoreat91.sh @@ -0,0 +1,6 @@ +#!/bin/sh +echo "----------------------------------------------------------------------------" +echo "BUILD-SYSTEM was switched from automake to cmake" +echo "----------------------------------------------------------------------------" +echo "" +echo "run cmake or cmake-gui to set up development environment" \ No newline at end of file diff --git a/setup_posix-ppc.sh b/setup_posix-ppc.sh new file mode 100644 index 000000000..189fd1d8c --- /dev/null +++ b/setup_posix-ppc.sh @@ -0,0 +1,7 @@ +#!/bin/bash +#!/bin/bash +echo "----------------------------------------------------------------------------" +echo "BUILD-SYSTEM was switched from automake to cmake" +echo "----------------------------------------------------------------------------" +echo "" +echo "run cmake or cmake-gui to set up development environment" \ No newline at end of file diff --git a/setup_posix.sh b/setup_posix.sh new file mode 100644 index 000000000..22cdf43d5 --- /dev/null +++ b/setup_posix.sh @@ -0,0 +1,38 @@ +#!/bin/bash +echo "----------------------------------------------------------------------------" +echo " Automatically set up development environment for POSIX-platform" +echo "----------------------------------------------------------------------------" +echo "" +echo " Includes 64bit-datatypes, float-datatypes, Ethernet-Interface," +echo " ASN1-encoding, ..." +echo "" +echo " To include tests set directories for boost-test-framework and " +echo " set FORTE_TESTS-option to 'ON'" +echo "" +echo "----------------------------------------------------------------------------" + +export forte_bin_dir="bin/posix" + +#set to boost-include directory +export forte_boost_test_inc_dirs="" +#set to boost-library directory +export forte_boost_test_lib_dirs="" + +if [ ! -d "$forte_bin_dir" ]; then + mkdir -p "$forte_bin_dir" +fi + +if [ -d "$forte_bin_dir" ]; then + + echo "For building forte go to $forte_bin_dir and execute \"make\"" + echo "forte can be found at ${forte_bin_dir}/src" + echo "forte_tests can be found at ${forte_bin_dir}/tests" + + + cd "./$forte_bin_dir" + + cmake -G "Unix Makefiles" -DFORTE_ARCHITECTURE=Posix -DFORTE_COM_ETH=ON -DFORTE_COM_FBDK=ON -DFORTE_COM_LOCAL=ON -DFORTE_TESTS=OFF -DFORTE_TESTS_INC_DIRS=${forte_boost_test_inc_dirs} -DFORTE_TESTS_LINK_DIRS=${forte_boost_test_inc_dirs} -DFORTE_MODULE_CONVERT=ON -DFORTE_MODULE_MATH=ON -DFORTE_MODULE_IEC61131=ON -DFORTE_MODULE_OSCAT=ON -DFORTE_MODULE_Test=ON -DFORTE_MODULE_UTILS=ON ../../ +else + echo "unable to create ${forte_bin_dir}" + exit 1 +fi diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..01f21d2fc --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,283 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2014 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Micheal Hofmann, Alois Zoitl, Stanislav Meduna, Gerhard Ebenhofer, +# * Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ + + +forte_create_modules_file(${CMAKE_CURRENT_SOURCE_DIR}/modules/) +forte_add_subdirectory(arch) +forte_add_subdirectory(core) +forte_add_subdirectory(modules) +forte_add_subdirectory(stdfblib) + +SET(SOURCE_GROUP core) +forte_add_sourcefile_with_path_hcpp(${FORTE_BINARY_DIR}/stringlist) +set_source_files_properties(${FORTE_BINARY_DIR}/stringlist.h PROPERTIES GENERATED TRUE) +set_source_files_properties(${FORTE_BINARY_DIR}/stringlist.cpp PROPERTIES GENERATED TRUE) + + +if(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) + forte_add_sourcefile_with_path_hcpp(${FORTE_BINARY_DIR}/forteinit) + set_source_files_properties(${FORTE_BINARY_DIR}/forteinit.h PROPERTIES GENERATED TRUE) + set_source_files_properties(${FORTE_BINARY_DIR}/forteinit.cpp PROPERTIES GENERATED TRUE) +ENDIF(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) + +####################################################################################### +# Define global Include-directorys +####################################################################################### +GET_PROPERTY(INCLUDE_DIRECTORIES GLOBAL PROPERTY FORTE_INCLUDE_DIRECTORIES) +LIST(LENGTH INCLUDE_DIRECTORIES len) +IF(len GREATER 0) + LIST(REMOVE_DUPLICATES INCLUDE_DIRECTORIES) + LIST(REVERSE INCLUDE_DIRECTORIES) # bugfix, for replaced include files +ENDIF(len GREATER 0) +INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES}) +INCLUDE_DIRECTORIES(./) +INCLUDE_DIRECTORIES(${FORTE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${FORTE_BINARY_DIR}/src_gen) +####################################################################################### +# Define directories for Libraries +####################################################################################### +GET_PROPERTY(LINK_DIRECTORIES GLOBAL PROPERTY FORTE_LINK_DIRECTORIES) +LIST(LENGTH LINK_DIRECTORIES len) +IF(len GREATER 0) + LIST(REMOVE_DUPLICATES LINK_DIRECTORIES) +ENDIF(len GREATER 0) +LINK_DIRECTORIES(${LINK_DIRECTORIES}) + +####################################################################################### +# Define directories for Libraries +####################################################################################### +GET_PROPERTY(DEFINITION GLOBAL PROPERTY FORTE_DEFINITION) +ADD_DEFINITIONS (${DEFINITION}) + +####################################################################################### +# Exclude FBs +####################################################################################### +set(FORTE_EXCLUDE_FBS "" CACHE STRING "Exclude Function blocks") +mark_as_advanced(FORTE_EXCLUDE_FBS) + +IF(FORTE_EXCLUDE_FBS) + STRING(REGEX MATCHALL "[^ ,;][^ ,;]*" FBLIST ${FORTE_EXCLUDE_FBS}) + + FOREACH(FB ${FBLIST}) + forte_remove_sourcefile_h(${FB}.h) + forte_remove_sourcefile_cpp(${FB}.cpp) + ENDFOREACH(FB) +ENDIF(FORTE_EXCLUDE_FBS) + +GET_PROPERTY(PLATFORM_REMOVES GLOBAL PROPERTY FORTE_PLATFORM_REMOVES) +FOREACH(FB ${PLATFORM_REMOVES}) + forte_remove_sourcefile_h(${FB}.h) + forte_remove_sourcefile_cpp(${FB}.cpp) +ENDFOREACH(FB) + +####################################################################################### +# Setup Forte-Executeable with all Functionblocks +####################################################################################### + +GET_PROPERTY(SOURCE_H GLOBAL PROPERTY FORTE_SOURCE_H) +GET_PROPERTY(SOURCE_H_GROUP GLOBAL PROPERTY FORTE_SOURCE_H_GROUP) +LIST(APPEND SOURCE_FILES ${SOURCE_H}) +LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_H_GROUP}) + +GET_PROPERTY(SOURCE_CPP GLOBAL PROPERTY FORTE_SOURCE_CPP) +GET_PROPERTY(SOURCE_CPP_GROUP_STRUCT GLOBAL PROPERTY FORTE_SOURCE_CPP_GROUP) +LIST(APPEND SOURCE_FILES ${SOURCE_CPP}) +LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_CPP_GROUP_STRUCT}) + +GET_PROPERTY(SOURCE_C GLOBAL PROPERTY FORTE_SOURCE_C) +GET_PROPERTY(SOURCE_C_GROUP_STRUCT GLOBAL PROPERTY FORTE_SOURCE_C_GROUP) +LIST(APPEND SOURCE_FILES ${SOURCE_C}) +LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_C_GROUP_STRUCT}) + +#FOREACH(FILE ${SOURCE_H}) + # Do not pars stringlist, as these files will be generated +# STRING(REGEX MATCH ".*stringlist\\.(cpp|h).*" REGEX_STRINGS ${FBLIB_FILE}) +# IF(NOT REGEX_STRINGS) +# ENDIF(NOT REGEX_STRINGS) +#ENDFOREACH(FILE) + +############################################################################# +# Configure Network Layers +############################################################################# + +GET_PROPERTY(LAYER_CLASS GLOBAL PROPERTY FORTE_LAYER_CLASS) +GET_PROPERTY(LAYER_CONFIGNAME GLOBAL PROPERTY FORTE_LAYER_CONFIGNAME) +GET_PROPERTY(LAYER_FILENAME GLOBAL PROPERTY FORTE_LAYER_FILENAME) +LIST(LENGTH LAYER_CLASS LAYER_CLASS_LEN) +math(EXPR LAYER_CLASS_LEN ${LAYER_CLASS_LEN}-1) + +SET(LAYERMANAGER_INCLUDE "") +SET(LAYERMANAGER_INSTANCE "if(false){}") + +FOREACH(POS RANGE ${LAYER_CLASS_LEN}-1) + LIST(GET LAYER_CLASS ${POS} CLASS) + LIST(GET LAYER_CONFIGNAME ${POS} CONFIGNAME) + LIST(GET LAYER_FILENAME ${POS} FILENAME) + SET(LAYERMANAGER_INCLUDE "${LAYERMANAGER_INCLUDE}#include<${FILENAME}>\n") + SET(LAYERMANAGER_INSTANCE "${LAYERMANAGER_INSTANCE}\nelse if(0 == strcmp(\"${CONFIGNAME}\", pa_acLayerIdentifier)){\nm_poNewLayer = new ${CLASS}(pa_poUpperLayer, pa_poComFB);\n}\n") +ENDFOREACH(POS) + +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/core/cominfra/comlayersmanager.cpp.in ${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager_new.cpp) +forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager_new.cpp ${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager.cpp) +file(REMOVE ${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager_new.cpp) + +############################################################################# +# Load FORTE Extension Files +############################################################################# + +GET_PROPERTY(EXTENSION_FILES GLOBAL PROPERTY FORTE_EXTENSION_FILES) +LIST(LENGTH EXTENSION_FILES len) +IF(len GREATER 0) + LIST(REMOVE_DUPLICATES EXTENSION_FILES) + FOREACH(FILE ${EXTENSION_FILES}) + INCLUDE("${FILE}") + ENDFOREACH(FILE) +ENDIF(len GREATER 0) + +############################################################################# +# Add Files to source-group +############################################################################# +LIST(LENGTH SOURCE_FILES SOURCE_LEN) +LIST(LENGTH SOURCE_FILES_GROUP SOURCE_GROUP_LEN) +math(EXPR SOURCE_LEN ${SOURCE_LEN}-1) +math(EXPR SOURCE_GROUP_LEN ${SOURCE_GROUP_LEN}-1) + +FOREACH(POS RANGE ${SOURCE_LEN}-1) + LIST(GET SOURCE_FILES ${POS} FILE) + LIST(GET SOURCE_FILES_GROUP ${POS} GROUP) + source_group(${GROUP} FILES ${FILE}) +ENDFOREACH(POS) + +# remove duplicate entries +LIST(LENGTH SOURCE_FILES len) +IF(len GREATER 0) + LIST(REMOVE_DUPLICATES SOURCE_FILES) +ENDIF(len GREATER 0) + +SET(WRITE_FILE "") +FOREACH(FILE ${SOURCE_FILES}) + SET(WRITE_FILE "${WRITE_FILE}${FILE}\n") +ENDFOREACH(FILE) +FILE(WRITE ${CMAKE_BINARY_DIR}/file_list.txt "${WRITE_FILE}") + +###################################################################################### +# Architecutre to build forte on +###################################################################################### +set(FORTE_ARCHITECTURE "None" CACHE STRING "Architecture to build FORTE on") +GET_PROPERTY(architectures GLOBAL PROPERTY FORTE_ARCHITECTURES) +list(SORT architectures) +set_property(CACHE FORTE_ARCHITECTURE PROPERTY STRINGS None ${architectures}) + + +####################################################################################### +# Create Exe File +####################################################################################### +#ADD_EXECUTABLE (forte ${SOURCE_CPP} ${SOURCE_H}) + +####################################################################################### +# Create Files +####################################################################################### +if(${FORTE_BUILD_TYPE} STREQUAL EXECUTABLE) +ADD_EXECUTABLE (forte ${SOURCE_CPP} ${SOURCE_C} ${SOURCE_H}) +ENDIF(${FORTE_BUILD_TYPE} STREQUAL EXECUTABLE) + +if(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY) +ADD_LIBRARY (forte STATIC ${SOURCE_CPP} ${SOURCE_C} ${SOURCE_H}) +forte_add_definition("-DFORTE_STATIC_LIB") +ADD_DEFINITIONS(-DFORTE_STATIC_LIB) +ENDIF(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY) + +if(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) +ADD_LIBRARY (forte SHARED ${SOURCE_CPP} ${SOURCE_C} ${SOURCE_H} ) +forte_add_definition("-DFORTE_STATIC_LIB") +forte_add_definition("-DFORTE_SHARED_LIB") +ADD_DEFINITIONS(-DFORTE_STATIC_LIB) +ADD_DEFINITIONS(-DFORTE_SHARED_LIB) +ENDIF(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) + +if("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + ADD_DEFINITIONS (-D_CRT_SECURE_NO_DEPRECATE) + ADD_DEFINITIONS (-D_CRT_NONSTDC_NO_DEPRECATE) + ADD_DEFINITIONS (-D_SCL_SECURE_NO_WARNINGS) + ADD_DEFINITIONS (-D_CRT_SECURE_NO_WARNINGS) +endif() + +get_target_property(existing_link_flags forte LINK_FLAGS) +if(existing_link_flags) + set_property(GLOBAL APPEND PROPERTY FORTE_LINK_FLAGS ${existing_link_flags}) +endif() + +GET_PROPERTY(link_flags GLOBAL PROPERTY FORTE_LINK_FLAGS) + +set_target_properties(forte PROPERTIES LINK_FLAGS "${link_flags}") + +install(TARGETS forte RUNTIME DESTINATION bin) + +####################################################################################### +# Link Libraries to the Executeable +####################################################################################### +# get Linker-Direcotries from Modules +get_property(LINK_LIBRARY GLOBAL PROPERTY FORTE_LINK_LIBRARY) +TARGET_LINK_LIBRARIES (forte ${LINK_LIBRARY} ) + +####################################################################################### +# Generate stringlist and modules +####################################################################################### + +if(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) #No reason to do this if we're building an executable... + Message("lib") + ADD_CUSTOM_TARGET(forte_init_generator COMMAND ${CMAKE_COMMAND} -DFORTE_STATIC_LIB:STRING="TRUE" -DFORTE_BINARY_DIR:STRING="${CMAKE_BINARY_DIR}" -DFORTE_SOURCE_DIR:STRING="${CMAKE_SOURCE_DIR}" -DFORTE_USE_64BIT_DATATYPES:STRING="${FORTE_USE_64BIT_DATATYPES}" -DFORTE_USE_REAL_DATATYPE:STRING="${FORTE_USE_REAL_DATATYPE}" -DFORTE_USE_LREAL_DATATYPE:STRING="${FORTE_USE_LREAL_DATATYPE}" -DFORTE_SUPPORT_ARRAYS:STRING="${FORTE_SUPPORT_ARRAYS}" -DFORTE_LITTLE_ENDIAN:STRING=${FORTE_LITTLE_ENDIAN} -DFORTE_BIG_ENDIAN:STRING=${FORTE_BIG_ENDIAN} -DFORTE_LOGLEVEL:STRING="${FORTE_LOGLEVEL}" -P ${FORTE_BUILDSUPPORT_DIRECTORY}/generate_init.cmake) # + ADD_DEPENDENCIES (forte forte_init_generator) + ADD_DEPENDENCIES (forte_init_generator forte_generate_modules_cmake_files) +endif(${FORTE_BUILD_TYPE} STREQUAL STATIC_LIBRARY OR ${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) + +ADD_CUSTOM_TARGET(forte_generate_modules_cmake_files COMMAND ${CMAKE_COMMAND} -DFORTE_MODULE_DIR:STRING=${CMAKE_CURRENT_SOURCE_DIR}/modules/ -P ${FORTE_BUILDSUPPORT_DIRECTORY}/generate_modules_cmake_file.cmake) +ADD_DEPENDENCIES (forte forte_generate_modules_cmake_files) +ADD_CUSTOM_TARGET(forte_stringlist_generator COMMAND ${CMAKE_COMMAND} -DFORTE_LINKED_STRINGDICT:STRING="${FORTE_LINKED_STRINGDICT}" -DFORTE_BINARY_DIR:STRING="${CMAKE_BINARY_DIR}" -DFORTE_SOURCE_DIR:STRING="${CMAKE_CURRENT_SOURCE_DIR}" -P ${FORTE_BUILDSUPPORT_DIRECTORY}/generate_stringlist.cmake) +ADD_DEPENDENCIES (forte forte_stringlist_generator) +ADD_DEPENDENCIES (forte_stringlist_generator forte_generate_modules_cmake_files) + +####################################################################################### +# Generate stringlist for every source file +####################################################################################### +if(FORTE_LINKED_STRINGDICT) + set(ENABLE_GENERATED_SOURCE_CPP ON) + ADD_DEPENDENCIES (forte forte_stringlist_externals) +endif(FORTE_LINKED_STRINGDICT) + +####################################################################################### +# Enable autogenerated source files +####################################################################################### +if(ENABLE_GENERATED_SOURCE_CPP) + ADD_DEFINITIONS ("-DFORTE_ENABLE_GENERATED_SOURCE_CPP") +endif(ENABLE_GENERATED_SOURCE_CPP) + + +####################################################################################### +# Link everything together +####################################################################################### +# link libraries to executeable +GET_PROPERTY(LINK_LIBRARY GLOBAL PROPERTY MODULE_LINK_LIBRARY) +TARGET_LINK_LIBRARIES (forte ${LINK_LIBRARY} ) + + +####################################################################################### +# Add post build commands +####################################################################################### +GET_PROPERTY(POST_BUILD_COM GLOBAL PROPERTY FORTE_POST_BUILD_COMMAND) +STRING(LENGTH "${POST_BUILD_COM}" LEN_POST_BUILD_COM) +if(NOT LEN_POST_BUILD_COM EQUAL 0) + ADD_CUSTOM_COMMAND(TARGET forte POST_BUILD ${POST_BUILD_COM}) +endif(NOT LEN_POST_BUILD_COM EQUAL 0) + + diff --git a/src/arch/CMakeLists.txt b/src/arch/CMakeLists.txt new file mode 100644 index 000000000..dc918ec52 --- /dev/null +++ b/src/arch/CMakeLists.txt @@ -0,0 +1,22 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2012 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl, Patrick Smejkal +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +SET(SOURCE_GROUP ${SOURCE_GROUP}\\arch) + +add_subdirectory(ecos) +add_subdirectory(netos) +add_subdirectory(posix) +add_subdirectory(win32) +add_subdirectory(be_m1) + +forte_add_sourcefile_hcpp(timerha devlog) + diff --git a/src/arch/be_m1/BE_RMT_DEV.cpp b/src/arch/be_m1/BE_RMT_DEV.cpp new file mode 100644 index 000000000..3b95f9a5a --- /dev/null +++ b/src/arch/be_m1/BE_RMT_DEV.cpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "BE_RMT_DEV.h" + +BE_RMT_DEV::BE_RMT_DEV(CFORTEModule &pa_roModule) : + RMT_DEV(), m_roModule(pa_roModule){ + +} + +BE_RMT_DEV::~BE_RMT_DEV(){ + +} + diff --git a/src/arch/be_m1/BE_RMT_DEV.h b/src/arch/be_m1/BE_RMT_DEV.h new file mode 100644 index 000000000..f0da9568d --- /dev/null +++ b/src/arch/be_m1/BE_RMT_DEV.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef BE_RMT_DEV_H_ +#define BE_RMT_DEV_H_ + +#include "../../../stdfblib/ita/RMT_DEV.h" +#include + +class BE_RMT_DEV : public RMT_DEV{ + public: + BE_RMT_DEV(CFORTEModule &pa_roModule); + + virtual ~BE_RMT_DEV(); + + CFORTEModule & getModule() const{ + return m_roModule; + } + protected: + private: + CFORTEModule & m_roModule; +}; + +#endif /* BE_RMT_DEV_H_ */ diff --git a/src/arch/be_m1/BE_SVIFB.cpp b/src/arch/be_m1/BE_SVIFB.cpp new file mode 100644 index 000000000..9034b2025 --- /dev/null +++ b/src/arch/be_m1/BE_SVIFB.cpp @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "BE_SVIFB.h" +#include "BE_RMT_DEV.h" + +const TForteUInt32 BE_SVIFB::scm_anBE_SVI_Types[] = { SVI_F_UNKNOWN, // e_ANY, + SVI_F_BOOL8, // e_BOOL, + SVI_F_SINT8, // e_SINT, + SVI_F_SINT16, // e_INT, + SVI_F_SINT32, // e_DINT, + SVI_F_SINT64, // e_LINT, + SVI_F_UINT8, // e_USINT, + SVI_F_UINT16, // e_UINT, + SVI_F_UINT32, // e_UDINT, + SVI_F_UINT64, // e_ULINT, + SVI_F_UINT8, // e_BYTE, + SVI_F_UINT16, // e_WORD, + SVI_F_UINT32, // e_DWORD, + SVI_F_UINT64, // e_LWORD, + SVI_F_SINT64, // e_DATE, + SVI_F_SINT64, // e_TIME_OF_DAY, + SVI_F_SINT64, // e_DATE_AND_TIME, + SVI_F_SINT64, // e_TIME, //until here simple Datatypes + SVI_F_REAL32, // e_REAL, + SVI_F_REAL64, // e_LREAL, + SVI_F_STRINGLSTBASE, // e_STRING, + SVI_F_STRINGLSTBASE, // e_WSTRING, + SVI_F_UNKNOWN, // e_DerivedData, + SVI_F_UNKNOWN, // e_DirectlyDerivedData, + SVI_F_UNKNOWN, // e_EnumeratedData, + SVI_F_UNKNOWN, // e_SubrangeData, + SVI_F_UNKNOWN, // e_ARRAY, //according to the compliance profile + SVI_F_UNKNOWN // e_STRUCT, + // e_External = 256, // Base for CIEC_ANY based types outside of the forte base + // e_Max = 65535 // Guarantees at least 16 bits - otherwise gcc will optimizes on some platforms + }; + +const TForteUInt32 BE_SVIFB::scm_anBE_SVI_VarSizes[] = { 0, // e_ANY, + 1, // e_BOOL, + 1, // e_SINT, + 2, // e_INT, + 4, // e_DINT, + 8, // e_LINT, + 1, // e_USINT, + 2, // e_UINT, + 4, // e_UDINT, + 8, // e_ULINT, + 1, // e_BYTE, + 2, // e_WORD, + 4, // e_DWORD, + 8, // e_LWORD, + 8, // e_DATE, + 8, // e_TIME_OF_DAY, + 8, // e_DATE_AND_TIME, + 8, // e_TIME, //until here simple Datatypes + 4, // e_REAL, + 8, // e_LREAL, + 4, // e_STRING, + 4, // e_WSTRING, + 0, // e_DerivedData, + 0, // e_DirectlyDerivedData, + 0, // e_EnumeratedData, + 0, // e_SubrangeData, + 0, // e_ARRAY, //according to the compliance profile + 0 // e_STRUCT, + // e_External = 256, // Base for CIEC_ANY based types outside of the forte base + // e_Max = 65535 // Guarantees at least 16 bits - otherwise gcc will optimizes on some platforms + }; + +bool BE_SVIFB::registerSVIvar(const CIEC_STRING& pa_roID, CIEC_ANY& pa_roValue, const TForteUInt32 pa_nMode){ + BE_RMT_DEV& roDev(static_cast(getResource().getDevice())); + + bool bRetVal = (OK == roDev.getModule().GetSVIHandler().AddGlobVar(((CHAR *) pa_roID.getValue()), pa_nMode | scm_anBE_SVI_Types[pa_roValue.getDataTypeID()], scm_anBE_SVI_VarSizes[pa_roValue.getDataTypeID()], (UINT32*) (pa_roValue.getDataPtr()), 0, 0)); + roDev.getModule().CfgRead(); + return bRetVal; +} diff --git a/src/arch/be_m1/BE_SVIFB.h b/src/arch/be_m1/BE_SVIFB.h new file mode 100644 index 000000000..425f8589e --- /dev/null +++ b/src/arch/be_m1/BE_SVIFB.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef BE_SVIFB_H_ +#define BE_SVIFB_H_ + +#include +#include "funcbloc.h" + +class BE_SVIFB : public CFunctionBlock{ + public: + BE_SVIFB(CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) : + CFunctionBlock(pa_poSrcRes, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData){ + } + + protected: + bool registerSVIvar(const CIEC_STRING& pa_roID, CIEC_ANY& pa_roValue, const TForteUInt32 pa_nMode); + + private: + static const TForteUInt32 scm_anBE_SVI_Types[]; + static const TForteUInt32 scm_anBE_SVI_VarSizes[]; + +}; + +#endif /* BE_SVIFB_H_ */ diff --git a/src/arch/be_m1/CMakeLists.txt b/src/arch/be_m1/CMakeLists.txt new file mode 100644 index 000000000..dbe39c377 --- /dev/null +++ b/src/arch/be_m1/CMakeLists.txt @@ -0,0 +1,94 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2105 ACIN and fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +SET(SOURCE_GROUP ${SOURCE_GROUP}\\be_m1) + +forte_add_architecture("Bachmann M1") + +if("${FORTE_ARCHITECTURE}" STREQUAL "Bachmann M1") + + + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + forte_add_sourcefile_hcpp(thread vxworkstimeha sync) + forte_add_sourcefile_hcpp(fortemodule) + + forte_add_sourcefile_h(stdint.h) + + forte_add_sourcefile_hcpp(GET_CHAN_INFO) + forte_add_sourcefile_hcpp(GET_VALUE) + forte_add_sourcefile_hcpp(SET_VALUE) + forte_add_sourcefile_hcpp(BE_SVIFB SVIsend_1 SVIreceive_1 BE_RMT_DEV) + + + if(FORTE_COM_ETH) + forte_add_sourcefile_hcpp( ../fdselecthand ../bsdsocketinterf) + forte_add_sourcefile_h(../gensockhand.h) + forte_add_sourcefile_h(sockhand.h) + endif(FORTE_COM_ETH) + + forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR}) + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + forte_add_definition("-W -Wall -Wextra -Woverloaded-virtual -Wconversion -DFORTE_LITTLE_ENDIAN -DVXWORKS -O0 -ggdb") + forte_add_definition("-fno-rtti") + + forte_add_link_flags("-Wl,-M -Wl,-Map -Wl,forte.map -Wl,-cref") + + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/forte.ver.in ${CMAKE_BINARY_DIR}/forte.new.ver) + forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/forte.new.ver ${CMAKE_BINARY_DIR}/forte.ver) + CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/CPPLIB.ver.in ${CMAKE_BINARY_DIR}/CPPLIB.new.ver) + forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/CPPLIB.new.ver ${CMAKE_BINARY_DIR}/CPPLIB.ver) + + + set(GNU_TOOLS C:/bachmann/SolutionCenter/V1.70Release/cutils/GnuTools) + set(MSYS_PATH C:/bachmann/SolutionCenter/V1.70Release/cutils/mcsdk/msys) + set(GNU_TOOLS_PATH ${GNU_TOOLS}/../GnuTools-4.1.2) + set(MSYS_UTILS_PATH ${MSYS_PATH}/utl) + +# Base directory of the compiler installation + set(GCC_BASE ${GNU_TOOLS_PATH}) + set(CPU_FAMILY I80X86) + +# Some settings need to be overwritten + set(GCC_BIN_DIR ${GCC_BASE}/bin) + set(BINUTILS_BIN_DIR ${GCC_BASE}/bin) + set(GCC_EXEC_PREFIX ${GCC_BASE}/lib/gcc/i386-wrs-vxworks/4.1.2/) + set(COMPILER_LIB_PATHS -L "${GCC_EXEC_PREFIX}" -L "${GCC_BASE}/i386-wrs-vxworks/lib") + set(BASE_LIB_PATH -L "${GNU_TOOLS_PATH}/lib") + set(M1_LD_PATH ${BASE_LIB_PATH} ${COMPILER_LIB_PATHS}) + +# Names of compiler frontends and linkers have changed + set(M1_CC "${GCC_BIN_DIR}/i386-wrs-vxworks-gcc") + set(M1_CPP "${GCC_BIN_DIR}/i386-wrs-vxworks-g++") + set(M1_LD "${BINUTILS_BIN_DIR}/i386-wrs-vxworks-ld") + set(M1_AR "${BINUTILS_BIN_DIR}/i386-wrs-vxworks-ar") + set(M1_NM "${BINUTILS_BIN_DIR}/i386-wrs-vxworks-nm") + set(M1_MUNCH "${MSYS_UTILS_PATH}/munch-new") + set(M1_MBIND "${MSYS_UTILS_PATH}/mbind") + set(M1_CONFC "${MSYS_UTILS_PATH}/confc") + set(M1_SYMCONV "${MSYS_UTILS_PATH}/symconv") + + forte_add_post_build_command(COMMAND ${M1_CONFC} ${CMAKE_CURRENT_SOURCE_DIR}/forte.cru forte.bcr + COMMAND ${M1_LD} ${M1_LD_PATH} -r -d -o forte_all.o --whole-archive libforte.a ${CMAKE_CURRENT_SOURCE_DIR}/forte.lk + COMMAND ${M1_SYMCONV} forte_all.o -i + COMMAND ${M1_NM} forte_all.o > symbols.txt + COMMAND ${M1_MUNCH} -c symbols.txt > ctdt.c + COMMAND ${M1_CC} -Wall -Wno-pointer-sign -march=pentium -nostdinc -fno-common -O0 -fno-builtin -fno-defer-pop -DCPU_FAMILY=I80X86 -DFORTE_LITTLE_ENDIAN -D_POSIX_THREAD_ATTR_STACKSIZE -DFORTE_USE_WSTRING_DATATYPE -g -c -o ctdt.o ctdt.c + COMMAND ${M1_LD} ${M1_LD_PATH} -S -r -d -o forte.o forte_all.o ctdt.o + COMMAND ${M1_MBIND} forte -c ${CMAKE_CURRENT_SOURCE_DIR}/forte.mbs) + +#TODO add dbo generation for debugging: +# Create a *.dbo file for debugging +#%.dbo: $(OBJECTS) $(LINKER_SCRIPT) +# $(LD) $(LDFLAGS) -r -d -o "$@" "$(COMPOUND_OBJECT)" $(AUXILIARY_OBJECTS) + +endif() diff --git a/src/arch/be_m1/CPPLIB.ver.in b/src/arch/be_m1/CPPLIB.ver.in new file mode 100644 index 000000000..f8dbf50bc --- /dev/null +++ b/src/arch/be_m1/CPPLIB.ver.in @@ -0,0 +1 @@ +"V4.1" diff --git a/src/arch/be_m1/GET_CHAN_INFO.cpp b/src/arch/be_m1/GET_CHAN_INFO.cpp new file mode 100644 index 000000000..2a9826993 --- /dev/null +++ b/src/arch/be_m1/GET_CHAN_INFO.cpp @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GET_CHAN_INFO.h" +#include /* M1 include files */ +#include +#include +#include + +DEFINE_FIRMWARE_FB(FORTE_GET_CHAN_INFO, g_nStringIdGET_CHAN_INFO) + +const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataInputNames[] = { g_nStringIdSYMB_NAME }; + +const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataInputTypeIds[] = { g_nStringIdSTRING }; + +const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataOutputNames[] = { g_nStringIdRET_CODE, g_nStringIdMOD_NB, g_nStringIdCHAN_NB }; + +const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anDataOutputTypeIds[] = { g_nStringIdINT, g_nStringIdINT, g_nStringIdINT }; + +const TForteInt16 FORTE_GET_CHAN_INFO::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FORTE_GET_CHAN_INFO::scm_anEIWith[] = { 0, 255 }; +const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anEventInputNames[] = { g_nStringIdINIT }; + +const TDataIOID FORTE_GET_CHAN_INFO::scm_anEOWith[] = { 0, 1, 2, 255 }; +const TForteInt16 FORTE_GET_CHAN_INFO::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FORTE_GET_CHAN_INFO::scm_anEventOutputNames[] = { g_nStringIdINITO }; + +const SFBInterfaceSpec FORTE_GET_CHAN_INFO::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_GET_CHAN_INFO::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(init()){ + sendOutputEvent(scm_nEventINITOID); + } + break; + } +} + +bool FORTE_GET_CHAN_INFO::init(){ + SINT32 retCode = getChannelInfo(); + return retCode == 0; +} + +SINT32 FORTE_GET_CHAN_INFO::getChannelInfo(){ + VOID *DrvId; + UINT32 Type; + UINT32 CardNb; + UINT32 ChanNb; + + CHAR* symbolicName = (CHAR*) (const char*) SYMB_NAME().getValue(); + SINT32 retCode = mio_GetDrvByName(symbolicName, &DrvId, &Type, &CardNb, &ChanNb, NULL); + + CHAN_NB() = ChanNb; + MOD_NB() = CardNb; + return retCode; +} diff --git a/src/arch/be_m1/GET_CHAN_INFO.h b/src/arch/be_m1/GET_CHAN_INFO.h new file mode 100644 index 000000000..4cc5ff2c1 --- /dev/null +++ b/src/arch/be_m1/GET_CHAN_INFO.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GET_CHAN_INFO_H_ +#define _GET_CHAN_INFO_H_ + +#include +#include +#include +#include + +class FORTE_GET_CHAN_INFO: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_GET_CHAN_INFO) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &SYMB_NAME() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &RET_CODE() { + return *static_cast(getDO(0)); + }; + + CIEC_INT &MOD_NB() { + return *static_cast(getDO(1)); + }; + + CIEC_INT &CHAN_NB() { + return *static_cast(getDO(2)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 3, 0); + + void executeEvent(int pa_nEIID); + + bool init(); + SINT32 getChannelInfo(); + +public: + FUNCTION_BLOCK_CTOR(FORTE_GET_CHAN_INFO){ + }; + + virtual ~FORTE_GET_CHAN_INFO(){}; +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/arch/be_m1/GET_VALUE.cpp b/src/arch/be_m1/GET_VALUE.cpp new file mode 100644 index 000000000..76e669c15 --- /dev/null +++ b/src/arch/be_m1/GET_VALUE.cpp @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GET_VALUE.h" + +#include /* M1 include files */ +#include +#include +#include + +DEFINE_FIRMWARE_FB(FORTE_GET_VALUE, g_nStringIdGET_VALUE) + +const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataInputNames[] = {g_nStringIdMOD_NB, g_nStringIdCHAN_NB}; + +const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataInputTypeIds[] = {g_nStringIdINT, g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataOutputNames[] = {g_nStringIdRET_CODE, g_nStringIdVALUE}; + +const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anDataOutputTypeIds[] = {g_nStringIdINT, g_nStringIdSINT}; + +const TForteInt16 FORTE_GET_VALUE::scm_anEIWithIndexes[] = {0, 2}; +const TDataIOID FORTE_GET_VALUE::scm_anEIWith[] = {0, 255, 1, 255}; +const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_GET_VALUE::scm_anEOWith[] = {0, 255, 0, 1, 255}; +const TForteInt16 FORTE_GET_VALUE::scm_anEOWithIndexes[] = {0, 2, -1}; +const CStringDictionary::TStringId FORTE_GET_VALUE::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_GET_VALUE::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_GET_VALUE::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventINITID: + if (init()) { + sendOutputEvent(scm_nEventINITOID); + } + break; + case scm_nEventREQID: + RET_CODE() = read(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +bool FORTE_GET_VALUE::init() { + driverId = mio_GetDrv(static_cast(MOD_NB())); + return driverId != NULL; +} + +SINT32 FORTE_GET_VALUE::read() { + SINT32 myValue; + SINT32 retCode = mio_GetValue(driverId, CHAN_NB(), &myValue); + VALUE() = myValue; + return retCode; +} + + diff --git a/src/arch/be_m1/GET_VALUE.h b/src/arch/be_m1/GET_VALUE.h new file mode 100644 index 000000000..ec385c492 --- /dev/null +++ b/src/arch/be_m1/GET_VALUE.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GET_VALUE_H_ +#define _GET_VALUE_H_ + +#include +#include +#include +#include +#include + +class FORTE_GET_VALUE : public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_GET_VALUE) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &MOD_NB(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_INT &CHAN_NB(){ + return *static_cast(getDI(1)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &RET_CODE(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_SINT &VALUE(){ + return *static_cast(getDO(1)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 2, 2, 0) + ; + + void executeEvent(int pa_nEIID); + + void *driverId; + + bool init(); + SINT32 read(); + + public: + FUNCTION_BLOCK_CTOR(FORTE_GET_VALUE){ + }; + + virtual ~FORTE_GET_VALUE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/arch/be_m1/SET_VALUE.cpp b/src/arch/be_m1/SET_VALUE.cpp new file mode 100644 index 000000000..0bc5d3e8d --- /dev/null +++ b/src/arch/be_m1/SET_VALUE.cpp @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "SET_VALUE.h" +#include /* M1 include files */ +#include +#include +#include + +DEFINE_FIRMWARE_FB(FORTE_SET_VALUE, g_nStringIdSET_VALUE) + +const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataInputNames[] = { g_nStringIdMOD_NB, g_nStringIdCHAN_NB, g_nStringIdVALUE }; + +const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataInputTypeIds[] = { g_nStringIdINT, g_nStringIdINT, g_nStringIdSINT }; + +const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataOutputNames[] = { g_nStringIdRET_CODE }; + +const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anDataOutputTypeIds[] = { g_nStringIdINT }; + +const TForteInt16 FORTE_SET_VALUE::scm_anEIWithIndexes[] = { 0, 2 }; +const TDataIOID FORTE_SET_VALUE::scm_anEIWith[] = { 0, 255, 2, 1, 255 }; +const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_SET_VALUE::scm_anEOWith[] = { 0, 255, 0, 255 }; +const TForteInt16 FORTE_SET_VALUE::scm_anEOWithIndexes[] = { 0, 2, -1 }; +const CStringDictionary::TStringId FORTE_SET_VALUE::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_SET_VALUE::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_SET_VALUE::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(init()){ + sendOutputEvent(scm_nEventINITOID); + } + break; + case scm_nEventREQID: + RET_CODE() = write(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +bool FORTE_SET_VALUE::init(){ + driverId = mio_GetDrv((short) MOD_NB()); + return driverId != NULL; +} + +SINT32 FORTE_SET_VALUE::write(){ + return mio_SetValue(driverId, static_cast(CHAN_NB()), VALUE()); +} + diff --git a/src/arch/be_m1/SET_VALUE.h b/src/arch/be_m1/SET_VALUE.h new file mode 100644 index 000000000..bd9548033 --- /dev/null +++ b/src/arch/be_m1/SET_VALUE.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SET_VALUE_H_ +#define _SET_VALUE_H_ + +#include /* M1 include files */ +#include +#include +#include +#include + +class FORTE_SET_VALUE : public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_SET_VALUE) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &MOD_NB(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_INT &CHAN_NB(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_SINT &VALUE(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &RET_CODE(){ + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 1, 0) + ; + + void executeEvent(int pa_nEIID); + + void *driverId; + + bool init(); + SINT32 write(); + + public: + FUNCTION_BLOCK_CTOR(FORTE_SET_VALUE){ + }; + + virtual ~FORTE_SET_VALUE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/arch/be_m1/SVIreceive_1.cpp b/src/arch/be_m1/SVIreceive_1.cpp new file mode 100644 index 000000000..91ddf04a8 --- /dev/null +++ b/src/arch/be_m1/SVIreceive_1.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "SVIreceive_1.h" + +DEFINE_FIRMWARE_FB(FORTE_SVIreceive_1, g_nStringIdSVIreceive_1) + +const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdID }; + +const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdSTRING }; + +const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdRD_1 }; + +const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdANY }; + +const TForteInt16 FORTE_SVIreceive_1::scm_anEIWithIndexes[] = { 0, 3 }; +const TDataIOID FORTE_SVIreceive_1::scm_anEIWith[] = { 0, 1, 255, 0, 255 }; +const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_SVIreceive_1::scm_anEOWith[] = { 0, 255, 0, 1, 255 }; +const TForteInt16 FORTE_SVIreceive_1::scm_anEOWithIndexes[] = { 0, 2, -1 }; +const CStringDictionary::TStringId FORTE_SVIreceive_1::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_SVIreceive_1::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_SVIreceive_1::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(true == QI()){ + QO() = registerSVIvar(ID(), RD_1(), SVI_F_IN); + } + sendOutputEvent(scm_nEventINITOID); + break; + + case scm_nEventREQID: + sendOutputEvent(scm_nEventCNFID); + break; + default: + break; + } +} + diff --git a/src/arch/be_m1/SVIreceive_1.h b/src/arch/be_m1/SVIreceive_1.h new file mode 100644 index 000000000..a28096c74 --- /dev/null +++ b/src/arch/be_m1/SVIreceive_1.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SVIRECEIVE_1_H_ +#define _SVIRECEIVE_1_H_ + +#include "BE_SVIFB.h" +#include +#include +#include + +class FORTE_SVIreceive_1: public BE_SVIFB{ + DECLARE_FIRMWARE_FB(FORTE_SVIreceive_1) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_STRING &ID() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_ANY &RD_1() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 2, 2, 0); + + void executeEvent(int pa_nEIID); + +public: + FORTE_SVIreceive_1(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + BE_SVIFB( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData){ + }; + virtual ~FORTE_SVIreceive_1(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/arch/be_m1/SVIsend_1.cpp b/src/arch/be_m1/SVIsend_1.cpp new file mode 100644 index 000000000..eff01734f --- /dev/null +++ b/src/arch/be_m1/SVIsend_1.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "SVIsend_1.h" + +DEFINE_FIRMWARE_FB(FORTE_SVIsend_1, g_nStringIdSVIsend_1) + +const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdID, g_nStringIdSD_1}; + +const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdANY}; + +const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_SVIsend_1::scm_anEIWithIndexes[] = {0, 4}; +const TDataIOID FORTE_SVIsend_1::scm_anEIWith[] = {0, 1, 2, 255, 0, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_SVIsend_1::scm_anEOWith[] = {0, 255, 0, 255}; +const TForteInt16 FORTE_SVIsend_1::scm_anEOWithIndexes[] = {0, 2, -1}; +const CStringDictionary::TStringId FORTE_SVIsend_1::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_SVIsend_1::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_SVIsend_1::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventINITID: + if(true == QI()){ + QO() = registerSVIvar(ID(),SD_1(),SVI_F_OUT); + } + sendOutputEvent(scm_nEventINITOID); + if (true == QO()) { + printf("Alles OK send\n"); + } else { + printf("Alles FALSCH send\n"); + } + break; + + case scm_nEventREQID: + sendOutputEvent(scm_nEventCNFID); + break; + default: + break; + } +} + + + diff --git a/src/arch/be_m1/SVIsend_1.h b/src/arch/be_m1/SVIsend_1.h new file mode 100644 index 000000000..7a57cb5e2 --- /dev/null +++ b/src/arch/be_m1/SVIsend_1.h @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SVISEND_1_H_ +#define _SVISEND_1_H_ + +#include "BE_SVIFB.h" +#include +#include +#include + +class FORTE_SVIsend_1: public BE_SVIFB{ + DECLARE_FIRMWARE_FB(FORTE_SVIsend_1) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_STRING &ID() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY &SD_1() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FORTE_SVIsend_1(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + BE_SVIFB( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData){ + }; + + virtual ~FORTE_SVIsend_1(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/arch/be_m1/forte.cru b/src/arch/be_m1/forte.cru new file mode 100644 index 000000000..7ec46e7a9 --- /dev/null +++ b/src/arch/be_m1/forte.cru @@ -0,0 +1,42 @@ +MODUL forte +VERSION 120 +PROPERTY RECONF +ROOT + (OwnParms) + DelayTime = UINT32(5 .. 100)[25] +END_ROOT + +DESC(049) + OwnParms = "Applikationsspezifische Parameter" + OwnParms.DelayTime = "Zykluszeit in ms" +END_DESC + +DESC(001) + OwnParms = "Application specific parameters" + OwnParms.DelayTime = "Access cyclic time in ms" +END_DESC + +HELP(049) + "Allgemein:" + " Dieses Software-Modul implementiert ein IEC 61499 Laufzeitsystem" + " basierend auf dem Source Code FORTE aus dem 4DIAC - Framework for" + " Distributed Industrial Automation and Control (www.fordiac.org)." + "" + "SVI:" + " Dieses Software-Modul verfuegt ueber einen SVI-Server. Prozesswerte" + " koennen damit online ausgelesen oder geaendert werden." + "" +END_HELP + +HELP(001) + "Introduction:" + " This software module enables IEC 61499 functionality based on the open" + " source environment FORTE from 4DIAC - Framework for Distributed " + " Industrial Automation and Control (www.fordiac.org)" + "" + "SVI:" + " This software module has an SVI server, that permits online changes of" + " parameters. The number and name of the parameters depedends on the " + " IEC 61499 control application loaded into this module." + "" +END_HELP diff --git a/src/arch/be_m1/forte.lk b/src/arch/be_m1/forte.lk new file mode 100644 index 000000000..3ad7b9343 --- /dev/null +++ b/src/arch/be_m1/forte.lk @@ -0,0 +1 @@ +GROUP("befc\libbefc_1.0.0.a") \ No newline at end of file diff --git a/src/arch/be_m1/forte.mbs b/src/arch/be_m1/forte.mbs new file mode 100644 index 000000000..c6ff6141f --- /dev/null +++ b/src/arch/be_m1/forte.mbs @@ -0,0 +1,34 @@ +;Script for MBIND to build forte.m +; +;Header +; +ModuleType = VXW +Version = ../forte.ver +Reentrant = FALSE +NoOnlineConfig = FALSE +NoOnlineInstall = FALSE +NoOnlineDeinstall = FALSE +DebugInfo = TRUE +ErrorTolerant = FALSE +NoAutoInstall = FALSE +SystemModule = FALSE +; +;Object-Code +; +ObjectType = OBJ +ObjectMode = NORMAL +Version = ../forte.ver +ObjectName = forte.o +; +;Configuration-Rule +; +ObjectType = BCRU +ObjectName = forte.bcr +; +;Source-Code +; +;ObjectType = C-ZIP +;ObjectName = forte.tgz +ObjectType = SWREQ +Version = ../CPPLIB.ver +ObjectName = CPPLIB diff --git a/src/arch/be_m1/forte.ver.in b/src/arch/be_m1/forte.ver.in new file mode 100644 index 000000000..31f54fdb3 --- /dev/null +++ b/src/arch/be_m1/forte.ver.in @@ -0,0 +1 @@ +"V1.00.01 Alpha" diff --git a/src/arch/be_m1/fortealloc.h b/src/arch/be_m1/fortealloc.h new file mode 100644 index 000000000..25842787d --- /dev/null +++ b/src/arch/be_m1/fortealloc.h @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 ACIN and fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FORTEALLOC_H_ +#define FORTEALLOC_H_ + +#include "datatype.h" +#include +#include +#include +#include +#include + +//--- SW-Module memory partition, needed for new operator +extern UINT32 FORTE_MemPart; + +inline +void forte_free(void *pa_pvData){ + sys_MemXFree(pa_pvData); +} + +inline +void *forte_malloc(size_t pa_nSize){ + void * pTemp; + + pTemp = sys_MemXPAlloc(FORTE_MemPart, pa_nSize); + + if (pTemp == NULL) + { + /* no memory, suspend task to avoid a NULL exception*/ + log_Err( + "forte_malloc: unable to allocate 0x%x bytes in partition %d, Suspend task!", + pa_nSize, FORTE_MemPart); + taskSuspend(taskIdSelf()); + } + + return pTemp; +} + +inline +void *forte_realloc(void *pa_pvData, size_t pa_nSize){ + //FIXME add realloc implementation for BE_M1 platform + return realloc(pa_pvData, pa_nSize); +} + + +inline +void* operator new(size_t pa_nSize) throw(std::bad_alloc) { + return forte_malloc(pa_nSize); +} + +inline +void* operator new[](size_t pa_nSize) throw(std::bad_alloc) { + return forte_malloc(pa_nSize); +} + +inline +void operator delete(void* pa_pvData) throw() { + sys_MemXFree(pa_pvData); +} + +inline +void operator delete[](void* pa_pvData) throw() { + sys_MemXFree(pa_pvData); +} + +/*! \brief Placement new operator + * + * Will use the given buffer as memory region. The need size will be ignored. + * Objects created with this new must not deleted only invoke the destructor + * + * @param pa_pData + */ +inline +void * operator new(size_t, TForteByte *pa_pData) throw() { + return pa_pData; +} + +inline +void * operator new[](size_t, TForteByte *pa_pData) throw() { + return pa_pData; +} + +inline +void operator delete(void *, TForteByte *) throw() { +} + +inline +void operator delete[](void *, TForteByte *) throw() { +} + +#endif /* FORTEALLOC_H_ */ diff --git a/src/arch/be_m1/fortemodule.cpp b/src/arch/be_m1/fortemodule.cpp new file mode 100644 index 000000000..33d1d33ad --- /dev/null +++ b/src/arch/be_m1/fortemodule.cpp @@ -0,0 +1,322 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include +#include +#include + +#include "fortemodule.h" + +#include +#include "BE_RMT_DEV.h" +#include + +#define MIO_VERS_LEN 24 +#define FORTE_DELAY 25 // Access cycle time in ms +#define FORTE_C_PARMS "OwnParms" // Group in mconfig.ini +#define FORTE_C_DELAY "DelayTime" // Keyword in mconfig.ini + +MLOCAL CHAR FORTE_Version[MIO_VERS_LEN] = +#include "forte.ver" +; + +extern UINT32 FORTE_MemPart; + +//--- Function definitions +MLOCAL VOID ExcHandler(SINT32 Signal); +MLOCAL VOID PanicHandler(UINT32 PanicMode); + +//--- Forward declaration +class CFORTEModule; + +//--- globals +CFORTEModule* g_poMainModule; + +//--- SW-Module memory partition, needed for new operator +UINT32 FORTE_MemPart = 0; + +/*-------------------------------------------------------------------------- + * Desc: This function is the entry point to the module. + * After module loading this function will be called as part + * of the module handler. + * This function has to initialize the interfaces to the + * environment (SMI, SVI) so that they are ready to operate. + * + * + * InP: pConf Parameter for configuration (data from MCONFIG.INI). + * InP: pLoad Parameter from module loading. + * OutP: + * + * Ret: >0 Task-Id, module initialized correctly. + * <0 Error during initialization. + *-------------------------------------------------------------------------*/ +extern "C" SINT32 forte_Init(MOD_CONF *pConf, MOD_LOAD *pLoad){ + //--- store memory partition, needed for new operator + FORTE_MemPart = pConf->MemPart; + + //--- Create new application class. + g_poMainModule = new CFORTEModule(); + + //--- Close application if an error is occurred. + if(g_poMainModule == NULL + ) + return ERROR; + + //--- Initialize software module. + SINT32 TaskId = g_poMainModule->Init(pConf, pLoad, CFORTEModule::MINVERS, CFORTEModule::MAXVERS, 10000, FORTE_Version, "FORTE", (VOIDFUNCPTR) PanicHandler, (VOIDFUNCPTR) ExcHandler); + + //--- Close application if an error is occurred. + if(TaskId == ERROR) + SAFE_DELETE(g_poMainModule); + + return TaskId; +} + +/*-------------------------------------------------------------------------- + * Desc: Handler for CPU exception signal if not in debug mode. + * + * InP: Signal Signal number (M_SIGEXCEPT) + * OutP: + * + * Ret: + *-------------------------------------------------------------------------*/ +MLOCAL VOID ExcHandler(SINT32 Signal){ + DEVLOG_INFO("%s: Signal %d received by task %x.", g_poMainModule->GetAppName(), Signal, taskIdSelf()); + + //--- Deinit application task and resources. + g_poMainModule->AppExcHandler(Signal); +} + +/*-------------------------------------------------------------------------- + * Desc: Handler for panic situation. + * + * InP: PanicMode Type of panic situation (SYS_APPPANIC, ...) + * OutP: + * + * Ret: + *-------------------------------------------------------------------------*/ +MLOCAL VOID PanicHandler(UINT32 PanicMode){ + // Bring critical parts to a predefined state. For example save + // data to NV-RAM or close open files. + // + // ATTENTION: Leave this function as fast as possible in order to + // give all other modules also the chance to work off + // there panic handler! + + g_poMainModule->AppPanicHandler(PanicMode); +} + +/*-------------------------------------------------------------------------- + * Desc: Constructor of application class. + * + * InP: + * OutP: + * + * Ret: + *-------------------------------------------------------------------------*/ +CFORTEModule::CFORTEModule() : + m_poDev(NULL){ + forteInit::initForte(); +} + +/*-------------------------------------------------------------------------- + * Desc: Destructor of application class. + * + * InP: + * OutP: + * + * Ret: + *-------------------------------------------------------------------------*/ +CFORTEModule::~CFORTEModule(){ + if(GetDebugLevel() & APP_DBG_INFO1) + DEVLOG_INFO("FORTE_mod: Destruct done."); +} + +/*-------------------------------------------------------------------------- + * Desc: This virtual function will be called as a part of the + forte_Init function after loading of the software module. + * + * InP: + * OutP: + * + * Ret: 0 Everything is Ok + * <0 Error occurred + *-------------------------------------------------------------------------*/ +SINT32 CFORTEModule::AppEarlyInit(VOID){ + return (0); +} + +/*-------------------------------------------------------------------------- + * Desc: This virtual function will be called after loading of the + * software module. + * + * InP: + * OutP: + * + * Ret: 0 Everything is Ok + * <0 Error occurred + *-------------------------------------------------------------------------*/ +SINT32 CFORTEModule::AppInit(VOID){ + m_unFORTEstartOK = 1; + //--- Add global variables for values that have to be exported via SVI. + if(GetSVIHandler().AddGlobVar("FORTEstart", SVI_F_INOUT | SVI_F_UINT32, 4, &(m_unFORTEstartOK), 0, 0) != OK){ + DEVLOG_ERROR("FORTE_mod::APPINIT: Can't add SVI variable 'FORTEstart'!"); + } + + DEVLOG_INFO("appInit of forte\n"); + if(0 == m_poDev){ + m_poDev = new BE_RMT_DEV(*this); + DEVLOG_INFO("appInit after new BE_RMT_DEV"); + } + + //--- Read configuration file + CfgRead(); + return (0); +} + +/*-------------------------------------------------------------------------- + * Desc: This virtual function will be called bevor the application will + * be removed. + * + * InP: + * OutP: + * + * Ret: 0 Everything ok + * <0 Error occurred + *-------------------------------------------------------------------------*/ +SINT32 CFORTEModule::AppDeInit(VOID){ + //--- Delete walking light class + SAFE_DELETE(m_poDev); + return (0); +} + +/*-------------------------------------------------------------------------- + * Desc: This virtual function will be called bevor the application will + * be removed. + * + * InP: + * OutP: + * + * Ret: 0 Everything ok + * <0 Error occurred + *-------------------------------------------------------------------------*/ +SINT32 CFORTEModule::AppLateDeInit(VOID){ + return (0); +} + +/*-------------------------------------------------------------------------- + * Desc: This virtual function will be called when the 'End of Init' + * signal will be sent by the system. + * + * InP: + * OutP: + * + * Ret: 0 Everything ok + * <0 Error occurred + *-------------------------------------------------------------------------*/ +SINT32 CFORTEModule::AppEOI(VOID){ + CHAR connectionString[16]; + if(0 != m_poDev){ + m_poDev->startDevice(); + DEVLOG_INFO("m_poDev started\n"); + } + else{ + DEVLOG_ERROR("no m_poDev preset\n"); + } + + return (0); +} + +/*-------------------------------------------------------------------------- + * Desc: This is a dummy method which will be called when the signal + * 'stop' is received from the system. + * + * InP: + * OutP: + * Throws: + * Ret: OK Everything ok + * ERROR An error occurred + *-------------------------------------------------------------------------*/ +SINT32 CFORTEModule::AppStop(VOID){ + if(0 != m_poDev){ + m_poDev->changeFBExecutionState(cg_nMGM_CMD_Stop); + } + + return OK; +} + +/*-------------------------------------------------------------------------- + * Desc: This is a dummy method which will be called when the signal + * 'run' is received from the system. + * + * InP: + * OutP: + * Throws: + * Ret: OK Everything ok + * ERROR An error occurred + *-------------------------------------------------------------------------*/ +SINT32 CFORTEModule::AppRun(VOID){ + + return OK; +} + +/*-------------------------------------------------------------------------- + * Desc: This virtual function will be called if a panic situation + * appears in the system. + * + * InP: + * OutP: + * + * Ret: 0 Everything ok + * <0 Error occurred + *-------------------------------------------------------------------------*/ +VOID CFORTEModule::AppPanicHandler(UINT32 PanicMode){ + sys_Printf("%s AppPanicHandler", GetAppName()); +} + +/*-------------------------------------------------------------------------- + * Desc: This method handles the RPC call 'RpcNewCfg'. + * + * InP: pMsg Message data from RPC call. + * OutP: + * Throws: + * Ret: + *-------------------------------------------------------------------------*/ +VOID CFORTEModule::RpcNewCfg(SMI_MSG *pMsg){ + SMI_NEWCFG_R Reply; + + if(GetModState() == RES_S_STOP || GetModState() == RES_S_RUN){ + //--- Read configuration file + CfgRead(); + + Reply.RetCode = SMI_E_OK; + } + else + Reply.RetCode = SMI_E_FAILED; + + smi_FreeData(pMsg); + smi_SendCReply(GetSmiID(), pMsg, SMI_E_OK, &Reply, sizeof(Reply)); +} + +/*--------------------------------------------------------------------------- + * Desc: This function reads the configuration from the given + * configuration file. + * + * InP: + * OutP: + * Ret: + *--------------------------------------------------------------------------*/ +VOID CFORTEModule::CfgRead(VOID){ + //--- Get the delay time for my application. + pf_GetInt(GetAppName(), FORTE_C_PARMS, FORTE_C_DELAY, FORTE_DELAY, (SINT32 *) &m_unFORTEstartOK, GetCfgLine(), GetProfileName()); +} + diff --git a/src/arch/be_m1/fortemodule.h b/src/arch/be_m1/fortemodule.h new file mode 100644 index 000000000..7bc6bc142 --- /dev/null +++ b/src/arch/be_m1/fortemodule.h @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef __FORTE_MODULE_H__ +#define __FORTE_MODULE_H__ + +#include +#include +#include + + +class BE_RMT_DEV; + +class CFORTEModule : public BEModule{ + public: + CFORTEModule(); + virtual ~CFORTEModule(); + + static const UINT32 MINVERS = 2; + static const UINT32 MAXVERS = 2; + + virtual VOID AppPanicHandler(UINT32 PanicMode); + VOID CfgRead(VOID); + + private: + virtual SINT32 AppEarlyInit(VOID); + virtual SINT32 AppInit(VOID); + virtual SINT32 AppDeInit(VOID); + virtual SINT32 AppLateDeInit(VOID); + virtual SINT32 AppEOI(VOID); + virtual SINT32 AppStop(VOID); + virtual SINT32 AppRun(VOID); + virtual VOID RpcNewCfg(SMI_MSG *pMsg); + + BE_RMT_DEV *m_poDev; + + UINT32 m_unFORTEstartOK; +}; + + +#endif // __FORTE_MODULE_H__ diff --git a/src/arch/be_m1/sockhand.h b/src/arch/be_m1/sockhand.h new file mode 100644 index 000000000..d6e764d0b --- /dev/null +++ b/src/arch/be_m1/sockhand.h @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012, 2015 ACIN and fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef SOCKHAND_H_ +#define SOCKHAND_H_ + + +#include +#include +#include +#include +#include + +//these include needs to be last +#include "../fdselecthand.h" +#include "../bsdsocketinterf.h" +#include "../gensockhand.h" + +typedef CGenericIPComSocketHandler CIPComSocketHandler; + +#endif /* SOCKHAND_H_ */ diff --git a/src/arch/be_m1/stdint.h b/src/arch/be_m1/stdint.h new file mode 100644 index 000000000..771c69f35 --- /dev/null +++ b/src/arch/be_m1/stdint.h @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Stefano Campanelli - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _STDINT_H_ +#define _STDINT_H_ + +#include + +#define UINT8_MIN _ARCH_UCHAR_MIN +#define UINT8_MAX _ARCH_UCHAR_MAX +#define INT8_MIN _ARCH_CHAR_MIN +#define INT8_MAX _ARCH_CHAR_MAX + +#define INT16_MIN _ARCH_SHRT_MIN +#define INT16_MAX _ARCH_SHRT_MAX +#define UINT16_MIN _ARCH_USHRT_MIN +#define UINT16_MAX _ARCH_USHRT_MAX + +#define INT32_MIN _ARCH_INT_MIN +#define INT32_MAX _ARCH_INT_MAX +#define UINT32_MIN _ARCH_UINT_MIN +#define UINT32_MAX _ARCH_UINT_MAX + +#define UINT64_MIN 0ULL // 0 +#define UINT64_MAX 18446744073709551615ULL // 2^64 -1 +#define INT64_MIN (-9223372036854775807LL - 1) // -2^63 +#define INT64_MAX 9223372036854775807LL // 2^63-1 + +#endif diff --git a/src/arch/be_m1/sync.cpp b/src/arch/be_m1/sync.cpp new file mode 100644 index 000000000..a7e3ab39b --- /dev/null +++ b/src/arch/be_m1/sync.cpp @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "sync.h" + +CVXWorksSyncObject::CVXWorksSyncObject(){ + m_oSemBinary = semMCreate(SEM_Q_PRIORITY); +} + +CVXWorksSyncObject::~CVXWorksSyncObject(){ + semDelete (m_oSemBinary); +} diff --git a/src/arch/be_m1/sync.h b/src/arch/be_m1/sync.h new file mode 100644 index 000000000..99b5cde38 --- /dev/null +++ b/src/arch/be_m1/sync.h @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SYNC_H_ +#define _SYNC_H_ + +#include "vxWorks.h" +#include "taskLib.h" +#include "semLib.h" + +#define CSyncObject CVXWorksSyncObject //allows that doxygen can generate better documentation + +/*! \ingroup bem1_hal + * \brief The sync object implementation for the Bachmann electronic M1 interface + * + * In the Bachmann electronic M1 version we use a binary semaphore provided from vxWorks + * + */ + +class CVXWorksSyncObject{ + public: + CVXWorksSyncObject(); + virtual ~CVXWorksSyncObject(); + + void lock(void){ + semTake(m_oSemBinary, WAIT_FOREVER); + } + + void unlock(void){ + semGive(m_oSemBinary); + } + + private: + SEM_ID m_oSemBinary; + +}; + +#endif /*SYNC_H_*/ diff --git a/src/arch/be_m1/thread.cpp b/src/arch/be_m1/thread.cpp new file mode 100644 index 000000000..270aa3f0c --- /dev/null +++ b/src/arch/be_m1/thread.cpp @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "thread.h" +#include "../devlog.h" +#include +#include + +void CBEThread::Main(VOID){ + m_bAlive = true; + run(); +} + +bool CBEThread::destroy(void){ + end(); + return true; +} + +CBEThread::CBEThread() : + mTskName(0){ + m_bAlive = false; + m_nDeadline = 0; +} + +CBEThread::~CBEThread(){ + destroy(); +} + +bool CBEThread::isAlive(void){ + return m_bAlive; +} + +void CBEThread::setDeadline(TForteUInt32 pa_nVal){ + m_nDeadline = pa_nVal; + //TODO implement priority assignment similar to threadx and ecos +} + +TForteUInt32 CBEThread::getDeadline(void){ + return m_nDeadline; +} + +void CBEThread::start(void){ + if(Spawn(0, 0, 130, VX_FP_TASK, APP_TSK_STACK) == ERROR){ + log_Err("test8_mod::APPLATEINIT: Error in TaskSpawn; '%s'!", "tForteTask"); + } +} + +void CBEThread::selfSuspend(void){ + Suspend(); +} + +void CBEThread::resumeSelfSuspend(void){ + Resume(); +} + +void CBEThread::end(void){ + m_bAlive = false; + resumeSelfSuspend(); + join(); +} + +void CBEThread::join(void){ + Delete(); +} diff --git a/src/arch/be_m1/thread.h b/src/arch/be_m1/thread.h new file mode 100644 index 000000000..f290716c4 --- /dev/null +++ b/src/arch/be_m1/thread.h @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _THREAD_H_ +#define _THREAD_H_ + +#include +#include +#include +#include +#include +#include "../datatype.h" + +#define CThread CBEThread //allows that doxygen can generate better documentation + +/** \ingroup FORTE-HAL + * \defgroup bem1_hal Bachmann electronic M1 FORTE Hardware Abstraction Layer + * + * \brief The FORTE-HAL implementation for normal Bachmann electronic M1 PLCs + */ + +/*! \ingroup bem1_hal + * \brief The thread implementation for the task class provided by Bachmann electronic. + * + * TODO implement priority assignment for realtime event chains. + */ +class CBEThread : public BETask{ + + public: + /*! \brief Constructor of the Thread class + * + * Does all the neccessary steps in order to get the thread running with the start()-method + */ + CBEThread(); + char * mTskName; + + /*! \brief Stops and destroys thread. + * + * Will stop the execution if running and destroy the thread including all system specific data. + */ + virtual ~CBEThread(); + + /*! \brief Indicates if the thread is allowed to execute. + * + * This functions checks if the Thread is still executing user code in its run()-method. + * \return true if there the run method is acitve. + */ + bool isAlive(void); + + void setDeadline(TForteUInt32 pa_nVal); //!Set the deadline of the thread. + TForteUInt32 getDeadline(void); //!Get the current deadline of the thread. + + virtual void Main(VOID); + + /*! \brief starts the Thread + * + * By calling this method the execution in the run()-Method will be started. If necessary additional data + * can be created here. Because of inheritance resons the best place for executing create is in this method. + * For details ask AZ. + */ + void start(void); + + /*! \brief Resumes a suspended Thread + * + * + */ + void resumeSelfSuspend(void); + + /*! \brief Stops the execution of the thread + * + * This function imidiatly stops the execution of the thread (seting m_bAlive to false) and waits till + * this is finished. + */ + void end(void); + + /*! \brief Waits for the Thread to finish its execution. + * + * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!! + */ + void join(void); // Waits + protected: + /*! \brief Suspends the thread. + * + * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called. + */ + void selfSuspend(void); + + private: + /*! \brief Abstract method for the code to execute in the thread. + * + * This thread class has to provide means that the code a inheriting class will add to the run()-method will + * be executed in a seperated thread regarding the creator of the CThread class. + * + * The inheriting class has to fullfill the folloing rules when using the run method: + * - To end the thread execution simple leave the run()-method + * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the + * execution if isAlive() returns false. + * + * \return true if thread execution ended successfull + */ + virtual void run() = 0; + + /*! \brief Destroies the thread + * + * This function destroies all the data structures created in the creation phase. All used memory is freed. + */ + bool destroy(void); + + /*! \brief Flag that indicates if the Thread is alive. + * + * This flag has two main purposes: + * -# indicate for other classes if the thread is still executing + * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ). + * This is important for stopping and destroying threads. + */ + bool m_bAlive; + + TForteUInt32 m_nDeadline; //!deadline the thread needs to be finish its exectuion. 0 means unconstraint. + +}; + +#endif /*THREAD_H_*/ + diff --git a/src/arch/be_m1/vxworkstimeha.cpp b/src/arch/be_m1/vxworkstimeha.cpp new file mode 100644 index 000000000..98836f050 --- /dev/null +++ b/src/arch/be_m1/vxworkstimeha.cpp @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 ACIN and fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "vxworkstimeha.h" +#include "../../core/devexec.h" +#include + + +void CTimerHandler::createTimerHandler(void){ + if(0 == sm_poFORTETimer) + sm_poFORTETimer = new CPCTimerHandler(); +} + +CPCTimerHandler::CPCTimerHandler(){ +} + +CPCTimerHandler::~CPCTimerHandler(){ + std::cout << "~CPCTimerHandler()" << std::endl; + disableHandler(); +} + +void CPCTimerHandler::run(){ + struct timespec stReq; + stReq.tv_sec = 0; + stReq.tv_nsec = (1000000 / getTicksPerSecond()) * 1000; + + while(isAlive()){ + nanosleep(&stReq, NULL); + nextTick(); + } +} + +void CPCTimerHandler::enableHandler(void){ + start(); +} + +void CPCTimerHandler::disableHandler(void){ + end(); +} + +void CPCTimerHandler::setPriority(int pa_nPriority){ + //TODO think on hwo to handle this. +} + +int CPCTimerHandler::getPriority(void) const{ + //TODO think on hwo to handle this. + return 1; +} diff --git a/src/arch/be_m1/vxworkstimeha.h b/src/arch/be_m1/vxworkstimeha.h new file mode 100644 index 000000000..f79480f27 --- /dev/null +++ b/src/arch/be_m1/vxworkstimeha.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _PCTIMEHA_H_ +#define _PCTIMEHA_H_ + +#include "thread.h" +#include "../timerha.h" + +/*! \ingroup bem1_hal + *\ingroup EXTEVHAND + *\brief the timer handler for the Bachmann electronic M1 architecture. + */ +class CPCTimerHandler : public CTimerHandler, private CThread{ + public: + virtual ~CPCTimerHandler(); + + virtual void run(); + + /*!\brief Enables this event source + * + */ + virtual void enableHandler(void); + + /*!\brief Disable this event source + */ + virtual void disableHandler(void); + + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority); + + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const; + + private: + CPCTimerHandler(); + + friend class CTimerHandler; + +}; + +#endif /*PCTIMEHA_H_*/ diff --git a/src/arch/bsdsocketinterf.cpp b/src/arch/bsdsocketinterf.cpp new file mode 100644 index 000000000..64dfc0cc2 --- /dev/null +++ b/src/arch/bsdsocketinterf.cpp @@ -0,0 +1,255 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Gerhard Ebenhofer, Thomas Strasser + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include //needs to be first pulls in the platform specific includes +#include "bsdsocketinterf.h" +#include "devlog.h" +#include + +void CBSDSocketInterface::closeSocket(TSocketDescriptor pa_nSockD){ +#if defined(WIN32) || defined(NET_OS) + closesocket(pa_nSockD); +#else + close(pa_nSockD); +#endif +} + +CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openTCPServerConnection( + char *pa_acIPAddr, unsigned short pa_nPort){ + TSocketDescriptor nRetVal = -1; + + DEVLOG_INFO("CBSDSocketInterface: Opening TCP-Server connection at: %s:%d\n", pa_acIPAddr, pa_nPort); + + TSocketDescriptor nSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + if(-1 != nSocket){ + struct sockaddr_in stSockAddr; + memset(&(stSockAddr), '\0', sizeof(sockaddr_in)); + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons(pa_nPort); + stSockAddr.sin_addr.s_addr = htonl(INADDR_ANY ); + + int nOptVal = 1; + if (setsockopt(nSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&nOptVal, sizeof(nOptVal)) == -1){ + DEVLOG_ERROR("CBSDSocketInterface: could not set socket option SO_REUSEADDR: %s\n", strerror(errno)); + } + + if(0 == bind(nSocket, (struct sockaddr *) &stSockAddr, sizeof(struct sockaddr))){ + if(-1 == listen(nSocket, 1)){ // for the classic IEC 61499 server only one connection at the same time is accepted TODO mayb make this adjustable for future extensions + DEVLOG_ERROR("CBSDSocketInterface: listen() failed: %s\n", strerror(errno)); + } + else{ + nRetVal = nSocket; + } + } + else{ + DEVLOG_ERROR("CBSDSocketInterface: bind() failed: %s\n", strerror(errno)); + } + } + else{ + DEVLOG_ERROR("CBSDSocketInterface: Couldn't create socket: %s\n", strerror(errno)); + } + return nRetVal; +} + +CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openTCPClientConnection( + char *pa_acIPAddr, unsigned short pa_nPort){ + TSocketDescriptor nRetVal = -1; + TSocketDescriptor nSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + + DEVLOG_INFO("CBSDSocketInterface: Opening TCP-Client connection at: %s:%d\n", pa_acIPAddr, pa_nPort); + + if(-1 != nSocket){ + struct sockaddr_in stSockAddr; + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons(pa_nPort); + stSockAddr.sin_addr.s_addr = inet_addr(pa_acIPAddr); + memset(&(stSockAddr.sin_zero), '\0', sizeof(stSockAddr.sin_zero)); + + if(-1 == connect(nSocket, (struct sockaddr *) &stSockAddr, sizeof(struct sockaddr))){ + DEVLOG_ERROR("CBSDSocketInterface: connect() failed: %s\n", strerror(errno)); + } + else{ + nRetVal = nSocket; + } + } + else{ + DEVLOG_ERROR("CBSDSocketInterface: Couldn't create socket: %s\n", strerror(errno)); + } + return nRetVal; +} + +CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::acceptTCPConnection( + TSocketDescriptor pa_nListeningSockD){ + struct sockaddr client_addr; + int sin_size = sizeof(struct sockaddr); + TSocketDescriptor nRetVal; + +#if defined(WIN32) || defined(NET_OS) || defined (VXWORKS) + nRetVal = accept(pa_nListeningSockD, &client_addr, &sin_size); +#else + nRetVal = accept(pa_nListeningSockD, &client_addr, (socklen_t*) &sin_size); +#endif + return nRetVal; +} + +int CBSDSocketInterface::sendDataOnTCP(TSocketDescriptor pa_nSockD, char* pa_pcData, + unsigned int pa_unSize){ + // This function sends all data in the buffer before it returns! + int nToSend = pa_unSize; + int nRetVal = 0; + + while(0 < nToSend){ + //TODO: check if open connection (socket might be closed by peer) + nRetVal = static_cast(send(pa_nSockD, pa_pcData, nToSend, 0)); + if(nRetVal <= 0){ + DEVLOG_ERROR("TCP-Socket Send failed: %s\n", strerror(errno)); + break; + } + nToSend -= nRetVal; + pa_pcData += nRetVal; + } + return nRetVal; +} + +int CBSDSocketInterface::receiveDataFromTCP(TSocketDescriptor pa_nSockD, char* pa_pcData, + unsigned int pa_unBufSize){ + int nRetVal; + do{ + nRetVal = static_cast(recv(pa_nSockD, pa_pcData, pa_unBufSize, 0)); +#ifdef WIN32 + }while((-1 == nRetVal) && (WSAEINTR == h_errno)); // recv got interrupt / recieving again +#else + } while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / recieving again +#endif + if(nRetVal == -1){ +#ifdef WIN32 + DEVLOG_ERROR("CBSDSocketInterface: TCP-Socket recv() failed: %d\n", WSAGetLastError()); + if(WSAECONNRESET == WSAGetLastError()){ + nRetVal = 0; //inform higher levels that the peer closed connection + } +#else + DEVLOG_ERROR("CBSDSocketInterface: TCP-Socket recv() failed: %s\n", strerror(errno)); +#endif + } + return nRetVal; +} + +CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openUDPSendPort(char *pa_acIPAddr, + unsigned short pa_nPort, TUDPDestAddr *m_ptDestAddr){ + DEVLOG_INFO("CBSDSocketInterface: Opening UDP sending connection at: %s:%d\n", pa_acIPAddr, pa_nPort); + TSocketDescriptor nRetVal; + + nRetVal = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if(-1 != nRetVal){ + m_ptDestAddr->sin_family = AF_INET; + m_ptDestAddr->sin_port = htons(pa_nPort); + m_ptDestAddr->sin_addr.s_addr = inet_addr(pa_acIPAddr); + memset(&(m_ptDestAddr->sin_zero), '\0', sizeof(m_ptDestAddr->sin_zero)); + +#ifdef NET_OS + /* following is typedef void TM_fAR * in treck/include/trsocket.h */ + int nIfCount; + int nRunner = 0; + unsigned long nLocalInAddr; + ttUserInterface *pIfList; + ttUserInterface stInterfaceHandle; /* gets recast as above */ + + /*get interfaces */ + pIfList = tfGetInterfaceList(&nIfCount); + while (nIfCount--){ + stInterfaceHandle = pIfList[nRunner++]; + if (tfGetIpAddress(stInterfaceHandle, &nLocalInAddr, 0) == 0){ //get IPv4 Address of interface + /* bind socket to all available IPv4 addresses for multicast */ + setsockopt (nRetVal, IPPROTO_IP, IP_MULTICAST_IF, (char *) &nLocalInAddr, sizeof (nLocalInAddr)); + } + } +#endif + + } + return nRetVal; +} + +CBSDSocketInterface::TSocketDescriptor CBSDSocketInterface::openUDPReceivePort(char *pa_acIPAddr, + unsigned short pa_nPort){ + DEVLOG_INFO("CBSDSocketInterface: Opening UDP receiving connection at: %s:%d\n", pa_acIPAddr, pa_nPort); + TSocketDescriptor nRetVal = -1; + TSocketDescriptor nSocket = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); + + if(-1 != nSocket){ + int nReuseAddrVal = 1; + if(0 + <= setsockopt(nSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &nReuseAddrVal, sizeof(nReuseAddrVal))){ + struct sockaddr_in stSockAddr; + stSockAddr.sin_family = AF_INET; + stSockAddr.sin_port = htons(pa_nPort); + stSockAddr.sin_addr.s_addr = htonl(INADDR_ANY); + memset(&(stSockAddr.sin_zero), '\0', sizeof(stSockAddr.sin_zero)); + if(0 == bind(nSocket, (struct sockaddr *) &stSockAddr, sizeof(struct sockaddr))){ + // setting up multicast group + struct ip_mreq stMReq; + stMReq.imr_multiaddr.s_addr = inet_addr(pa_acIPAddr); + stMReq.imr_interface.s_addr = htonl(INADDR_ANY); + setsockopt(nSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*) &stMReq, sizeof(stMReq)); + //if this fails we may have given a non multicasting addr. For now we accept this. May need to be changed in the future. + + nRetVal = nSocket; + } + else{ + DEVLOG_ERROR("CBSDSocketInterface: bind() failed: %s\n", strerror(errno)); + } + } + else{ + DEVLOG_ERROR("CBSDSocketInterface: setsockopt(SO_REUSEADDR) failed: %s\n", strerror(errno)); + } + } + else{ + DEVLOG_ERROR("CBSDSocketInterface: Couldn't create socket: %s\n", strerror(errno)); + } + return nRetVal; +} + +int CBSDSocketInterface::sendDataOnUDP(TSocketDescriptor pa_nSockD, TUDPDestAddr *pa_ptDestAddr, + char* pa_pcData, unsigned int pa_unSize){ + // This function sends all data in the buffer before it returns! + int nToSend = pa_unSize; + int nRetVal = 0; + + while(0 < nToSend){ + //TODO: check if open connection (socket might be closed by peer) + nRetVal = static_cast( + sendto(pa_nSockD, pa_pcData, nToSend, 0, (struct sockaddr *) pa_ptDestAddr, sizeof(struct sockaddr))); + if(nRetVal <= 0){ + DEVLOG_ERROR("CBSDSocketInterface: UDP-Socket Send failed: %s\n", strerror(errno)); + break; + } + nToSend -= nRetVal; + pa_pcData += nRetVal; + } + return nRetVal; +} + +int CBSDSocketInterface::receiveDataFromUDP(TSocketDescriptor pa_nSockD, char* pa_pcData, + unsigned int pa_unBufSize){ + int nRetVal; + do{ + nRetVal = static_cast(recvfrom(pa_nSockD, pa_pcData, pa_unBufSize, 0, 0, 0)); +#ifdef WIN32 + }while((-1 == nRetVal) && (WSAEINTR == h_errno)); // recv got interrupt / recieving again +#else + } while((-1 == nRetVal) && (EINTR == errno)); // recv got interrupt / recieving again +#endif + if(nRetVal == -1){ // + DEVLOG_ERROR("CBSDSocketInterface: UDP-Socket recvfrom() failed: %s\n", strerror(errno)); + } + return nRetVal; +} diff --git a/src/arch/bsdsocketinterf.h b/src/arch/bsdsocketinterf.h new file mode 100644 index 000000000..09212c7a9 --- /dev/null +++ b/src/arch/bsdsocketinterf.h @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef BSDSOCKETINTERF_H_ +#define BSDSOCKETINTERF_H_ + + +class CBSDSocketInterface{ + public: + typedef int TSocketDescriptor; + typedef struct sockaddr_in TUDPDestAddr; + + static void closeSocket(TSocketDescriptor pa_nSockD); + static TSocketDescriptor openTCPServerConnection(char *pa_acIPAddr, unsigned short pa_nPort); + static TSocketDescriptor openTCPClientConnection(char *pa_acIPAddr, unsigned short pa_nPort); + static TSocketDescriptor acceptTCPConnection(TSocketDescriptor pa_nListeningSockD); + static int sendDataOnTCP(TSocketDescriptor pa_nSockD, char* pa_pcData, unsigned int pa_unSize); + static int receiveDataFromTCP(TSocketDescriptor pa_nSockD, char* pa_pcData, unsigned int pa_unBufSize); + + static TSocketDescriptor openUDPSendPort(char *pa_acIPAddr, unsigned short pa_nPort, TUDPDestAddr *m_ptDestAddr); + static TSocketDescriptor openUDPReceivePort(char *pa_acIPAddr, unsigned short pa_nPort); + static int sendDataOnUDP(TSocketDescriptor pa_nSockD, TUDPDestAddr *pa_ptDestAddr, char* pa_pcData, unsigned int pa_unSize); + static int receiveDataFromUDP(TSocketDescriptor pa_nSockD, char* pa_pcData, unsigned int pa_unBufSize); + + private: + CBSDSocketInterface(); //this function is not implemented as we don't want instances of this class +}; + +#endif /* BSDSOCKETINTERF_H_ */ diff --git a/src/arch/datatype.h b/src/arch/datatype.h new file mode 100644 index 000000000..bdabc3972 --- /dev/null +++ b/src/arch/datatype.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Alois Zoitl, Thomas Strasser, Martin Melik Merkumians, + * Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _DATATYPES_H_ +#define _DATATYPES_H_ + + +// this define is required to get the limit macros +#define __STDC_LIMIT_MACROS + +#include + +/*! \ingroup FORTE-HAL + * \brief This are the device-independent data types used by FORTE. + */ + +/*************************************************************************** + type definitions + ***************************************************************************/ + +typedef uint8_t TForteByte; /**< 8 bit unsigned */ +typedef uint16_t TForteWord; /**< 16 bit unsigned */ +typedef uint32_t TForteDWord; /**< 32 bit unsigned */ +typedef uint64_t TForteLWord; /**< 64 bit unsigned */ + +typedef int8_t TForteInt8; /**< 8 bit signed */ +typedef int16_t TForteInt16; /**< 16 bit signed */ +typedef int32_t TForteInt32; /**< 32 bit signed */ +typedef int64_t TForteInt64; /**< 64 bit signed */ + +typedef uint8_t TForteUInt8; /**< 8 bit unsigned */ +typedef uint16_t TForteUInt16; /**< 16 bit unsigned */ +typedef uint32_t TForteUInt32; /**< 32 bit unsigned */ +typedef uint64_t TForteUInt64; /**< 64 bit unsigned */ + +typedef float TForteFloat; /**< single precision IEEE float (32 Bit) */ +typedef double TForteDFloat; /**< double precision IEEE float (64 bit) */ + +const unsigned int cg_nIdentifierLength = 32; //! +#include +#include + +#ifndef NOLOG + +static const char* cg_acLogLevel[] = {"INFO", "WARNING", "ERROR", "DEBUG", "TRACE" }; + +//this define allows to provide an own log handler (see LMS for an example of this) +#ifndef FORTE_EXTERNAL_LOG_HANDLER + +/*! \brief print the given log message with the error level and a time stamp + * + * @param pa_ecLevel the message's log level + * @param pa_acMessage the message to log + */ +void printLogMessage(E_MsgLevel pa_eLevel, const char *pa_acMessage); + +static const int scm_nMsgBufSize = 300; +static char sm_acMsgBuf[scm_nMsgBufSize]; //!getForteTime().m_nUpperValue, CTimerHandler::sm_poFORTETimer->getForteTime().m_nLowerValue); + } + else{ + fprintf(stderr,": T#notime: "); + } + fprintf(stderr, pa_acMessage); +} + +#endif +#endif diff --git a/src/arch/devlog.h b/src/arch/devlog.h new file mode 100644 index 000000000..b58e939bb --- /dev/null +++ b/src/arch/devlog.h @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Thomas Strasser, Alois Zoitl, Ingo Hegny, Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _DEVLOG_H_ +#define _DEVLOG_H_ + +/*!\ingroup FORTE_HAL + * \brief CDeviceLog is the entity that logs messages created by the FORTE Runtime system. + * They can be printed to a console or archived somewhere (This is implementation dependent). + */ +#include "datatype.h" +#include "../core/utils/singlet.h" +#include + +enum E_MsgLevel {E_INFO, E_WARNING, E_ERROR, E_DEBUG, E_TRACE}; + +// possible loglevels: NOLOG, LOGERROR, LOGWARNING, LOGINFO, LOGDEBUG +/* Meaning: + * LOGERROR: log only error messages + * LOGWARNING: log error and warning messages + * LOGINFO: log error, warning, and info messages + * LOGDEBUG: log all messages: error, warning, info, and debug + * NOLOG: log no messages + */ + +#if !(defined(NOLOG) || defined(LOGERROR) || defined(LOGWARNING) || defined(LOGINFO) || defined(LOGDEBUG)) +/* Set default loglevel */ +# define LOGDEBUG +#endif + +#ifdef LOGDEBUG + #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__) + #define DEVLOG_WARNING(...) logMessage(E_WARNING, __VA_ARGS__) + #define DEVLOG_INFO(...) logMessage(E_INFO, __VA_ARGS__) + #define DEVLOG_DEBUG(...) logMessage(E_DEBUG, __VA_ARGS__) +#endif + +#ifdef LOGERROR + #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__) + #define DEVLOG_WARNING(...) + #define DEVLOG_INFO(...) + #define DEVLOG_DEBUG(...) +#endif + +#ifdef LOGWARNING + #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__) + #define DEVLOG_WARNING(...) logMessage(E_WARNING, __VA_ARGS__) + #define DEVLOG_INFO(...) + #define DEVLOG_DEBUG(...) +#endif + +#ifdef LOGINFO + #define DEVLOG_ERROR(...) logMessage(E_ERROR, __VA_ARGS__) + #define DEVLOG_WARNING(...) logMessage(E_WARNING, __VA_ARGS__) + #define DEVLOG_INFO(...) logMessage(E_INFO, __VA_ARGS__) + #define DEVLOG_DEBUG(...) +#endif + +#ifdef NOLOG + #define DEVLOG_INFO(...) + #define DEVLOG_WARNING(...) + #define DEVLOG_ERROR(...) + #define DEVLOG_DEBUG(...) +#endif + +#if (defined(FORTE_TRACE_EVENTS) && !defined(NOLOG)) + #define FORTE_TRACE(...) logMessage(E_TRACE, __VA_ARGS__) +#else + #define FORTE_TRACE(...) +#endif + +#ifndef NOLOG + +/*! \brief Adds an Entry to the LogBook + * + */ + void logMessage(E_MsgLevel pa_eLevel, const char *pa_acMessage, ...); +#endif + +#endif //_DEVLOG_H_ diff --git a/src/arch/ecos/CMakeLists.txt b/src/arch/ecos/CMakeLists.txt new file mode 100644 index 000000000..a3319169a --- /dev/null +++ b/src/arch/ecos/CMakeLists.txt @@ -0,0 +1,14 @@ +#******************************************************************************* +# * Copyright (c) 2010 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +add_subdirectory(phycoreat91) + +#as LMS is added differently it is not put here as sub directory diff --git a/src/arch/ecos/ecoscppinit.cpp b/src/arch/ecos/ecoscppinit.cpp new file mode 100644 index 000000000..c2d99278b --- /dev/null +++ b/src/arch/ecos/ecoscppinit.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +//current tests have shown that this works only if it is in the main.cpp file +//I don't know why. The best is to copy or include it into your specific main file + +//Workaround for an ecos problem +extern "C" void +__cxa_pure_virtual(void) { + //TODO maybe add some exception handling reporting here +} diff --git a/src/arch/ecos/ecostiha.cpp b/src/arch/ecos/ecostiha.cpp new file mode 100644 index 000000000..f5f063957 --- /dev/null +++ b/src/arch/ecos/ecostiha.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "ecostiha.h" +#include "../../core/devexec.h" + +cyg_sem_t CECOSTimerHandler::m_stSemaphore; + +void CTimerHandler::createTimerHandler(void){ + if(0 == sm_poFORTETimer){ + sm_poFORTETimer = new CECOSTimerHandler(); + static_cast(sm_poFORTETimer)->start(); + } +} + +CECOSTimerHandler::CECOSTimerHandler(){ + cyg_semaphore_init(&m_stSemaphore, 0); + + m_stSystemclockHandle = cyg_real_time_clock(); + cyg_clock_to_counter(m_stSystemclockHandle, &m_stCounterHandle); + + cyg_alarm_create(m_stCounterHandle, timerHandlerFunc, (cyg_addrword_t) 0, &m_stAlarmHandle, &m_stAlarm); +} + +CECOSTimerHandler::~CECOSTimerHandler(){ + cyg_semaphore_destroy(&m_stSemaphore); +} + +void CECOSTimerHandler::enableHandler(void){ + cyg_alarm_initialize(m_stAlarmHandle, cyg_current_time() + 1, 1); +} + +void CECOSTimerHandler::disableHandler(void){ + cyg_alarm_disable(m_stAlarmHandle); +} + +void CECOSTimerHandler::setPriority(int ){ + +} + +int CECOSTimerHandler::getPriority(void) const{ + return 0; +} + +void CECOSTimerHandler::run(void){ + CECOSThread::setPriority(0); //we want to be a very important thread + while(isAlive()){ + cyg_semaphore_wait(&m_stSemaphore); + //FIXME add compensation code for timer activation jitter similar to the code in the posix architecture + sm_poFORTETimer->nextTick(); + } +} + diff --git a/src/arch/ecos/ecostiha.h b/src/arch/ecos/ecostiha.h new file mode 100644 index 000000000..dde483eda --- /dev/null +++ b/src/arch/ecos/ecostiha.h @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ECOSTIMEHA_H_ +#define _ECOSTIMEHA_H_ + +#include +#include "../timerha.h" +#include "thread.h" + +/*! \brief External event handler for the eCos Timer. + * \ingroup ECOS-HAL + * + */ +class CECOSTimerHandler : public CTimerHandler, private CThread{ + public: + virtual ~CECOSTimerHandler(); + + /*!\brief Enables this event source + * + */ + virtual void enableHandler(void); + /*!\brief Disable this event source + */ + virtual void disableHandler(void); + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority); + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const; + + private: + + static cyg_sem_t m_stSemaphore; + + /*!\brief callback function for the system timer + */ + static void timerHandlerFunc(cyg_handle_t , cyg_addrword_t ){ + cyg_semaphore_post(&m_stSemaphore); + } + + CECOSTimerHandler(); + virtual void run(void); + + cyg_handle_t m_stAlarmHandle; + cyg_handle_t m_stCounterHandle, m_stSystemclockHandle; + cyg_alarm m_stAlarm; + + friend class CTimerHandler; +}; + +#endif /*_ECOSTIMEHA_H_*/ diff --git a/src/arch/ecos/fortealloc.h b/src/arch/ecos/fortealloc.h new file mode 100644 index 000000000..11c05a9b0 --- /dev/null +++ b/src/arch/ecos/fortealloc.h @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FORTEALLOC_H_ +#define FORTEALLOC_H_ + +//on ecos environments we are typically happy with the generic alloc implementation based on malloc and free +#include "../genfortealloc.h" + +#endif /* FORTEALLOC_H_ */ diff --git a/src/arch/ecos/phycoreat91/CMakeLists.txt b/src/arch/ecos/phycoreat91/CMakeLists.txt new file mode 100644 index 000000000..22686a134 --- /dev/null +++ b/src/arch/ecos/phycoreat91/CMakeLists.txt @@ -0,0 +1,41 @@ +#******************************************************************************* +# * Copyright (c) 2010 -2105 ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +SET(SOURCE_GROUP ${SOURCE_GROUP}\\phycoreat91) + +forte_add_architecture("Phycore AT91") + +if("${FORTE_ARCHITECTURE}" STREQUAL "Phycore AT91") + + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) + + forte_add_sourcefile_hcpp(../thread ../ecostiha ../sync) + forte_add_sourcefile_cpp(phycoreAT91main.cpp) + + if(FORTE_COM_ETH) + forte_add_sourcefile_hcpp( ../../fdselecthand ../../bsdsocketinterf) + forte_add_sourcefile_h(../gensockhand.h) + forte_add_sourcefile_h(../sockhand.h) + endif(FORTE_COM_ETH) + + forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR}) + + forte_add_definition("-Wpointer-arith -Wundef -Woverloaded-virtual -Wno-write-strings") + forte_add_definition("-W -Wall -Wextra -D_KERNEL -D__ECOS -DFORTE_LITTLE_ENDIAN") + forte_add_definition("-mcpu=arm7tdmi -msoft-float -mno-thumb-interwork -g -O2") + forte_add_definition("-ffunction-sections -fdata-sections -fno-threadsafe-statics -fno-rtti -fno-exceptions") + + + forte_add_link_flags("-mcpu=arm7tdmi -msoft-float -W,--gc-sections -g -nostartfiles -nostdlib -fno-threadsafe-statics -mno-thumb-interwork -Wl,-static -Wl,-M -Wl,-Map -Wl,forte.map -Wl,-cref") + + + +endif() \ No newline at end of file diff --git a/src/arch/ecos/phycoreat91/phycoreAT91main.cpp b/src/arch/ecos/phycoreat91/phycoreAT91main.cpp new file mode 100644 index 000000000..6d7fcfbc4 --- /dev/null +++ b/src/arch/ecos/phycoreat91/phycoreAT91main.cpp @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007, 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include +#include +#include // IO macros + +externC void +cyg_user_start( void ); + +void cyg_user_start(void){ + RMT_DEV *dev = new RMT_DEV; //otherwise we would loose the var if it is only on the stack + dev->startDevice(); +} + +//get the stuff that fixes some ecos cpp problems which have to be near the main +#include "../ecoscppinit.cpp" diff --git a/src/arch/ecos/sockhand.h b/src/arch/ecos/sockhand.h new file mode 100644 index 000000000..8d4631f94 --- /dev/null +++ b/src/arch/ecos/sockhand.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef SOCKHAND_H_ +#define SOCKHAND_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//these include needs to be last +#include "../fdselecthand.h" +#include "../bsdsocketinterf.h" +#include "../gensockhand.h" + +typedef CGenericIPComSocketHandler CIPComSocketHandler; + +#endif /* SOCKHAND_H_ */ diff --git a/src/arch/ecos/sync.cpp b/src/arch/ecos/sync.cpp new file mode 100644 index 000000000..af7582cd6 --- /dev/null +++ b/src/arch/ecos/sync.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "sync.h" + +CECOSSyncObject::CECOSSyncObject(){ + cyg_mutex_init(&m_oMutexHandle); + cyg_mutex_set_protocol(&m_oMutexHandle, CYG_MUTEX_NONE); +} + +CECOSSyncObject::~CECOSSyncObject(){ + cyg_mutex_destroy(&m_oMutexHandle); +} diff --git a/src/arch/ecos/sync.h b/src/arch/ecos/sync.h new file mode 100644 index 000000000..91b8767ce --- /dev/null +++ b/src/arch/ecos/sync.h @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2006, 2007 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SYNC_H_ +#define _SYNC_H_ + +#include + +#define CSyncObject CECOSSyncObject //allows that doxygen can generate better documenation + +/*! \ingroup ECOS-HAL + * \brief The sync object implementation for eCos. + * + * In the eCos version a mutex is used for the sync object. + */ +class CECOSSyncObject{ + private: + protected: + //! The posix thread mutex handle of the operating system. + cyg_mutex_t m_oMutexHandle; + public: + CECOSSyncObject(); + ~CECOSSyncObject(); + /*!\brief Lock the resource coming after the lock command + * + * This function blocks until it will get the lock for the coming critical section. + */ + void lock(void){ + cyg_mutex_lock(&m_oMutexHandle); + }; + //!Freee the resource coming after the lock command + void unlock(void){ + cyg_mutex_unlock(&m_oMutexHandle); + }; +}; + +#endif /*SYNC_H_*/ diff --git a/src/arch/ecos/thread.cpp b/src/arch/ecos/thread.cpp new file mode 100644 index 000000000..955f96990 --- /dev/null +++ b/src/arch/ecos/thread.cpp @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include "thread.h" + +TCECOSThreadPtr CECOSThread::sm_aoThreadList[CECOSThread::scm_nThreadListSize] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +CSyncObject CECOSThread::sm_oThreadListLock; + +bool CECOSThread::create(void){ + // Get new Thread + cyg_thread_create(scm_nThreadListSize + 2, //lowest priority in ecos + threadFunction, (cyg_addrword_t)(this), + "Test Name", m_cStack, + m_nStackSize, + &m_stHandle, + &m_stThread); + +//setup the signals for the join implementation + return true; +} + +void CECOSThread::threadFunction(cyg_addrword_t data){ + // Get pointer to CThread object out of void pointer + CECOSThread *pThread = (CECOSThread *)(data); + + // if pointer is ok + if (pThread){ + CCriticalRegion criticalRegion(pThread->m_stResLock); + pThread->m_bAlive = true; + pThread->run(); + pThread->m_bAlive = false; + } + cyg_thread_exit(); +} + +CECOSThread::CECOSThread(long pa_nStackSize){ + m_bAlive = false; + m_nStackSize = pa_nStackSize; + m_cStack = new unsigned char[m_nStackSize]; + cyg_semaphore_init(&m_stSuspendSem, 0); +} + +CECOSThread::~CECOSThread(){ + end(); + cyg_semaphore_destroy(&m_stSuspendSem); + delete[] m_cStack; +} + +void CECOSThread::setDeadline(const CIEC_TIME &pa_roVal){ + int i, ii; + CCriticalRegion criticalRegion(sm_oThreadListLock); + DEVLOG_DEBUG(">>>>Thread: Set Deadline: %lu\n", pa_roVal.operator TValueType ()); + m_oDeadLine = pa_roVal; + //first of all check if this thread is already in the list and remove it from the list + for(i = 0; i < scm_nThreadListSize; i++){ + if(0 == sm_aoThreadList[i]) + break; + else + if(this == sm_aoThreadList[i]){ + for(ii = i; ii < scm_nThreadListSize - 1; ii++){ + if(0 == sm_aoThreadList[ii + 1]) + break; + sm_aoThreadList[ii + 1]->setPriority(ii + 2); + sm_aoThreadList[ii] = sm_aoThreadList[ii + 1]; + } + break; + } + } + + if(0 == m_oDeadLine) + setPriority(scm_nThreadListSize + 2); // use the lowest user priority + else{ + for(i = 0; i < scm_nThreadListSize; i++){ + if(0 == sm_aoThreadList[i]){ + sm_aoThreadList[i] = this; + setPriority( i + 2); + break; + } + else + if(m_oDeadLine < sm_aoThreadList[i]->getDeadline()){ + CECOSThread *poRBuf, *poSBuf= sm_aoThreadList[i]; + sm_aoThreadList[i] = this; + setPriority( i + 2); + for(ii = i + 1; ii < scm_nThreadListSize; ii++){ + poSBuf->setPriority(ii + 2); + poRBuf = sm_aoThreadList[ii]; + sm_aoThreadList[ii] = poSBuf; + if(0 == poRBuf) + break; + poSBuf = poRBuf; + } + break; + } + } + } +} + +void CECOSThread::join(void){ + if(isAlive()){ + {CCriticalRegion criticalRegion(m_stResLock); } + cyg_thread_delete(m_stHandle); + } +} diff --git a/src/arch/ecos/thread.h b/src/arch/ecos/thread.h new file mode 100644 index 000000000..f0f3b2934 --- /dev/null +++ b/src/arch/ecos/thread.h @@ -0,0 +1,185 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Carolyn Oates - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _THREAD_H_ +#define _THREAD_H_ + +#include +#include "../datatype.h" +#include "sync.h" +#include "../devlog.h" +#include "../../core/datatypes/forte_time.h" + +#define CThread CECOSThread //allows that doxygen can generate better documentation +class CECOSThread; + +typedef CECOSThread *TCECOSThreadPtr; + +/** \defgroup ECOS-HAL eCos FORTE Hardware Abstraction Layer + *\ingroup FORTE-HAL + * \brief The FORTE-HAL implementation for the eCos operating system. + * + * + */ +/*! \ingroup ECOS-HAL + * \brief This class is a wrapper class the eCos multitasking support + */ +class CECOSThread { + public: + /*! \brief Constructor of the Thread class + * + * Does all the necessary steps in order to get the thread running with the start()-method + * @param pa_nStackSize the Size of the stack the thread is allowed to use. this class will + * allocate the stack size in bytes from the heap + */ + CECOSThread(long pa_nStackSize = CYGNUM_HAL_STACK_SIZE_TYPICAL); // may need adjustment for small platforms + + /*! \brief Stops and destroys thread. + * + * Will stop the execution if running and destroy the thread including all system specific data. + */ + virtual ~CECOSThread(); + + /*! \brief Indicates if the thread is allowed to execute. + * + * This functions checks if the Thread is still executing user code in its run()-method. + * \return true if there the run method is active. + */ + bool isAlive(void) const { + return m_bAlive; + } + + //!Set the deadline of the thread. + void setDeadline(const CIEC_TIME &pa_roVal); + + //!Get the current deadline of the thread. + const CIEC_TIME &getDeadline(void) const { + return m_oDeadLine; + } + + + /*! \brief starts the Thread + * + * By calling this method the execution in the run()-Method will be started. If necessary additional data + * can be created here. Because of inheritance reasons the best place for executing create is in this method. + */ + void start(void){ + create(); + cyg_thread_resume(m_stHandle); + } + + /*! \brief Resumes a suspended Thread + * + * + */ + void resumeSelfSuspend(void){ + cyg_semaphore_post(&m_stSuspendSem); + } + + /*! \brief Stops the execution of the thread + * + * This function imidiatly stops the execution of the thread (seting m_bAlive to false) and waits till + * this is finished. + */ + void end(void){ + m_bAlive = false; + resumeSelfSuspend(); + join(); + } + + /*! \brief Waits for the Thread to finish its execution. + * + * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!! + */ + void join(void); + protected: + /*! \brief Suspends the thread. + * + * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called. + */ + + void selfSuspend(void){ + cyg_semaphore_wait(&m_stSuspendSem); + } + + void setPriority(cyg_priority_t pa_nPriority) { + DEVLOG_DEBUG(">>>>Thread: Set Priority: %d\n", pa_nPriority); + cyg_thread_set_priority(m_stHandle, pa_nPriority); + } + + private: + /*!\brief Function that is given to the system thread support that should be called for the thread. + * + * this function will call the run method of the thread instance. + */ + static void threadFunction(cyg_addrword_t data); + + /*! \brief Abstract method for the code to execute in the thread. + * + * This thread class has to provide means that the code a inheriting class will add to the run()-method will + * be executed in a separated thread regarding the creator of the CThread class. + * + * The inheriting class has to fulfill the following rules when using the run method: + * - To end the thread execution simple leave the run()-method + * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the + * execution if isAlive() returns false. + */ + virtual void run() = 0; + + /*! \brief Creates a new thread. + * + * With this function all the setup things for a new thread are done. The Thread created is initial + * suspended and with the start() method the execution of the code in the run() method is started. + */ + bool create(void); + + /*! \brief Destroys the thread + * + * This function destroys all the data structures created in the creation phase. All used memory is freed. + */ + bool destroy(void); + + + static const int scm_nThreadListSize = 27; + static TCECOSThreadPtr sm_aoThreadList[scm_nThreadListSize]; + static CSyncObject sm_oThreadListLock; + + /*! \brief data needed for ecos to identify the thread. + */ + cyg_handle_t m_stHandle; + cyg_thread m_stThread; + //! used for providing the join function + CSyncObject m_stResLock; + + /*! \brief Size of the stack used by this thread. + */ + long m_nStackSize; + unsigned char *m_cStack; + CIEC_TIME m_oDeadLine; + cyg_sem_t m_stSuspendSem; //! Semaphore for implementing the self suspend + + + /*! \brief Flag that indicates if the Thread is alive. + * + * This flag has two main purposes: + * -# indicate for other classes if the thread is still executing + * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ). + * This is important for stopping and destroying threads. + */ + bool m_bAlive; + + //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private + //but not implemented + CECOSThread(const CECOSThread&); + CECOSThread& operator = (const CECOSThread &); + +}; + +#endif /*THREAD_H_*/ diff --git a/src/arch/fdselecthand.cpp b/src/arch/fdselecthand.cpp new file mode 100644 index 000000000..c4af2bd5c --- /dev/null +++ b/src/arch/fdselecthand.cpp @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include //needs to be first pulls in the platform specific includes +#include "fdselecthand.h" +#include "../core/devexec.h" +#include "devlog.h" +#include "../core/cominfra/commfb.h" +#include + + +DEFINE_SINGLETON(CFDSelectHandler); + +CFDSelectHandler::CFDSelectHandler(){ + m_bConnectionListChanged = false; +#ifdef WIN32 + // Windows Socket Startupcode + WORD wVersionRequested; + WSADATA wsaData; + int err; + + /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ + wVersionRequested = MAKEWORD(2, 2); + + err = WSAStartup(wVersionRequested, &wsaData); +#endif +} + +CFDSelectHandler::~CFDSelectHandler(){ + this->end(); +#ifdef WIN32 + WSACleanup(); +#endif +} + +// single-threaded-network-code +void CFDSelectHandler::run(void){ + + struct timeval tv; + fd_set anFDSet; + fd_set anFDSetMaster; + + int nHighestFDID = 0; + int retval = 0; + + FD_ZERO(&anFDSetMaster); + + while(isAlive()){ + // TODO: create method to prevent 100ms timeout on reconnection + m_oSync.lock(); + if(m_lstConnectionsList.isEmpty()){ + m_oSync.unlock(); + selfSuspend(); + m_oSync.lock(); + } + + if(true == m_bConnectionListChanged){ + nHighestFDID = createFDSet(&anFDSetMaster); + } + anFDSet = anFDSetMaster; + m_oSync.unlock(); + + tv.tv_sec = 1; //TODO : To be set! + tv.tv_usec = 1000; + + if(0 != nHighestFDID){ + retval = select(nHighestFDID + 1, &anFDSet, NULL, NULL, &tv); + } + else{ + retval = 0; + } + + if(retval > 0){ + m_oSync.lock(); + TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end()); + for(TConnectionContainer::Iterator itRunner = m_lstConnectionsList.begin(); itRunner != itEnd;){ + // need to retrieve the callee as the iterator may get invalid in the recvDat function below in case of connection closing + forte::com_infra::CComLayer *comLayer = itRunner->m_poCallee; + TFileDescriptor sockDes = itRunner->m_nSockDes; + ++itRunner; + + if((0 != FD_ISSET(sockDes, &anFDSet)) && (0 != comLayer)){ + m_oSync.unlock(); + if(forte::com_infra::e_Nothing != comLayer->recvData(&sockDes,0)){ + startNewEventChain(comLayer->getCommFB()); + } + m_oSync.lock(); + } + } + m_oSync.unlock(); + } + else{ + if(retval == 0){ +// printf("."); + } + else{ +#ifdef WIN32 + DEVLOG_ERROR("Select failed: %d", WSAGetLastError()); +#else + DEVLOG_ERROR("Select failed: %s", strerror(errno)); +#endif + } + } + } +} + +void CFDSelectHandler::addComCallback(TFileDescriptor pa_nFD, forte::com_infra::CComLayer *pa_poComLayer){ + { + CCriticalRegion criticalRegion(m_oSync); + TConnContType stNewNode = { pa_nFD, pa_poComLayer }; + m_lstConnectionsList.push_back(stNewNode); + m_bConnectionListChanged = true; + } + if(!isAlive()){ + this->start(); + } + resumeSelfSuspend(); +} + +void CFDSelectHandler::removeComCallback(TFileDescriptor pa_nFD){ + CCriticalRegion criticalRegion(m_oSync); + + TConnectionContainer::Iterator itRunner(m_lstConnectionsList.begin()); + TConnectionContainer::Iterator itRefNode(m_lstConnectionsList.end()); + TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end()); + + while(itRunner != itEnd){ + if(itRunner->m_nSockDes == pa_nFD){ + if(itRefNode ==itEnd){ + m_lstConnectionsList.pop_front(); + } + else{ + m_lstConnectionsList.eraseAfter(itRefNode); + } + break; + } + + itRefNode = itRunner; + ++itRunner; + } + + m_bConnectionListChanged = true; +} + +CFDSelectHandler::TFileDescriptor CFDSelectHandler::createFDSet(fd_set *m_panFDSet){ + TFileDescriptor nRetVal = 0; + FD_ZERO(m_panFDSet); + TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end()); + for(TConnectionContainer::Iterator itRunner = m_lstConnectionsList.begin(); itRunner != itEnd; ++itRunner){ + FD_SET(itRunner->m_nSockDes, m_panFDSet); + if(itRunner->m_nSockDes > nRetVal){ + nRetVal = itRunner->m_nSockDes; + } + } + m_bConnectionListChanged = false; + return nRetVal; +} diff --git a/src/arch/fdselecthand.h b/src/arch/fdselecthand.h new file mode 100644 index 000000000..e5bc6fa7a --- /dev/null +++ b/src/arch/fdselecthand.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Patrick Smejkal + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FDHAND_H_ +#define _FDHAND_H_ + +#include "../core/fortelist.h" +#include "../core/extevhan.h" +#include "../core/cominfra/comlayer.h" +#include "../core/utils/singlet.h" +#include +#include + +#if !defined(WIN32) && !defined(NET_OS) && !defined(VXWORKS) +#include +#endif + +/*!\brief An external event handler for file descriptor based external events. + * + * This handler uses a thread and the select function to monitor given file descriptors on + * data reception. Examples for possible file descriptors are sockets or com re + */ + +class CFDSelectHandler : public CExternalEventHandler, private CThread{ + DECLARE_SINGLETON(CFDSelectHandler) + ; + public: + typedef int TFileDescriptor; //!< General type definition for a file descriptor. To be used by the callback classes. + static const TFileDescriptor scm_nInvalidFileDescriptor = -1; + + void addComCallback(TFileDescriptor pa_nFD, forte::com_infra::CComLayer *pa_poComLayer); + void removeComCallback(TFileDescriptor pa_nFD); + + /* functions needed for the external event handler interface */ + void enableHandler(void){ + start(); + } + + void disableHandler(void){ + end(); + } + + void setPriority(int ){ + //currently we are doing nothing here. + //TODO We should adjust the thread priority. + } + + int getPriority(void) const { + //the same as for setPriority + return 0; + } + + protected: + virtual void run(void); + + private: + struct TConnContType{ + TFileDescriptor m_nSockDes; + forte::com_infra::CComLayer * m_poCallee; + }; + + typedef CSinglyLinkedList TConnectionContainer; + + TFileDescriptor createFDSet(fd_set *m_panFDSet); + + TConnectionContainer m_lstConnectionsList; + CSyncObject m_oSync; + bool m_bConnectionListChanged; +}; + +#endif diff --git a/src/arch/genfortealloc.h b/src/arch/genfortealloc.h new file mode 100644 index 000000000..16c96cb3a --- /dev/null +++ b/src/arch/genfortealloc.h @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2013 ACIN, nxtcontrol GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Stanislav Meduna, Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef GENFORTEALLOC_H_ +#define GENFORTEALLOC_H_ + +#include "datatype.h" +#include +#include + + +inline +void forte_free(void *pa_pvData){ + free(pa_pvData); +} + +inline +void *forte_malloc(size_t pa_nSize){ + return malloc(pa_nSize); +} + +inline +void *forte_realloc(void *pa_pvData, size_t pa_nSize){ + return realloc(pa_pvData, pa_nSize); +} + +/*! \file genfortealloc.h + * Collection of new and delete operators used by forte for dynamically allocating memory. + * + * The generic implementation uses malloc and free in order to not introduce any std c++ overhead + * other implementations are also fine. + * + * TODO try std new with nothrow. + */ + +inline +void* operator new(size_t pa_nSize) throw (std::bad_alloc){ + return malloc(pa_nSize); +} + +inline +void* operator new[](size_t pa_nSize) throw (std::bad_alloc){ + return malloc(pa_nSize ? pa_nSize : 1); +} + +inline +void operator delete(void* pa_pvData) throw(){ + if (pa_pvData) + free(pa_pvData); +} + +inline +void operator delete[](void* pa_pvData) throw(){ + if (pa_pvData) + free(pa_pvData); +} + +/*! \brief Placement new operator + * + * Will use the given buffer as memory region. The need size will be ignored. + * Objects created with this new must not deleted only invoke the destructor + * + * @param pa_pData + */ +inline +void * operator new(size_t, TForteByte *pa_pData){ + return pa_pData; +} + +inline +void * operator new[](size_t, TForteByte *pa_pData){ + return pa_pData; +} + +inline +void operator delete(void *, TForteByte *){ +} + +inline +void operator delete[](void *, TForteByte *){ +} + +#endif /* GENFORTEALLOC_H_ */ diff --git a/src/arch/gensockhand.h b/src/arch/gensockhand.h new file mode 100644 index 000000000..45ef8c6f5 --- /dev/null +++ b/src/arch/gensockhand.h @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GENSOCKHAND_H_ +#define _GENSOCKHAND_H_ + + +/*!\brief Template class allowing to easily setup IP communication socket handlers. + * + * There are two template parameters: + * - THandler an external event handler which allows Comlayers to register with a descriptor and get notifications on received messages + * - TSocektCreator a class providing methods for creating and deleting tcp and udp sockets + */ +template +class CGenericIPComSocketHandler : public THandler, public TSocketCreator{ + public: + //! Type needed by the class CIPCommLayer + typedef typename THandler::TFileDescriptor TSocketDescriptor; + + static const TSocketDescriptor scm_nInvalidSocketDescriptor = THandler::scm_nInvalidFileDescriptor; + private: + //as this class is just a place holder for the others we don't want to have an instance of it + CGenericIPComSocketHandler(); + CGenericIPComSocketHandler(const CGenericIPComSocketHandler&); + CGenericIPComSocketHandler& operator =(const CGenericIPComSocketHandler &); + ~CGenericIPComSocketHandler(); +}; + + +#endif /* _GENSOCKHAND_H_ */ diff --git a/src/arch/netos/CMakeLists.txt b/src/arch/netos/CMakeLists.txt new file mode 100644 index 000000000..f871114de --- /dev/null +++ b/src/arch/netos/CMakeLists.txt @@ -0,0 +1,15 @@ +#******************************************************************************* +# * Copyright (c) 2011 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl, Patrick Smejkal +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +#add_subdirectory(netos73) +add_subdirectory(netos74) + diff --git a/src/arch/netos/fortealloc.h b/src/arch/netos/fortealloc.h new file mode 100644 index 000000000..04036ce09 --- /dev/null +++ b/src/arch/netos/fortealloc.h @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FORTEALLOC_H_ +#define FORTEALLOC_H_ + +//on threadx environments we are typically happy with the generic alloc implementation based on malloc and free +#include "../genfortealloc.h" + +#endif /* FORTEALLOC_H_ */ diff --git a/src/arch/netos/netos74/CMakeLists.txt b/src/arch/netos/netos74/CMakeLists.txt new file mode 100644 index 000000000..a1daba61e --- /dev/null +++ b/src/arch/netos/netos74/CMakeLists.txt @@ -0,0 +1,125 @@ +#******************************************************************************* +# * Copyright (c) 2011, 2014 ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl, Patrick Smejkal - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +SET(SOURCE_GROUP ${SOURCE_GROUP}\\netos74) + +forte_add_architecture("NetOS 7.4") + +if("${FORTE_ARCHITECTURE}" STREQUAL "NetOs 7.4") + + +####################################################################################### +# Buffer root path and convert it to Cygwin format +####################################################################################### + set(NETOS_ROOT_PATH_WIN ${CMAKE_FIND_ROOT_PATH}) + execute_process(COMMAND cygpath ${CMAKE_FIND_ROOT_PATH} OUTPUT_VARIABLE NETOS_ROOT_PATH_CYG) + string(REPLACE "\n" "" NETOS_ROOT_PATH_CYG ${NETOS_ROOT_PATH_CYG}) + + +####################################################################################### +# Look for available Board support packages +####################################################################################### + set(FORTE_NETOS74_BSP "connectme" CACHE STRING "Select NetOS Board Support Package") + execute_process(COMMAND ls ${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu/bsp OUTPUT_VARIABLE LS_BSP) + execute_process(COMMAND echo -n ${LS_BSP} OUTPUT_VARIABLE ECHO_BSP) + string(LENGTH "${ECHO_BSP}" LEN_BSP) + if(LEN_BSP EQUAL 0) + message(FATAL_ERROR "No Board Support Package found! Have you installed Digi NET+OS toolchain and set CMAKE_FIND_ROOT_PATH to the root directory of it (default C:\\netos74)?") + endif(LEN_BSP EQUAL 0) + string(REPLACE " " ";" AVAILABLE_BSP ${ECHO_BSP}) + set_property(CACHE FORTE_NETOS74_BSP PROPERTY STRINGS ${AVAILABLE_BSP}) + + +####################################################################################### +# Add commands for creating target image +####################################################################################### + forte_add_post_build_command(COMMAND arm-elf-objcopy.exe ARGS -Obinary src/forte src/forte.uncompressed + COMMAND ${NETOS_ROOT_PATH_WIN}/bin/compress.exe ARGS src/forte.uncompressed src/forte.compressed + COMMAND ${NETOS_ROOT_PATH_WIN}/bin/boothdr.exe ARGS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/bootldr.dat src/forte.compressed src/forte.bin connectme_rfid + COMMAND cp src/forte.bin image.bin + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Create target image (image.bin)...") + + +####################################################################################### +# COMPILER FLAGS - INCLUDE DIRS +####################################################################################### + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) + + forte_add_sourcefile_hcpp(../thread ../txtimeha ../sync) + forte_add_sourcefile_cpp(appconf_api.c ../root.cpp) + + if(FORTE_COM_ETH) + forte_add_sourcefile_hcpp( ../../fdselecthand ../../bsdsocketinterf) + forte_add_sourcefile_h(../gensockhand.h) + forte_add_sourcefile_h(../sockhand.h) + endif(FORTE_COM_ETH) + + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + # Include-Dirs for NetOS + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/shared) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/threadx) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/tcpip) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/snmp) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/rphttpd) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/fs_intf) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/wln) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/h/wps) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/src/treck/include) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/src/treck/source/ossupport) + forte_add_include_directories(${NETOS_ROOT_PATH_CYG}/src/treck/source/ossupport/netos) + + forte_add_definition(-Wpointer-arith -Wundef -Woverloaded-virtual -Wno-write-strings) + forte_add_definition(-W -Wall -Wextra -DFORTE_BIG_ENDIAN -DIAM_ENABLED) + forte_add_definition(-D__GNU__ -DNETOS_GNU_TOOLS -DNETOS_GNU_CLIB_REENT -DNET_OS -DNET_WORKS -D_POSIX_SOURCE) + #forte_add_definition(-DBOOT_LOADER) + forte_add_definition(-DIAM_ENABLED -DNET_OS_SPECIFIC -DFUSION=0 -DTRECK=1 -DNETWORK_STACK=1) + forte_add_definition(-mbig-endian -mcpu=arm7tdmi -g -O2) + forte_add_definition(-ffunction-sections -fdata-sections -fno-threadsafe-statics -fno-rtti -fno-exceptions) + + +####################################################################################### +# LINKER FLAGS +####################################################################################### + # Linker-Flags for NetOS + forte_add_link_directories(${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu) + forte_add_link_directories(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu) + forte_add_link_directories(${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}) + + forte_add_link_library(-Wl,--start-group) + + # Look for reset.o + if(EXISTS ${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o) + forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o) + else(EXISTS ${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o) + message(WARNING "reset.o wasn't found where it is expected (${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o). Your program maybe won't work without this object. Build BSP first! For further information please refer to the Digi support.") + endif(EXISTS ${NETOS_ROOT_PATH_WIN}/lib/arm7/32b/gnu/bsp/${FORTE_NETOS74_BSP}/reset.o) + + forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crt0.o) + forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crti.o) + forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crtbegin.o) + forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crtend.o) + forte_add_link_library(${NETOS_ROOT_PATH_CYG}/lib/32b/gnu/crtn.o) + forte_add_link_library(-lbsp -lftpsvr -lflash -lfilesys -lposix -ltx -ldnsclnt -laddp -ltcpip -ltelnsvr) + forte_add_link_library(-lc -lgcc -lm -lstdc++) + forte_add_link_library(-Wl,--end-group) + + # Look for image.ld + if(EXISTS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld) + forte_add_link_flags("-mbig-endian -nostartfiles -nostdlib -mcpu=arm7tdmi -T ${NETOS_ROOT_PATH_CYG}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld") + else(EXISTS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld) + message(WARNING "image.ld wasn't found where it is expected (${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld). Your program maybe won't work without this object. Build BSP first! For further information please refer to the Digi support.") + forte_add_link_flags("-mbig-endian -nostartfiles -nostdlib -mcpu=arm7tdmi -T") + endif(EXISTS ${NETOS_ROOT_PATH_WIN}/src/bsp/platforms/${FORTE_NETOS74_BSP}/image.ld) + +endif() \ No newline at end of file diff --git a/src/arch/netos/root.cpp b/src/arch/netos/root.cpp new file mode 100644 index 000000000..4b0593fda --- /dev/null +++ b/src/arch/netos/root.cpp @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Rene Smodic, Alois Zoitl, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include +#include "appconf_api.h" +#include "../../forte.h" +#include +#include +#include + +/* + * Set this to 1 to run the system POST tests during startup. + */ +const int APP_POST = 0; + +/* + * Set this to 1 to run the manufacturing burn in tests. + */ +int APP_BURN_IN_TEST = 0; + +/* + * Function: void applicationTcpDown (void) + * + * Description: + * + * This routine will be called by the NET+OS root thread once every + * clock tick while it is waiting for the TCP/IP stack to come up. + * + * This routone is called to print the application name and then + * to print the '.' every second. + * + * This function will not be called once the stack has started. + * + * This function uses the global C++ object PrintApplicationDown app_down. + * + * Parameters: + * + * none + * + * Return Values: + * + * none + */ +extern "C" +void applicationTcpDown(void) { + static int ticksPassed = 0; + ticksPassed++; +} + + +/* + * Function: void applicationStart (void) + * + * Description: + * + * This routine is responsible for starting the user application. It should + * create any threads or other resources the application needs. + * + * ThreadX, the NET+OS device drivers, and the TCP/IP stack will be running + * when this function is called. + * + * This function uses global C++ object: + * PrintApplicationDown app_down. + * + * Parameters: + * + * none + * + * Return Values: + * + * none + */ + +extern "C" +void applicationStart(void) { + DEVLOG_INFO("\n\nStarting FTP-Server\n\n"); + naFtpDlInit(NA_FTP_DEF_USERS); + + DEVLOG_INFO("\n\nStarting forteMain()\n\n"); + + // Starting Runtime + RMT_DEV dev; + dev.startDevice(); + dev.MGR.getResourceEventExecution()->join(); + tx_thread_suspend(tx_thread_identify()); +} + + + + + diff --git a/src/arch/netos/sockhand.h b/src/arch/netos/sockhand.h new file mode 100644 index 000000000..eb262e01e --- /dev/null +++ b/src/arch/netos/sockhand.h @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef SOCKHAND_H_ +#define SOCKHAND_H_ + +#include +#include +#include +//these include needs to be last +#include "../fdselecthand.h" +#include "../bsdsocketinterf.h" +#include "../gensockhand.h" + +typedef CGenericIPComSocketHandler CIPComSocketHandler; + + +#endif /* SOCKHAND_H_ */ diff --git a/src/arch/netos/sync.cpp b/src/arch/netos/sync.cpp new file mode 100644 index 000000000..df5c55258 --- /dev/null +++ b/src/arch/netos/sync.cpp @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2010 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "sync.h" + +CTXSyncObject::CTXSyncObject(){ + tx_mutex_create(&m_stMutex, "Test Mutex", TX_INHERIT); + //TODO handle return value +} + +CTXSyncObject::~CTXSyncObject(){ + tx_mutex_delete(&m_stMutex); + //TODO handle return value +} diff --git a/src/arch/netos/sync.h b/src/arch/netos/sync.h new file mode 100644 index 000000000..be535f6de --- /dev/null +++ b/src/arch/netos/sync.h @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SYNC_H_ +#define _SYNC_H_ + +#include + +#define CSyncObject CTXSyncObject //allows that doxygen can generate better documenation + +/*! \ingroup tnetos_hal + * \brief The sync object implementation for NET+OS. + * + * In the NET+OS version a mutex is used for the sync object. + * + * @author AZ + */ +class CTXSyncObject{ + private: + protected: + TX_MUTEX m_stMutex; + public: + CTXSyncObject(); + ~CTXSyncObject(); + /*!\brief Lock the resource coming after the lock command + * + * This function blocks until it will get the lock for the coming critical section. + */ + void lock(void){ + tx_mutex_get(&m_stMutex, TX_WAIT_FOREVER); + //TODO handle return value + }; + //!Freee the resource coming after the lock command + void unlock(void){ + tx_mutex_put(&m_stMutex); + //TODO handle return value + }; +}; + +#endif /*SYNC_H_*/ diff --git a/src/arch/netos/thread.cpp b/src/arch/netos/thread.cpp new file mode 100644 index 000000000..0aa75d653 --- /dev/null +++ b/src/arch/netos/thread.cpp @@ -0,0 +1,147 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "thread.h" + +const char *CTXThread::csm_cName = { "Test Name" }; + +const int CTXThread::scm_nThreadListSize = 27; +TCTXThreadPtr CTXThread::sm_aoThreadList[27] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +bool CTXThread::create(void) { + // Get new Thread + + if (m_stThread.tx_thread_id != 0) + return true; + if (TX_SUCCESS == tx_thread_create(&m_stThread, m_acThreadName, threadFunction, (ULONG)(this), m_cStack, m_nStackSize, scm_nThreadListSize + 3, scm_nThreadListSize + 3, //disable preemption threshhold + TX_NO_TIME_SLICE, //disable timeslicing + TX_AUTO_START))// we start manually + { + tx_thread_sleep(1); + //TODO check return values + return true; + } + else { + DEVLOG_DEBUG("Error while creating thread with ID: %d\n",(int)m_stThread.tx_thread_id); + return false; + } +} + +void CTXThread::threadFunction(ULONG data) { + // Get pointer to CThread object out of void pointer + CTXThread *pThread = (CTXThread*) (data); + // if pointer is ok + if (pThread) { + tx_mutex_get(&(pThread->m_stMutex), TX_WAIT_FOREVER); + pThread->m_bAlive = true; + pThread->run(); + pThread->m_bAlive = false; + tx_mutex_put(&(pThread->m_stMutex)); + } +} + +CTXThread::CTXThread(long pa_nStackSize, char * pa_acThreadName) { + m_bAlive = false; + m_nStackSize = pa_nStackSize; + m_cStack = malloc(m_nStackSize); + m_acThreadName = pa_acThreadName; + memset((void *) &m_stThread, 0, sizeof(m_stThread)); + + tx_mutex_create(&m_stMutex, "test", TX_NO_INHERIT); + tx_semaphore_create(&m_stSemaphore, "hugo", 0); +} + +CTXThread::~CTXThread() { + end(); + tx_mutex_delete(&m_stMutex); + tx_semaphore_delete(&m_stSemaphore); +} + +void CTXThread::setDeadline(const CIEC_TIME &pa_roVal) { + int i; + int ii; + m_oDeadLine = pa_roVal; + //first of all check if this thread is already in the list and remove it from the list + for (i = 0; i < scm_nThreadListSize; i++) { + if (0 == sm_aoThreadList[i]) + break; + else + if (this == sm_aoThreadList[i]) { + for (ii = i; ii < scm_nThreadListSize - 1; ii++) { + if (0 == sm_aoThreadList[ii + 1]) + break; + sm_aoThreadList[ii + 1]->setPriority(ii + 2); + sm_aoThreadList[ii] = sm_aoThreadList[ii + 1]; + } + break; + } + } + + if (0 == m_oDeadLine) + setPriority(scm_nThreadListSize + 2); + else { + for (i = 0; i < scm_nThreadListSize; i++) { + if (0 == sm_aoThreadList[i]) { + sm_aoThreadList[i] = this; + setPriority(i + 2); + break; + } + else + if (m_oDeadLine < sm_aoThreadList[i]->getDeadline()) { + CTXThread *poRBuf, *poSBuf = sm_aoThreadList[i]; + sm_aoThreadList[i] = this; + setPriority(i + 2); + for (ii = i + 1; ii < scm_nThreadListSize; ii++) { + poSBuf->setPriority(ii + 2); + poRBuf = sm_aoThreadList[ii]; + sm_aoThreadList[ii] = poSBuf; + if (0 == poRBuf) + break; + poSBuf = poRBuf; + } + break; + } + } + } +} + +void CTXThread::end(void) { + DEVLOG_INFO("entering end ID: %d\n", (int) m_stThread.tx_thread_id); + m_bAlive = false; + resumeSelfSuspend(); + join(); +} + +void CTXThread::join(void) { + if (0 != m_stThread.tx_thread_id) { + //wait till the thread is up and running + while (!m_bAlive) { + tx_thread_sleep(1); + } + + tx_mutex_get(&m_stMutex, TX_WAIT_FOREVER); + tx_mutex_put(&m_stMutex); + tx_thread_delete(&m_stThread); + m_stThread.tx_thread_id = 0; + } +} + +// function for output of the semaphore status, for debugging +void CTXThread::printseminfo(TX_SEMAPHORE *pa_stSemaphore) { + CHAR *name; + ULONG current_value; + TX_THREAD *first_suspended; + ULONG suspended_count; + TX_SEMAPHORE *next_semaphore; + UINT status; + status = tx_semaphore_info_get(pa_stSemaphore, &name, ¤t_value, &first_suspended, &suspended_count, &next_semaphore); + //DEVLOG_DEBUG_2(cg_nID_CThread, 0x01,"Seminfo: Name : %s, Value : %d, First Susp. Thread: %d, status : %d\n", name, (int)current_value, (int)first_suspended->tx_thread_id, status); +} diff --git a/src/arch/netos/thread.h b/src/arch/netos/thread.h new file mode 100644 index 000000000..e075b182c --- /dev/null +++ b/src/arch/netos/thread.h @@ -0,0 +1,190 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _THREAD_H_ +#define _THREAD_H_ + +#include "../datatype.h" +#include +#include <../devlog.h> +#include +#include +#include +#include "../../core/datatypes/forte_time.h" + +#define CThread CTXThread //allows that doxygen can generate better documenation +class CTXThread; +typedef CTXThread *TCTXThreadPtr; + +/** \ingroup FORTE-HAL + * \defgroup netos_hal NET+OS Hardware Abstraction Layer + * + * \brief The FORTE-HAL implemenation for the NET+OS operating system + * + * + */ + +/*! \ingroup netos_hal + * \brief Multithreading implementation for NET+OS. + * + */ +class CTXThread { + public: + /*! \brief Constructor of the Thread class + * + * Does all the neccessary steps in order to get the thread running with the start()-method + * @param pa_nStackSize the Size of the stack the thread is allowed to use. 0 means use system default stack size. + * @param pa_acThreadName the name of the thread + */ + CTXThread(long pa_nStackSize = 32384, char* pa_acThreadName = "Event Execution Thread"); + + /*! \brief Stops and destroys thread. + * + * Will stop the execution if running and destroy the thread including all system specific data. + */ + virtual ~CTXThread(); + + /*! \brief Indicates if the thread is allowed to execute. + * + * This functions checks if the Thread is still executing user code in its run()-method. + * \return true if there the run method is acitve. + */ + bool isAlive(void) const { + return m_bAlive; + } + + //!Set the deadline of the thread. + void setDeadline(const CIEC_TIME &pa_roVal); + //!Get the current deadline of the thread. + const CIEC_TIME &getDeadline(void) const { + return m_oDeadLine; + } + + /*! \brief starts the Thread + * + * By calling this method the execution in the run()-Method will be started. If necessary additional data + * can be created here. Because of inheritance resons the best place for executing create is in this method. + * For details ask AZ. + */ + void start(void) { + create(); + } + + /*! \brief Resumes a suspended Thread + * + * + */ + void resumeSelfSuspend(void) { + // if the thread is not created yet, we do this here + tx_semaphore_put(&m_stSemaphore); + } + + /*! \brief Stops the execution of the thread + * + * This function imidiatly stops the execution of the thread (seting m_bAlive to false) and waits till + * this is finished. + */ + void end(void); + + /*! \brief Waits for the Thread to finish its execution. + * + * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!! + */ + void join(void); + protected: + + /*! \brief Suspends the thread. + * + * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called. + */ + void selfSuspend(void) { + tx_semaphore_get(&m_stSemaphore, TX_WAIT_FOREVER); + } + + private: + /*!\brief Funciton that is given to the system thread support that should be called for the thread. + * + * this function will call the run method of the thread instance. + */ + static void threadFunction(ULONG data); + + /*! \brief Abstract method for the code to execute in the thread. + * + * This thread class has to provide means that the code a inheriting class will add to the run()-method will + * be executed in a seperated thread regarding the creator of the CThread class. + * + * The inheriting class has to fullfill the folloing rules when using the run method: + * - To end the thread execution simple leave the run()-method + * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the + * execution if isAlive() returns false. + */ + virtual void run() = 0; + + void setPriority(UINT pa_nPriority) { + UINT nOldPrio; + tx_thread_priority_change(&m_stThread, pa_nPriority, &nOldPrio); + } + + /*! \brief Creates a new thread. + * + * With this function all the setup things for a new thread are done. The Thread created is initialy + * suspended and with the start() method the execution of the code in the run() method is started. + */ + bool create(void); + + /*! \brief Destroies the thread + * + * This function destroies all the data structures created in the creation phase. All used memory is freed. + */ + bool destroy(void); + + void printseminfo(TX_SEMAPHORE *pa_stSemaphore); + + //!deadline the thread needs to be finish its execution. 0 means unconstrained. + CIEC_TIME m_oDeadLine; + + /*! \brief data neede for ecos to identify the thread. + */ + TX_THREAD m_stThread; + + TX_MUTEX m_stMutex; //!< used for join function + + TX_SEMAPHORE m_stSemaphore; //!< used for resume/suspend + + /*! \brief Size of the stack used by this thread. + */ + long m_nStackSize; + void *m_cStack; + static const char *csm_cName; + + char *m_acThreadName; + + static const int scm_nThreadListSize; + static TCTXThreadPtr sm_aoThreadList[27]; + + /*! \brief Flag that indicates if the Thread is alive. + * + * This flag has two main purposes: + * -# indicate for other classes if the thread is still executing + * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ). + * This is important for stopping and destroying threads. + */ + bool m_bAlive; + + //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private + //but not implemented + CTXThread(const CTXThread&); + CTXThread& operator = (const CTXThread &); + +}; + +#endif /*THREAD_H_*/ + diff --git a/src/arch/netos/txtimeha.cpp b/src/arch/netos/txtimeha.cpp new file mode 100644 index 000000000..5d65a72d3 --- /dev/null +++ b/src/arch/netos/txtimeha.cpp @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "txtimeha.h" +#include "../../core/devexec.h" + + +void CTimerHandler::createTimerHandler(void){ + if(0 == sm_poFORTETimer) + sm_poFORTETimer = new CTXTimerHandler(); +} + +CTXTimerHandler::CTXTimerHandler(){ +// setup the handler for recieving the timer calls + //TODO handle ticks per second correctly here + UINT status = tx_timer_create(&m_stTimer, "FORTE timer", &timerHandlerFunc, 0, 1, 1, TX_NO_ACTIVATE); + if (status == TX_SUCCESS) + DEVLOG_DEBUG("Timer created\n"); + else + DEVLOG_DEBUG("Error creating timer\n"); + + //TODO handle retval +} + +CTXTimerHandler::~CTXTimerHandler(){ + disableHandler(); + tx_timer_delete(&m_stTimer); +} + +void CTXTimerHandler::enableHandler(void){ + UINT status = tx_timer_activate(&m_stTimer); + if (status == TX_SUCCESS) + DEVLOG_DEBUG("Timer activated\n"); + else + DEVLOG_DEBUG("Error activating timer\n"); + + //TODO handle retval +} + +void CTXTimerHandler::disableHandler(void){ + tx_timer_deactivate(&m_stTimer); + //TODO handle retval +} + +void CTXTimerHandler::setPriority(int pa_nPriority){ +} + +int CTXTimerHandler::getPriority(void) const { + return 0; +} diff --git a/src/arch/netos/txtimeha.h b/src/arch/netos/txtimeha.h new file mode 100644 index 000000000..4f6d4f329 --- /dev/null +++ b/src/arch/netos/txtimeha.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _TXTIMEHA_H_ +#define _TXTIMEHA_H_ + +#include +#include "../timerha.h" +#include "../devlog.h" + +/*! \ingroup netos_hal + * \ingroup EXTEVHAND + * \brief Timerhandler for NET+OS. + * + */ +class CTXTimerHandler : public CTimerHandler{ + public: + virtual ~CTXTimerHandler(); + + /*!\brief Enables this event source + * + */ + virtual void enableHandler(void); + /*!\brief Disable this event source + */ + virtual void disableHandler(void); + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority); + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const; + private: + /*!\brief callback function for the system timer + */ + static void timerHandlerFunc(ULONG data){ + sm_poFORTETimer->nextTick(); + } + ; + + CTXTimerHandler(); + + TX_TIMER m_stTimer; + + friend class CTimerHandler; +}; + +#endif /*PCTIMEHA_H_*/ diff --git a/src/arch/posix/CMakeLists.txt b/src/arch/posix/CMakeLists.txt new file mode 100644 index 000000000..66414356d --- /dev/null +++ b/src/arch/posix/CMakeLists.txt @@ -0,0 +1,55 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Martin Melik Merkumians +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +SET(SOURCE_GROUP ${SOURCE_GROUP}\\posix) + +forte_add_architecture(Posix) + +if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + forte_add_sourcefile_hcpp(thread pctimeha sync) + forte_add_sourcefile_cpp(main.cpp) + + if(FORTE_COM_ETH) + forte_add_sourcefile_hcpp( ../fdselecthand ../bsdsocketinterf) + forte_add_sourcefile_h(../gensockhand.h) + forte_add_sourcefile_h(sockhand.h) + endif(FORTE_COM_ETH) + + forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR}) + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + #forte_add_link_library(pthread) + + forte_add_definition("-W -Wall -Wextra -Woverloaded-virtual -Wconversion -DFORTE_LITTLE_ENDIAN -ggdb") + + set(FORTE_RTTI_AND_EXCEPTIONS FALSE CACHE BOOL "Enable RTTI and Exceptions") + mark_as_advanced(FORTE_RTTI_AND_EXCEPTIONS) + IF(NOT FORTE_RTTI_AND_EXCEPTIONS) + forte_add_definition("-fno-rtti -fno-exceptions") + ENDIF(NOT FORTE_RTTI_AND_EXCEPTIONS) + + + set(FORTE_POSIX_GENERATE_MAP_FILE FALSE CACHE BOOL "Enable the generation of map files") + mark_as_advanced(FORTE_POSIX_GENERATE_MAP_FILE) + IF(FORTE_POSIX_GENERATE_MAP_FILE) + forte_add_link_flags("-Wl,-M -Wl,-Map -Wl,forte.map -Wl,-cref") + ENDIF(FORTE_POSIX_GENERATE_MAP_FILE) + + forte_add_link_library("-lpthread") + + + forte_add_network_layer(SER OFF "ser" CSerCommLayer sercommlayer "Enable Forte serial line communication") + forte_add_network_layer(MUXSER OFF "muxser" CMuxedSerCommLayer muxedsercommlayer "Enable Forte multiplexed serial line communication") + +endif() \ No newline at end of file diff --git a/src/arch/posix/fortealloc.h b/src/arch/posix/fortealloc.h new file mode 100644 index 000000000..eab852529 --- /dev/null +++ b/src/arch/posix/fortealloc.h @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FORTEALLOC_H_ +#define FORTEALLOC_H_ + +//on posix environments we are typically happy with the generic alloc implementation based on malloc and free +#include "../genfortealloc.h" + +#endif /* FORTEALLOC_H_ */ diff --git a/src/arch/posix/main.cpp b/src/arch/posix/main.cpp new file mode 100644 index 000000000..b2402a4ee --- /dev/null +++ b/src/arch/posix/main.cpp @@ -0,0 +1,128 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser, Rene Smodic, + * Martin Melik Merkumians, Ingo Hegny, Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include +#include + +#ifdef CONFIG_POWERLINK_USERSTACK +#include +#endif + +/*!\brief Check if the correct endianess has been configured. + * + * If the right endianess is not set this function will end FORTE. + */ +void checkEndianess(); + +//this keeps away a lot of rtti and exception handling stuff +extern "C" void __cxa_pure_virtual(void){ + //TODO maybe add some reporting here + //Although we should never get here + //if we are here something very very bad has happened e.g., stack overflow or other memory corruption + +} + +RMT_DEV *poDev = 0; + +void endForte(int pa_nSig){ + (void) pa_nSig; + if(0 != poDev){ + poDev->changeFBExecutionState(cg_nMGM_CMD_Kill); + } +} + +/*!\brief Creates the Device-Object + * \param pa_acMGRID A string containing IP and Port like [IP]:[Port] + */ +void createDev(const char *pa_acMGRID){ + + signal(SIGINT, endForte); + signal(SIGTERM, endForte); + signal(SIGHUP, endForte); + +#ifdef CONFIG_POWERLINK_USERSTACK + CEplStackWrapper::eplMainInit(); +#endif + + poDev = new RMT_DEV; + + poDev->setMGR_ID(pa_acMGRID); + poDev->startDevice(); + poDev->MGR.getResourceEventExecution()->joinEventChainExecutionThread(); + delete poDev; +} + +/*!\brief Lists the help for FORTE + * + */ +void listHelp(){ + printf("\nUsage of FORTE:\n"); + printf(" -h\t lists this help.\n"); + printf("\n"); + printf(" -c\t sets the destination for the connection.\n"); + printf(" \t Usage: forte -c :"); + printf("\n"); +} + +int main(int argc, char *arg[]){ + + checkEndianess(); + + DEVLOG_INFO("Memory size CFunctionBlock : %d \n", sizeof(CFunctionBlock)); + DEVLOG_INFO("Memory size CDevice : %d \n", sizeof(CDevice)); + DEVLOG_INFO("Memory size CResource : %d \n", sizeof(CResource)); + DEVLOG_INFO("Memory size CConnection : %d \n", sizeof(CConnection)); + DEVLOG_INFO("Memory size CDataConnection : %d \n", sizeof(CDataConnection)); + DEVLOG_INFO("Memory size CEventConnection : %d \n", sizeof(CEventConnection)); + + DEVLOG_INFO("Memory size int : %d \n", sizeof(int)); + DEVLOG_INFO("Memory size long : %d \n", sizeof(long)); + + DEVLOG_INFO("Memory size int8_t : %d \n", sizeof(int8_t)); + DEVLOG_INFO("Memory size int16_t : %d \n", sizeof(int16_t)); + DEVLOG_INFO("Memory size int32_t : %d \n", sizeof(int32_t)); + DEVLOG_INFO("Memory size int64_t : %d \n", sizeof(int64_t)); + + if(argc <= 1){ //! Default Value (localhost:61499) + createDev("localhost:61499"); + } + else{ + if(strcmp("-c", arg[1]) == 0){ //! sets the destination for the connection + createDev(arg[2]); + } + else{ //! Lists the help for FORTE + listHelp(); + } + } + return 0; +} + +void checkEndianess(){ + int i = 1; + char *p = (char *) &i; + if(p[0] == 1){ + //we are on a little endian platform +#ifdef FORTE_BIG_ENDIAN + DEVLOG_ERROR("Wrong endianess configured! You are on a little endian platform and have configured big endian!\n"); + exit(-1); +#endif + } + else{ + //we are on a big endian platform +#ifdef FORTE_LITTLE_ENDIAN + DEVLOG_ERROR("Wrong endianess configured! You are on a big endian platform and have configured little endian!\n"); + exit(-1); +#endif + } +} + diff --git a/src/arch/posix/muxedsercommlayer.cpp b/src/arch/posix/muxedsercommlayer.cpp new file mode 100644 index 000000000..b8e30d49f --- /dev/null +++ b/src/arch/posix/muxedsercommlayer.cpp @@ -0,0 +1,264 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "muxedsercommlayer.h" +#include "commfb.h" +#include "../devlog.h" +#include +#include +#include +#include +#include +#include + +using namespace forte::com_infra; + +CMuxedSerCommLayer::CMuxedSerPortsManager CMuxedSerCommLayer::sm_oMuxedSerPortsManager; + +CMuxedSerCommLayer::CMuxedSerCommLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB) : + CComLayer(pa_poUpperLayer, pa_poFB), m_unBufFillSize(0){ + +} + +CMuxedSerCommLayer::~CMuxedSerCommLayer(){ + closeConnection(); +} + +void CMuxedSerCommLayer::closeConnection(){ + if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){ + sm_oMuxedSerPortsManager.removeMuxedSerLayer(m_nFD, this); + m_nFD = CFDSelectHandler::scm_nInvalidFileDescriptor; + } +} + +EComResponse CMuxedSerCommLayer::sendData(void *pa_pvData, unsigned int pa_unSize){ + if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){ + //first send id + + m_acRecvBuffer[0] = m_unSerMuxId; + memcpy(&(m_acRecvBuffer[1]), pa_pvData, pa_unSize); + pa_unSize++; + + ssize_t nSentBytes; + ssize_t nToSend = pa_unSize; + while(0 < nToSend){ + nSentBytes = write(m_nFD, &(m_acRecvBuffer[0]), nToSend); + if(nSentBytes <= 0){ + DEVLOG_ERROR("CMuxedSerCommLayer: Send failed: %s\n", strerror(errno)); + return e_ProcessDataSendFailed; + } + nToSend -= nSentBytes; + pa_pvData = static_cast(pa_pvData) + nSentBytes; + } + } + + return e_ProcessDataOk; +} + +EComResponse CMuxedSerCommLayer::recvData(const void *, unsigned int){ + ssize_t nReadCount = read(m_nFD, &m_acRecvBuffer[m_unBufFillSize], cg_unIPLayerRecvBufferSize - m_unBufFillSize); + + switch (nReadCount){ + case 0: + DEVLOG_INFO("CMuxedSerCommLayer: Connection closed by peer\n"); + m_eInterruptResp = e_InitTerminated; + closeConnection(); + break; + case -1: + DEVLOG_ERROR("CMuxedSerCommLayer: read failed: %s\n", strerror(errno)); + m_eInterruptResp = e_ProcessDataRecvFaild; + break; + default: + //we successfully received data + m_unBufFillSize += nReadCount; + m_eInterruptResp = e_ProcessDataOk; + break; + } + + m_poFb->interruptCommFB(this); + return m_eInterruptResp; +} + +EComResponse CMuxedSerCommLayer::processInterrupt(){ + if(e_ProcessDataOk == m_eInterruptResp){ + m_eInterruptResp = m_poTopLayer->recvData(m_acRecvBuffer, m_unBufFillSize); + m_unBufFillSize = 0; + } + return m_eInterruptResp; +} + +EComResponse CMuxedSerCommLayer::openConnection(char *pa_acLayerParameter){ + EComResponse eRetVal = e_InitInvalidId; + + char *acPort = strchr(pa_acLayerParameter, ':'); + if(0 != acPort){ + *acPort = '\0'; + ++acPort; + m_unSerMuxId = static_cast(forte::core::util::strtoul(acPort, 0, 10)); + m_nFD = sm_oMuxedSerPortsManager.addMuxedSerLayer(pa_acLayerParameter, this); + if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){ + eRetVal = e_InitOk; + } + } + + return eRetVal; +} + +//************************************************************************************************************************** +CMuxedSerCommLayer::CMuxedSerPortsManager::CMuxedSerPortsManager(){ + +} + +CFDSelectHandler::TFileDescriptor CMuxedSerCommLayer::CMuxedSerPortsManager::addMuxedSerLayer(char* pa_acSerPort, CMuxedSerCommLayer *pa_poComCallBack){ + CCriticalRegion criticalRegion(m_oSync); + CFDSelectHandler::TFileDescriptor nRetVal = CFDSelectHandler::scm_nInvalidFileDescriptor; + SSerPortEntry *m_pstSerPortEntry = getSerPortEntry(pa_acSerPort); + if(0 != m_pstSerPortEntry){ + m_pstSerPortEntry->m_lstConnectionsList.push_back(pa_poComCallBack); + nRetVal = m_pstSerPortEntry->m_nFD; + } + return nRetVal; +} + +void CMuxedSerCommLayer::CMuxedSerPortsManager::removeMuxedSerLayer(CFDSelectHandler::TFileDescriptor m_nFD, CMuxedSerCommLayer *pa_poComCallBack){ + CCriticalRegion criticalRegion(m_oSync); + SSerPortEntry *m_pstSerPortEntry = getOpendSerPortEntry(m_nFD); + if(0 != m_pstSerPortEntry){ + TConnectionContainer::Iterator itRunner(m_pstSerPortEntry->m_lstConnectionsList.begin()); + TConnectionContainer::Iterator itRevNode(m_pstSerPortEntry->m_lstConnectionsList.end()); + TConnectionContainer::Iterator itEnd(m_pstSerPortEntry->m_lstConnectionsList.end()); + + while(itRunner != itEnd){ + if((*itRunner) == pa_poComCallBack){ + if(itRevNode == itEnd){ + m_pstSerPortEntry->m_lstConnectionsList.pop_front(); + }else{ + m_pstSerPortEntry->m_lstConnectionsList.eraseAfter(itRevNode); + } + break; + } + + itRevNode = itRunner; + ++itRunner; + } + + if(m_pstSerPortEntry->m_lstConnectionsList.isEmpty()){ + closePort(m_pstSerPortEntry); + } + } +} + +EComResponse CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry::recvData(const void *, unsigned int){ + EComResponse eRetVal = e_Nothing; + char nID; + + ssize_t nReadCount = read(m_nFD, &nID, 1); + + if(1 == nReadCount){ + + TConnectionContainer::Iterator itEnd(m_lstConnectionsList.end()); + for(TConnectionContainer::Iterator itRunner = m_lstConnectionsList.begin(), itCurrent = m_lstConnectionsList.begin(); itRunner != itEnd;){ + itCurrent = itRunner; + ++itRunner; + if(nID == itCurrent->getSerMuxId()){ + eRetVal = itCurrent->recvData(0,0); + if(e_Nothing != eRetVal){ + m_poFb = itCurrent->getCommFB(); + } + break; + } + } + } + else{ + //FIXME handle error close connections and inform FBs + } + + return eRetVal; +} + +EComResponse CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry::processInterrupt(){ + return e_Nothing; +} + +CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry *CMuxedSerCommLayer::CMuxedSerPortsManager::getSerPortEntry(char* pa_acSerPort){ + for(TSerPortList::Iterator itRunner = m_lstPortList.begin(); itRunner != m_lstPortList.end(); ++itRunner){ + if(0 == strcmp(itRunner->m_acSerPort, pa_acSerPort)){ + return &(*itRunner); + } + } + + TSerPortList::Iterator itRef(m_lstPortList.back()); +//this port is not yet managed by us + m_lstPortList.push_back(SSerPortEntry()); + TSerPortList::Iterator itCurrent(m_lstPortList.back()); + SSerPortEntry *pstRetVal = &(*itCurrent); + openPort(pa_acSerPort, pstRetVal); + if(CFDSelectHandler::scm_nInvalidFileDescriptor == pstRetVal->m_nFD){ + if(itCurrent == m_lstPortList.begin()){ + m_lstPortList.pop_front(); + } + else{ + m_lstPortList.eraseAfter(itRef); + } + pstRetVal = 0; + } + else{ + pstRetVal->m_acSerPort = new char[strlen(pa_acSerPort) + 1]; + strcpy(pstRetVal->m_acSerPort, pa_acSerPort); + } + return pstRetVal; +} + +CMuxedSerCommLayer::CMuxedSerPortsManager::SSerPortEntry *CMuxedSerCommLayer::CMuxedSerPortsManager::getOpendSerPortEntry(CFDSelectHandler::TFileDescriptor pa_nFD){ + SSerPortEntry *pstRetVal = 0; + for(TSerPortList::Iterator itRunner = m_lstPortList.begin(); itRunner != m_lstPortList.end(); ++itRunner){ + if(pa_nFD == itRunner->m_nFD){ + pstRetVal = &(*itRunner); + break; + } + } + return pstRetVal; +} + +void CMuxedSerCommLayer::CMuxedSerPortsManager::openPort(char* pa_acSerPort, SSerPortEntry *pa_pstPortEntry){ + pa_pstPortEntry->m_nFD = open(pa_acSerPort, O_RDWR | O_NOCTTY); + + if(CFDSelectHandler::scm_nInvalidFileDescriptor != pa_pstPortEntry->m_nFD){ + CFDSelectHandler::getInstance().addComCallback(pa_pstPortEntry->m_nFD, pa_pstPortEntry); + } + else{ + DEVLOG_ERROR("CSerCommLayer: open failed: %s\n", strerror(errno)); + } +} + +void CMuxedSerCommLayer::CMuxedSerPortsManager::closePort(SSerPortEntry *pa_pstSerPortEntry){ + CFDSelectHandler::getInstance().removeComCallback(pa_pstSerPortEntry->m_nFD); + close(pa_pstSerPortEntry->m_nFD); + + delete[] pa_pstSerPortEntry->m_acSerPort; + + TSerPortList::Iterator itRunner(m_lstPortList.begin()); + TSerPortList::Iterator itRefNode(m_lstPortList.end()); + + while(itRunner != m_lstPortList.end()){ + if(itRunner->m_nFD == pa_pstSerPortEntry->m_nFD){ + if(itRefNode == m_lstPortList.end()){ + m_lstPortList.pop_front(); + } + else{ + m_lstPortList.eraseAfter(itRefNode); + } + break; + } + + itRefNode = itRunner; + ++itRunner; + } +} diff --git a/src/arch/posix/muxedsercommlayer.h b/src/arch/posix/muxedsercommlayer.h new file mode 100644 index 000000000..aa62eb997 --- /dev/null +++ b/src/arch/posix/muxedsercommlayer.h @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2012, 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _MUXEDSERCOMMLAYER_H_ +#define _MUXEDSERCOMMLAYER_H_ + +#include "comlayer.h" +#include "fdselecthand.h" + +class CMuxedSerCommLayer : public forte::com_infra::CComLayer{ + public: + CMuxedSerCommLayer(forte::com_infra::CComLayer* pa_poUpperLayer, forte::com_infra::CCommFB * pa_poFB); + virtual ~CMuxedSerCommLayer(); + + virtual void closeConnection(); + virtual forte::com_infra::EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); + virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + + virtual forte::com_infra::EComResponse processInterrupt(); + + TForteUInt8 getSerMuxId() const{ + return m_unSerMuxId; + } + + protected: + private: + virtual forte::com_infra::EComResponse openConnection(char *pa_acLayerParameter); + + forte::com_infra::EComResponse m_eInterruptResp; + char m_acRecvBuffer[cg_unIPLayerRecvBufferSize]; + unsigned int m_unBufFillSize; + TForteUInt8 m_unSerMuxId; + CFDSelectHandler::TFileDescriptor m_nFD; //!< file descriptor for accessing the serial device + + class CMuxedSerPortsManager{ + + public: + + CFDSelectHandler::TFileDescriptor addMuxedSerLayer(char* pa_acSerPort, CMuxedSerCommLayer *pa_poComCallBack); + void removeMuxedSerLayer(CFDSelectHandler::TFileDescriptor m_nFD, CMuxedSerCommLayer *pa_poComCallBack); + + private: + + typedef CSinglyLinkedList TConnectionContainer; + class SSerPortEntry : public forte::com_infra::CComLayer{ + public: + SSerPortEntry(): forte::com_infra::CComLayer(0, 0){ + } + + char* m_acSerPort; + CFDSelectHandler::TFileDescriptor m_nFD; + TConnectionContainer m_lstConnectionsList; + + virtual void closeConnection(){} + + virtual forte::com_infra::EComResponse sendData(void *, unsigned int ){ + return forte::com_infra::e_Nothing; + } + + virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + virtual forte::com_infra::EComResponse processInterrupt(); + + private: + virtual forte::com_infra::EComResponse openConnection(char *){ + return forte::com_infra::e_Nothing; + } + }; + + typedef CSinglyLinkedList TSerPortList; + + CMuxedSerPortsManager(); + SSerPortEntry *getSerPortEntry(char* pa_acSerPort); + SSerPortEntry *getOpendSerPortEntry(CFDSelectHandler::TFileDescriptor pa_nFD); + void openPort(char* pa_acSerPort, SSerPortEntry *pa_pstPortEntry); + void closePort(SSerPortEntry *pa_pstSerPortEntry); + + TSerPortList m_lstPortList; + + CSyncObject m_oSync; + + //needed so that CLMSUSBLayer can have a static member variable holding the manager. + friend class CMuxedSerCommLayer; + + //not to be implemented + CMuxedSerPortsManager(const CMuxedSerPortsManager &); + CMuxedSerPortsManager &operator =(const CMuxedSerPortsManager&); + }; + + static CMuxedSerPortsManager sm_oMuxedSerPortsManager; +}; + +#endif /* MUXEDSERCOMMLAYER_H_ */ diff --git a/src/arch/posix/pctimeha.cpp b/src/arch/posix/pctimeha.cpp new file mode 100644 index 000000000..1b1a2c6e3 --- /dev/null +++ b/src/arch/posix/pctimeha.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "pctimeha.h" +#include "../../core/devexec.h" +#include +#include + +void CTimerHandler::createTimerHandler(void){ + if(0 == sm_poFORTETimer) + sm_poFORTETimer = new CPCTimerHandler(); +} + +CPCTimerHandler::CPCTimerHandler(){ +} + +CPCTimerHandler::~CPCTimerHandler(){ + disableHandler(); +} + +void CPCTimerHandler::run(){ + struct timespec stReq; + stReq.tv_sec = 0; + stReq.tv_nsec = (1000000 / getTicksPerSecond()) * 1000; + + struct timeval stOldTime; + struct timeval stNewTime; + struct timeval stReqTime; + // Timer interval is 1ms + stReqTime.tv_sec = 0; + stReqTime.tv_usec = (1000 / getTicksPerSecond()) * 1000; + struct timeval stDiffTime; + struct timeval stRemainingTime; + timerclear(&stRemainingTime); + + gettimeofday(&stOldTime, 0); + while(isAlive()){ + + nanosleep(&stReq, NULL); + + gettimeofday(&stNewTime, 0); + + timersub(&stNewTime, &stOldTime, &stDiffTime); + + timeradd(&stRemainingTime, &stDiffTime, &stRemainingTime); + + while(!timercmp(&stRemainingTime, &stReqTime, <)){ + nextTick(); + timersub(&stRemainingTime, &stReqTime, &stRemainingTime); + } + stOldTime = stNewTime; // in c++ this should work fine + } +} + +void CPCTimerHandler::enableHandler(void){ + start(); +} + +void CPCTimerHandler::disableHandler(void){ + end(); +} + +void CPCTimerHandler::setPriority(int ){ + //TODO think on hwo to handle this. +} + +int CPCTimerHandler::getPriority(void) const { + //TODO think on hwo to handle this. + return 1; +} diff --git a/src/arch/posix/pctimeha.h b/src/arch/posix/pctimeha.h new file mode 100644 index 000000000..851f8f8cd --- /dev/null +++ b/src/arch/posix/pctimeha.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _PCTIMEHA_H_ +#define _PCTIMEHA_H_ + +#include "thread.h" +#include "../timerha.h" + +/*! \ingroup posix_hal + *\ingroup EXTEVHAND + *\brief the timer handler for the pc architecture. + */ +class CPCTimerHandler : public CTimerHandler, private CThread{ + public: + virtual ~CPCTimerHandler(); + + virtual void run(); + + /*!\brief Enables this event source + * + */ + virtual void enableHandler(void); + /*!\brief Disable this event source + */ + virtual void disableHandler(void); + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority); + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const; + private: + CPCTimerHandler(); + + friend class CTimerHandler; + +}; + +#endif /*PCTIMEHA_H_*/ diff --git a/src/arch/posix/sercommlayer.cpp b/src/arch/posix/sercommlayer.cpp new file mode 100644 index 000000000..1bad94298 --- /dev/null +++ b/src/arch/posix/sercommlayer.cpp @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2012, 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "sercommlayer.h" +#include "commfb.h" +#include "../devlog.h" +#include +#include +#include +#include +#include +#include + +using namespace forte::com_infra; + +CSerCommLayer::CSerCommLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB) : + CComLayer(pa_poUpperLayer, pa_poFB), m_nFD(CFDSelectHandler::scm_nInvalidFileDescriptor), m_unBufFillSize(0){ + +} + +CSerCommLayer::~CSerCommLayer(){ + closeConnection(); +} + +void CSerCommLayer::closeConnection(){ + if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){ + CFDSelectHandler::getInstance().removeComCallback(m_nFD); + tcsetattr(m_nFD, TCSANOW, &m_stOldTIO); + close(m_nFD); + m_nFD = CFDSelectHandler::scm_nInvalidFileDescriptor; + } +} + +forte::com_infra::EComResponse CSerCommLayer::sendData(void *pa_pvData, unsigned int pa_unSize){ + if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){ + ssize_t nSentBytes; + ssize_t nToSend = pa_unSize; + while(0 < nToSend){ + nSentBytes = write(m_nFD, pa_pvData, nToSend); + if(nSentBytes <= 0){ + DEVLOG_ERROR("CSerCommLayer: Send failed: %s\n", strerror(errno)); + return e_ProcessDataSendFailed; + } + nToSend -= nSentBytes; + pa_pvData = static_cast(pa_pvData) + nSentBytes; + } + } + + return e_ProcessDataOk; +} + +forte::com_infra::EComResponse CSerCommLayer::recvData(const void *, unsigned int){ + ssize_t nReadCount = read(m_nFD, &m_acRecvBuffer[m_unBufFillSize], cg_unIPLayerRecvBufferSize - m_unBufFillSize); + + switch (nReadCount){ + case 0: + DEVLOG_INFO("Connection closed by peer\n"); + m_eInterruptResp = e_InitTerminated; + closeConnection(); + break; + case -1: + DEVLOG_ERROR("CSerCommLayer: read failed: %s\n", strerror(errno)); + m_eInterruptResp = e_ProcessDataRecvFaild; + break; + default: + //we successfully received data + m_unBufFillSize += nReadCount; + m_eInterruptResp = e_ProcessDataOk; + break; + } + + m_poFb->interruptCommFB(this); + return m_eInterruptResp; +} + +forte::com_infra::EComResponse CSerCommLayer::processInterrupt(){ + if(e_ProcessDataOk == m_eInterruptResp){ + m_eInterruptResp = m_poTopLayer->recvData(m_acRecvBuffer, m_unBufFillSize); + m_unBufFillSize = 0; + } + return m_eInterruptResp; +} + +forte::com_infra::EComResponse CSerCommLayer::openConnection(char *pa_acLayerParameter){ + EComResponse eRetVal = e_InitInvalidId; + + //as first shot take the serial interface device as param (e.g., /dev/ttyS0 ) + m_nFD = open(pa_acLayerParameter, O_RDWR | O_NOCTTY); + + if(CFDSelectHandler::scm_nInvalidFileDescriptor != m_nFD){ + tcgetattr(m_nFD, &m_stOldTIO); + struct termios stNewTIO; + memset(&stNewTIO, 0, sizeof(stNewTIO)); + + //TODO make more of these flags setable by the user, current baudrate is suitable for lms usb serial communication + stNewTIO.c_cflag = B115200 | CS8 | CLOCAL | CREAD; + + stNewTIO.c_iflag = IGNPAR | ICRNL; + + stNewTIO.c_oflag = 0; //raw output + + stNewTIO.c_lflag = ICANON; // enable canonical input, disable echo func and don't send signals to calling programm + + stNewTIO.c_cc[VINTR] = 0; /* Ctrl-c */ + stNewTIO.c_cc[VQUIT] = 0; /* Ctrl-\ */ + stNewTIO.c_cc[VERASE] = 0; /* del */ + stNewTIO.c_cc[VKILL] = 0; /* @ */ + stNewTIO.c_cc[VEOF] = 4; /* Ctrl-d */ + stNewTIO.c_cc[VTIME] = 0; /* inter-character timer unused */ + stNewTIO.c_cc[VMIN] = 1; /* blocking read until 1 character arrives */ + stNewTIO.c_cc[VSWTC] = 0; /* '\0' */ + stNewTIO.c_cc[VSTART] = 0; /* Ctrl-q */ + stNewTIO.c_cc[VSTOP] = 0; /* Ctrl-s */ + stNewTIO.c_cc[VSUSP] = 0; /* Ctrl-z */ + stNewTIO.c_cc[VEOL] = 0; /* '\0' */ + stNewTIO.c_cc[VREPRINT] = 0; /* Ctrl-r */ + stNewTIO.c_cc[VDISCARD] = 0; /* Ctrl-u */ + stNewTIO.c_cc[VWERASE] = 0; /* Ctrl-w */ + stNewTIO.c_cc[VLNEXT] = 0; /* Ctrl-v */ + stNewTIO.c_cc[VEOL2] = 0; /* '\0' */ + + tcflush(m_nFD, TCIFLUSH); + tcsetattr(m_nFD, TCSANOW, &stNewTIO); + + CFDSelectHandler::getInstance().addComCallback(m_nFD, this); + eRetVal = e_InitOk; + + } + else{ + DEVLOG_ERROR("CSerCommLayer: open failed: %s\n", strerror(errno)); + } + + return eRetVal; +} + diff --git a/src/arch/posix/sercommlayer.h b/src/arch/posix/sercommlayer.h new file mode 100644 index 000000000..fe6da0a00 --- /dev/null +++ b/src/arch/posix/sercommlayer.h @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2012, 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SERCOMMLAYER_H_ +#define _SERCOMMLAYER_H_ + +#include "comlayer.h" +#include "../fdselecthand.h" +#include + +class CSerCommLayer : public forte::com_infra::CComLayer{ + public: + CSerCommLayer(forte::com_infra::CComLayer* pa_poUpperLayer, forte::com_infra::CCommFB * pa_poFB); + virtual ~CSerCommLayer(); + + virtual void closeConnection(); + virtual forte::com_infra::EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); + virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + + virtual forte::com_infra::EComResponse processInterrupt(); + + protected: + private: + virtual forte::com_infra::EComResponse openConnection(char *pa_acLayerParameter); + + CFDSelectHandler::TFileDescriptor m_nFD; //!< file descriptor for accessing the serial device + + forte::com_infra::EComResponse m_eInterruptResp; + char m_acRecvBuffer[cg_unIPLayerRecvBufferSize]; + unsigned int m_unBufFillSize; + struct termios m_stOldTIO; //!< buffer for the existing sercom settings + +}; + +#endif /* CSERCOMMLAYER_H_ */ diff --git a/src/arch/posix/sockhand.h b/src/arch/posix/sockhand.h new file mode 100644 index 000000000..2df95e2f1 --- /dev/null +++ b/src/arch/posix/sockhand.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef SOCKHAND_H_ +#define SOCKHAND_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +//these include needs to be last +#include "../fdselecthand.h" +#include "../bsdsocketinterf.h" +#include "../gensockhand.h" + +typedef CGenericIPComSocketHandler CIPComSocketHandler; + +#endif /* SOCKHAND_H_ */ diff --git a/src/arch/posix/sync.cpp b/src/arch/posix/sync.cpp new file mode 100644 index 000000000..90efbf665 --- /dev/null +++ b/src/arch/posix/sync.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "sync.h" + +CPCSyncObject::CPCSyncObject(){ +// m_oMutexHandle = PTHREAD_MUTEX_INITIALIZER; + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + + #ifdef __CYGWIN__ + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + #else + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); + #endif + + pthread_mutex_init(&m_oMutexHandle, &attr); + //TODO handle return value + pthread_mutexattr_destroy(&attr); +} + +CPCSyncObject::~CPCSyncObject(){ + pthread_mutex_destroy(&m_oMutexHandle); + //TODO handle return value +} diff --git a/src/arch/posix/sync.h b/src/arch/posix/sync.h new file mode 100644 index 000000000..b8faa9717 --- /dev/null +++ b/src/arch/posix/sync.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SYNC_H_ +#define _SYNC_H_ + +#include + +#define CSyncObject CPCSyncObject //allows that doxygen can generate better documenation + + +/*! \ingroup posix_hal + * \brief The sync object implementation for the posix thread interface. + * + * In the posix version a mutex is used for the sync object. + * + */ + +class CPCSyncObject{ + private: + protected: + //! The posix thread mutex handle of the operating system. + pthread_mutex_t m_oMutexHandle; + public: + CPCSyncObject(); + ~CPCSyncObject(); + /*!\brief Lock the resource coming after the lock command + * + * This function blocks until it will get the lock for the coming critical section. + */ + void lock(void){ + pthread_mutex_lock(&m_oMutexHandle); + //TODO handle return value + }; + //!Freee the resource coming after the lock command + void unlock(void){ + pthread_mutex_unlock(&m_oMutexHandle); + //TODO handle return value + }; +}; + +#endif /*SYNC_H_*/ diff --git a/src/arch/posix/thread.cpp b/src/arch/posix/thread.cpp new file mode 100644 index 000000000..ec064dfbc --- /dev/null +++ b/src/arch/posix/thread.cpp @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Martin Melik Merkiumians - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "thread.h" +#include "../devlog.h" +#include +#include +#include +#include +#include +#include + +void CPosixThread::start(void){ + // Get new Thread + if(0 == m_stThreadID){ + + //If the stackSize is not 0 we have to set it + if(m_nStackSize){ + pthread_attr_t stAttr; + + if(pthread_attr_init(&stAttr)){ + DEVLOG_ERROR("Error could not get the default thread attributes! %s\n", strerror(errno)); + return; + } + #ifdef __CYGWIN__ + if (pthread_attr_setstacksize (&stAttr, m_nStackSize)){ + DEVLOG_ERROR("Error could not set the stacksize for the thread! %s\n", strerror(errno)); + return; + } + #else + //if (pthread_attr_setstacksize(&stAttr, m_nStackSize)) { + if(pthread_attr_setstack(&stAttr, m_pacStack, m_nStackSize)){ + DEVLOG_ERROR("Error could not set the stacksize for the thread! %s\n", strerror(errno)); + return; + } + #endif + if(pthread_create(&m_stThreadID, &stAttr, threadFunction, this)){ + DEVLOG_ERROR("Error could not create the thread! %s\n", strerror(errno)); + return; + } + if(pthread_attr_destroy(&stAttr)){ + DEVLOG_ERROR("Error could not free the thread attributes! %s\n", strerror(errno)); + return; + } + } + else{ + if(pthread_create(&m_stThreadID, NULL, threadFunction, this)){ + DEVLOG_ERROR("Error could not create the thread! %s\n", strerror(errno)); + return; + } + } + } + //wait till the thread is up and running + do{ + //pthread_yield(); + sleep(1); + }while(!isAlive()); +} + +void * CPosixThread::threadFunction(void *arguments){ + // Get pointer to CThread object out of void pointer + CPosixThread *pThread = (CPosixThread *) arguments; + + // if pointer is ok + if(0 != pThread){ + CCriticalRegion criticalRegion(pThread->mJoinMutex); + pThread->m_bAlive = true; + pThread->run(); + pThread->m_bAlive = false; + pThread->m_stThreadID = 0; + } + else{ + DEVLOG_ERROR("pThread pointer is 0!"); + } + return 0; +} + +CPosixThread::CPosixThread(long pa_nStackSize) : + m_bAlive(false), m_stThreadID(0), m_nStackSize(pa_nStackSize), m_pacStack(0){ + + if(0 != m_nStackSize){ + m_pacStack = new char[m_nStackSize]; + } + + if(-1 == sem_init(&m_stSuspendSemaphore, 0, 0)){ + DEVLOG_ERROR("Could not initialize suspend sempaphore: %s\n", strerror(errno)); + } +} + +CPosixThread::~CPosixThread(){ + if(0 != m_stThreadID){ + end(); + } + if(0 != m_nStackSize){ + delete[] m_pacStack; + } + sem_destroy(&m_stSuspendSemaphore); +} + +void CPosixThread::setDeadline(const CIEC_TIME &pa_roVal){ + m_oDeadline = pa_roVal; + //under the posix pthread implemention currently it makes no sense to set any priority. + //It will not be considered. +} + +void CPosixThread::resumeSelfSuspend(void){ + sem_post(&m_stSuspendSemaphore); +} + +void CPosixThread::join(void){ + if(0 != m_stThreadID){ + CCriticalRegion criticalRegion(mJoinMutex); + } +} + +void CPosixThread::selfSuspend(void) { + int n; + do{ + n = sem_wait(&m_stSuspendSemaphore); + }while( (-1 == n) && (errno == EINTR) ); //handle interrupts from signals +} diff --git a/src/arch/posix/thread.h b/src/arch/posix/thread.h new file mode 100644 index 000000000..f9c8798bd --- /dev/null +++ b/src/arch/posix/thread.h @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Ingo Hegny, Martin Melik Merkiumians - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _THREAD_H_ +#define _THREAD_H_ + +#include +#include +#include "../datatype.h" +#include "../../core/datatypes/forte_time.h" +#include + +/** \ingroup FORTE-HAL + * \defgroup posix_hal PC FORTE Hardware Abstraction Layer + * + * \brief The FORTE-HAL implementation for normal PCs + * + * It will mainly work under linux or linux similar environments like cygwin. + */ + +/*! \ingroup posix_hal + * \brief The thread implementation for the posix thread interface. + */ +class CPosixThread { + public: + /*! \brief Constructor of the Thread class + * + * Does all the necessary steps in order to get the thread running with the start()-method + * @param pa_nStackSize the Size of the stack the thread is allowed to use. 0 means use system default stack size. + * If you like to set this value it is best to use the form: PTHREAD_STACK_MIN + additional bytes you need. + */ + CPosixThread(long pa_nStackSize = 0); + + /*! \brief Stops and destroys thread. + * + * Will stop the execution if running and destroy the thread including all system specific data. + */ + virtual ~CPosixThread(); + + /*! \brief Indicates if the thread is allowed to execute. + * + * This functions checks if the Thread is still executing user code in its run()-method. + * \return true if there the run method is active. + */ + bool isAlive(void) const { + return m_bAlive; + } + //!Set the deadline of the thread. + void setDeadline(const CIEC_TIME &pa_roVal); + + //!Get the current deadline of the thread. + const CIEC_TIME &getDeadline(void) const { + return m_oDeadline; + } + + /*! \brief starts the Thread + * + * By calling this method the execution in the run()-Method will be started. + */ + void start(void); + + /*! \brief Resumes a suspended Thread + * + * + */ + void resumeSelfSuspend(void); + + /*! \brief Stops the execution of the thread + * + * This function immediately stops the execution of the thread (setting m_bAlive to false) and waits till + * this is finished. + */ + void end(void){ + m_bAlive = false; + resumeSelfSuspend(); + join(); + } + + /*! \brief Waits for the Thread to finish its execution. + * + * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!! + */ + void join(void); // Waits + protected: + /*! \brief Suspends the thread. + * + * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called. + */ + void selfSuspend(); + + void setAlive(bool paAlive){ + m_bAlive = paAlive; + } + + private: + /*!\brief Function that is given to the system thread support that should be called for the thread. + * + * this function will call the run method of the thread instance. + */ + static void * threadFunction(void *arguments); + + /*! \brief Abstract method for the code to execute in the thread. + * + * This thread class has to provide means that the code a inheriting class will add to the run()-method will + * be executed in a separated thread regarding the creator of the CThread class. + * + * The inheriting class has to fulfill the following rules when using the run method: + * - To end the thread execution simple leave the run()-method + * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the + * execution if isAlive() returns false. + */ + virtual void run() = 0; + + /*! \brief Flag that indicates if the Thread is alive. + * + * This flag has two main purposes: + * -# indicate for other classes if the thread is still executing + * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ). + * This is important for stopping and destroying threads. + */ + bool m_bAlive; + + //!deadline the thread needs to be finish its execution. 0 means unconstrained. + CIEC_TIME m_oDeadline; + + sem_t m_stSuspendSemaphore; + + CPCSyncObject mJoinMutex; + + /*! \brief data needed for posix scheduling system to identify the thread. + */ + pthread_t m_stThreadID; + /*! \brief Size of the stack used by this thread. + */ + long m_nStackSize; + + /*! \brief Pointer to the memory to be used for this thread'm_stSuspendSemaphore stack + * + * This pointer is only not 0 if m_nStackSize is not 0 + */ + char *m_pacStack; + + //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private + //but not implemented + CPosixThread(const CPosixThread&); + CPosixThread& operator = (const CPosixThread &); + +}; + + +typedef CPosixThread CThread; //allows that doxygen can generate better documentation + +#endif /*THREAD_H_*/ + diff --git a/src/arch/timerha.cpp b/src/arch/timerha.cpp new file mode 100644 index 000000000..67052f93a --- /dev/null +++ b/src/arch/timerha.cpp @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Thomas Strasser, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "timerha.h" +#include "../core/devexec.h" +#include "../core/esfb.h" +#include + +CTimerHandler *CTimerHandler::sm_poFORTETimer = 0; + +void CTimerHandler::registerTimedFB(STimedFBListEntry *pa_pstTimerListEntry, const CIEC_TIME &pa_roTimeInterval) { + //calculate the correct interval based on time-base and timer ticks per seconds + pa_pstTimerListEntry->m_nInterval = static_cast((pa_roTimeInterval * getTicksPerSecond()) / FORTE_TIME_BASE_UNITS_PER_SECOND); + { + CCriticalRegion criticalRegion(m_oSync); + addTimedFBEntry(pa_pstTimerListEntry); + } +} + +void CTimerHandler::addTimedFBEntry(STimedFBListEntry *pa_pstTimerListEntry) { + pa_pstTimerListEntry->m_stTimeOut = m_stForteTime; + pa_pstTimerListEntry->m_stTimeOut += pa_pstTimerListEntry->m_nInterval; // the next activationtime of this FB + pa_pstTimerListEntry->m_pstNext = 0; + + // Correct null intervals that can lead to event queue overflow to 10 ms + if (pa_pstTimerListEntry->m_nInterval == 0) + pa_pstTimerListEntry->m_stTimeOut += getTicksPerSecond() > 100 ? getTicksPerSecond() / 100 : 1; + + if (0 == m_pstTimedFBList) { + m_pstTimedFBList = pa_pstTimerListEntry; + } else { + if (m_pstTimedFBList->m_stTimeOut > pa_pstTimerListEntry->m_stTimeOut) { + pa_pstTimerListEntry->m_pstNext = m_pstTimedFBList; + m_pstTimedFBList = pa_pstTimerListEntry; + } else { + STimedFBListEntry *runner = m_pstTimedFBList; + while (0 != runner->m_pstNext) { + if (runner->m_pstNext->m_stTimeOut > pa_pstTimerListEntry->m_stTimeOut) { + pa_pstTimerListEntry->m_pstNext = runner->m_pstNext; + runner->m_pstNext = pa_pstTimerListEntry; + break; + } + runner = runner->m_pstNext; + } + runner->m_pstNext = pa_pstTimerListEntry; + } + } +} + +void CTimerHandler::unregisterTimedFB(CEventSourceFB *pa_poTimedFB) { + CCriticalRegion criticalRegion(m_oSync); + STimedFBListEntry *buffer = 0; + if (0 != m_pstTimedFBList) { + if (m_pstTimedFBList->m_poTimedFB == pa_poTimedFB) { + buffer = m_pstTimedFBList; + m_pstTimedFBList = m_pstTimedFBList->m_pstNext; + buffer->m_pstNext = 0; + buffer->m_stTimeOut.m_nLowerValue = 0; + buffer->m_stTimeOut.m_nUpperValue = 0; + } else { + STimedFBListEntry *runner = m_pstTimedFBList; + while (0 != runner->m_pstNext) { + if (runner->m_pstNext->m_poTimedFB == pa_poTimedFB) { + buffer = runner->m_pstNext; + runner->m_pstNext = runner->m_pstNext->m_pstNext; + buffer->m_pstNext = 0; + buffer->m_stTimeOut.m_nLowerValue = 0; + buffer->m_stTimeOut.m_nUpperValue = 0; + break; + } + runner = runner->m_pstNext; + } + } + } +} + +void CTimerHandler::nextTick(void) { + ++m_stForteTime; + getDeviceExecution()->notifyTime(m_stForteTime); //notify the device execution that one tick passed by. + { + CCriticalRegion criticalRegion(m_oSync); + while (0 != m_pstTimedFBList) { + if (m_pstTimedFBList->m_stTimeOut > m_stForteTime) { + break; + } + getDeviceExecution()->startNewEventChain(m_pstTimedFBList->m_poTimedFB); + STimedFBListEntry *buffer = m_pstTimedFBList; + m_pstTimedFBList = m_pstTimedFBList->m_pstNext; + + switch (buffer->m_eType) { + case e_Periodic: + addTimedFBEntry(buffer); //reregister the timed FB + break; + case e_SingleShot: + // nothing special is to do up to now + default: + buffer->m_pstNext = 0; + buffer->m_stTimeOut.m_nLowerValue = 0; + buffer->m_stTimeOut.m_nUpperValue = 0; + break; + } + } + } +} + diff --git a/src/arch/timerha.h b/src/arch/timerha.h new file mode 100644 index 000000000..d484c3cce --- /dev/null +++ b/src/arch/timerha.h @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Monika Wenger, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _TIMERHA_H_ +#define _TIMERHA_H_ + +#include +#include "../core/extevhan.h" +#include "../core/utils/singlet.h" +#include "../core/datatypes/forte_time.h" +#include + +class CEventSourceFB; + +enum ETimerActivationType{ + e_SingleShot, e_Periodic +}; + +struct SForteTime{ + TForteUInt32 m_nLowerValue; + TForteUInt32 m_nUpperValue; + + SForteTime(){ + m_nLowerValue = m_nUpperValue = 0; + } + + SForteTime &operator++(){ //++i; + ++m_nLowerValue; + if(0 == m_nLowerValue) + ++m_nUpperValue; + return *this; + } + SForteTime& operator=(const SForteTime &pa_stRightVal){ + m_nLowerValue = pa_stRightVal.m_nLowerValue; + m_nUpperValue = pa_stRightVal.m_nUpperValue; + return *this; + } + + SForteTime& operator+=(TForteUInt32 pa_nRightVal){ + TForteUInt32 nBuf = m_nLowerValue; + m_nLowerValue += pa_nRightVal; + if(nBuf > m_nLowerValue) + ++m_nUpperValue; + return *this; + } + + SForteTime& operator-=(TForteUInt32 pa_nRightVal){ + TForteUInt32 nBuf = m_nLowerValue; + m_nLowerValue -= pa_nRightVal; + if(nBuf < m_nLowerValue) + --m_nUpperValue; + return *this; + } + + SForteTime& operator-=(const SForteTime& pa_nRightVal){ + m_nUpperValue -= pa_nRightVal.m_nUpperValue; + if(m_nLowerValue < pa_nRightVal.m_nLowerValue){ + --m_nUpperValue; + --m_nLowerValue; + } + m_nLowerValue -= pa_nRightVal.m_nLowerValue; + return *this; + } + + bool operator>(const SForteTime &pa_stRightVal) const{ + bool bRetVal = false; + if((m_nUpperValue > pa_stRightVal.m_nUpperValue) || ((m_nUpperValue == pa_stRightVal.m_nUpperValue) && (m_nLowerValue > pa_stRightVal.m_nLowerValue))){ + bRetVal = true; + } + return bRetVal; + } + + bool operator==(const SForteTime &pa_stRightVal) const{ + return m_nUpperValue == pa_stRightVal.m_nUpperValue && m_nLowerValue == pa_stRightVal.m_nLowerValue; + } +}; + +inline const SForteTime operator-(const SForteTime &pa_nLeftVal, const SForteTime &pa_nRightVal){ + SForteTime oRetVal(pa_nLeftVal); + oRetVal -= pa_nRightVal; + return oRetVal; +} + +//! Data stored for each FB that is registered to the timer handler +struct STimedFBListEntry{ + SForteTime m_stTimeOut; //!< absolut time when the next trigger of the FB should occure + CEventSourceFB *m_poTimedFB; //!< Functionblock to be triggered + TForteUInt32 m_nInterval; //!< relative time between FB trigger points (mainly needed for the different periodic timed FBs) + ETimerActivationType m_eType; //!< type of activation. e.g. singleshot, periodic, ... + STimedFBListEntry *m_pstNext; //!< pointer to the next entry in the list +}; + +/*! \brief External event handler for the Timer. + * \ingroup EXTEVHAND + */ +class CTimerHandler : public CExternalEventHandler{ + public: + + virtual ~CTimerHandler(){ + } + ; + + /*!\brief Pointer to the instance of the concrete forte timer + */ + static CTimerHandler *sm_poFORTETimer; + /*!\brief create the timer handler and set the pointer of sm_poFORTETimer to the new timer handler. + * + * This function is not implemented in the standardtimerhandler and has to be implemented in the specific implementation. + * implementations should check that not two timerhanlders can be created. + */ + static void createTimerHandler(void); + + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority) = 0; + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const = 0; + + /*! \brief Get the time base of the runtime + * + * \return internal runtime ticks per second + */ + static TForteUInt32 getTicksPerSecond(void){ + return cg_nForteTicksPerSecond; + } + ; + + /*!\brief Register an Event source Functionblock to this external event source. + * + * \param pa_pstTimerListEntry TimerListEntry data + * \param pa_roTimeInterval time interval to next event + */ + void registerTimedFB(STimedFBListEntry *pa_pstTimerListEntry, const CIEC_TIME &pa_roTimeInterval); + /*!\brief Unregister an FB from an the timmer + * + * \param pa_poTimedFB FB to unregister from this external event handler + */ + void unregisterTimedFB(CEventSourceFB *pa_poTimedFB); + //! one tick of time elapsed. Implementations should call this function on each tick. + void nextTick(void); + //! returns the time since startup of FORTE + const SForteTime &getForteTime() const{ + return m_stForteTime; + } + protected: + CSyncObject m_oSync; + + //! private constructor that allows that no other object can create an timerhandler + CTimerHandler() : m_pstTimedFBList(0){ + } + ; + private: + /*!\brief The runtime time in tics till last reboot. + */ + SForteTime m_stForteTime; + //! List of function blocks currently registered to the timer handler + STimedFBListEntry *m_pstTimedFBList; + //!Add an entry to the timed list. + void addTimedFBEntry(STimedFBListEntry *pa_pstTimerListEntry); + +}; + +#endif /*TIMERHA_H_*/ diff --git a/src/arch/win32/CMakeLists.txt b/src/arch/win32/CMakeLists.txt new file mode 100644 index 000000000..b28a4eec1 --- /dev/null +++ b/src/arch/win32/CMakeLists.txt @@ -0,0 +1,60 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl, Gerhard Ebenhofer, Martin Melik-Merkumians - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +SET(SOURCE_GROUP ${SOURCE_GROUP}\\win32) + +forte_add_architecture(Win32) + +if("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + + add_subdirectory ( serlayer ) + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + forte_add_sourcefile_h(fortealloc.h) + forte_add_sourcefile_hcpp(thread sync) + forte_add_sourcefile_cpp(main.cpp) + + if(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) + set(FORTE_EXTERNAL_TIMEHA ON CACHE BOOL "Use External Time Handler") + if(FORTE_EXTERNAL_TIMEHA) + forte_add_sourcefile_hcpp(externtimeha) + else(FORTE_EXTERNAL_TIMEHA) + forte_add_sourcefile_hcpp(pctimeha) + endif(FORTE_EXTERNAL_TIMEHA) + else(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) + unset(FORTE_EXTERNAL_TIMEHA CACHE) + forte_add_sourcefile_hcpp(pctimeha) + endif(${FORTE_BUILD_TYPE} STREQUAL SHARED_LIBRARY) + + + if(FORTE_COM_ETH) + forte_add_sourcefile_hcpp( ../fdselecthand ../bsdsocketinterf) + forte_add_sourcefile_h(../gensockhand.h) + forte_add_sourcefile_h(sockhand.h) + endif(FORTE_COM_ETH) + + forte_add_include_directories(../${CMAKE_CURRENT_SOURCE_DIR}) + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + SET(CMAKE_CXX_FLAGS_RELEASE "/MT" ) + forte_add_definition("-DFORTE_LITTLE_ENDIAN") # -DNONAMESPACE -DWITH_NONAMESPACES) + +# TODO this flag was originaly wrongly added to the definitions. May be necessary to be added as link flag. However currently working fine. +# forte_add_link_flags("/NODEFAULTLIB:MSVCRT.lib") + + forte_add_link_library(comctl32.lib) + forte_add_link_library(rpcrt4.lib) + forte_add_link_library(winmm.lib) + forte_add_link_library(Ws2_32.lib) + forte_add_link_library(version.lib) + + +endif() diff --git a/src/arch/win32/externtimeha.cpp b/src/arch/win32/externtimeha.cpp new file mode 100644 index 000000000..fe3f6d8e5 --- /dev/null +++ b/src/arch/win32/externtimeha.cpp @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2011, 2013 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "externtimeha.h" +#include "../../core/devexec.h" +#include + + +const TForteInt32 CExternTimerHandler::csm_nTicksPerSecond = 1000; + +extern "C" __declspec(dllexport) +void __stdcall nextTick(void){ + CExternTimerHandler::externNextTick(); +} + +extern "C" __declspec(dllexport) +unsigned int __stdcall getTicksPerSecond(){ + return CExternTimerHandler::getExternTicksPerSecond(); +} + +void CTimerHandler::createTimerHandler(void){ + if(0 == sm_poFORTETimer) + sm_poFORTETimer = new CExternTimerHandler(); + +} + +CExternTimerHandler::CExternTimerHandler(){ +} + +CExternTimerHandler::~CExternTimerHandler(){ + disableHandler(); +} + +void CExternTimerHandler::externNextTick(){ + if(0 != sm_poFORTETimer){ + sm_poFORTETimer->nextTick(); + } +} + + +void CExternTimerHandler::enableHandler(void){ + //TODO think on hwo to handle this. +} + +void CExternTimerHandler::disableHandler(void){ + //TODO think on hwo to handle this. +} + +void CExternTimerHandler::setPriority(int pa_nPriority){ + //TODO think on hwo to handle this. +} + +int CExternTimerHandler::getPriority(void) const{ + //TODO think on hwo to handle this. + return 1; +} diff --git a/src/arch/win32/externtimeha.h b/src/arch/win32/externtimeha.h new file mode 100644 index 000000000..e38fd2fa9 --- /dev/null +++ b/src/arch/win32/externtimeha.h @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2011 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _PCTIMEHA_H_ +#define _PCTIMEHA_H_ + +#include "timerha.h" + +/*! \ingroup pc_hal + *\ingroup EXTEVHAND + *\brief the timer handler for the pc architecture. +*/ +class CExternTimerHandler : public CTimerHandler{ + private: + /*!\brief default time base of the used timer. in useconds. + */ + static const TForteInt32 csm_nTicksPerSecond; + /*!\brief callback function for the system timer + */ + + public: + static void externNextTick(); + static TForteUInt32 getExternTicksPerSecond(void){ return csm_nTicksPerSecond; }; + CExternTimerHandler(); + + virtual ~CExternTimerHandler(); + + + /*!\brief Enables this event source + * + */ + virtual void enableHandler(void); + /*!\brief Disable this event source + */ + virtual void disableHandler(void); + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority); + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const; + + /*! \brief Get the time base of the runtime + * + * \return internal runtime ticks per millisecond + */ + virtual TForteUInt32 getTicksPerSecond(void){ return csm_nTicksPerSecond; }; + + +}; + +#endif /*PCTIMEHA_H_*/ diff --git a/src/arch/win32/fortealloc.h b/src/arch/win32/fortealloc.h new file mode 100644 index 000000000..eb53c165c --- /dev/null +++ b/src/arch/win32/fortealloc.h @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FORTEALLOC_H_ +#define FORTEALLOC_H_ + +//on win32 environments use default new operator +#include +#include + +inline +void forte_free(void *pa_pvData){ + free(pa_pvData); +} + +inline +void *forte_malloc(size_t pa_nSize){ + return malloc(pa_nSize); +} + +inline +void *forte_realloc(void *pa_pvData, size_t pa_nSize){ + return realloc(pa_pvData, pa_nSize); +} + + +#endif /* FORTEALLOC_H_ */ diff --git a/src/arch/win32/main.cpp b/src/arch/win32/main.cpp new file mode 100644 index 000000000..47bb8a54b --- /dev/null +++ b/src/arch/win32/main.cpp @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2012 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include +#include +#ifdef WIN32 +#include +#endif +#ifdef FORTE_FBTESTS +#include +#endif + +//this keeps away a lot of rtti and exception handling stuff +extern "C" void +__cxa_pure_virtual(void) { + //TODO maybe add some reporting here + //Although we should never get here + //if we are here something very very bad has happened e.g., stack overflow or other memory corruption + +} + +RMT_DEV *poDev = 0; + +void endForte(int pa_nSig){ + (void)pa_nSig; + if(0 != poDev){ + poDev->changeFBExecutionState(cg_nMGM_CMD_Kill); + } +} + +/*!\brief Creates the Device-Object + * \param pa_acMGRID A string containing IP and Port like [IP]:[Port] + */ +void createDev(const char *pa_acMGRID) { + + signal(SIGINT, endForte); + signal(SIGTERM, endForte); + + poDev = new RMT_DEV; + + #ifdef FORTE_FBTESTS + CFBTestsManager::getInstance().runAllTests(); + #endif + + poDev->setMGR_ID(pa_acMGRID); + poDev->startDevice(); + poDev->MGR.getResourceEventExecution()->joinEventChainExecutionThread(); + delete poDev; +} + +/*!\brief Lists the help for FORTE + * + */ +void listHelp() { + printf("\nUsage of FORTE:\n"); + printf(" -h\t lists this help.\n"); + printf("\n"); + printf(" -c\t sets the destination for the connection.\n"); + printf(" \t Usage: forte -c :"); + printf("\n"); +} + +#ifdef FORTE_SHARED_LIB +extern "C" __declspec(dllexport) int __stdcall main(int argc, char *arg[]) { +#else + int main(int argc, char *arg[]) { +#endif + #ifdef WIN32 + // Windows Socket Startupcode + WORD wVersionRequested; + WSADATA wsaData; + + /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ + wVersionRequested = MAKEWORD(2, 2); + + WSAStartup(wVersionRequested, &wsaData); + #endif + + if (argc <= 1) { //! Default Value (localhost:61499) + createDev("localhost:61499"); + } + else { + if (strcmp("-c", arg[1]) == 0) { //! sets the destination for the connection + createDev(arg[2]); + } + else { //! Lists the help for FORTE + listHelp(); + } + } + + #ifdef WIN32 + WSACleanup(); + #endif + return 0; +} diff --git a/src/arch/win32/pctimeha.cpp b/src/arch/win32/pctimeha.cpp new file mode 100644 index 000000000..864ff4b4f --- /dev/null +++ b/src/arch/win32/pctimeha.cpp @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "pctimeha.h" +#include "../../core/devexec.h" +//#include +#define WIN32_LEAN_AND_MEAN +#include + +const TForteInt32 CPCTimerHandler::csm_nTicksPerSecond = 1000; + +void CTimerHandler::createTimerHandler(void){ + if(0 == sm_poFORTETimer) + sm_poFORTETimer = new CPCTimerHandler(); + +} + +CPCTimerHandler::CPCTimerHandler(){ +} + +CPCTimerHandler::~CPCTimerHandler(){ + disableHandler(); +} + +/* + HANDLE gDoneEvent; + + VOID CALLBACK TimerRoutine(PVOID lpParam, BOOLEAN TimerOrWaitFired) + { + CPCTimerHandler *timerHandler = (CPCTimerHandler*) lpParam; + if(timerHandler != 0){ + if(timerHandler->isAlive() ){ + timerHandler->nextTick(); + } + else{ + SetEvent(gDoneEvent); + } + } + } + + + bool CPCTimerHandler::run(){ + + HANDLE hTimer = NULL; + + // Use an event object to track the TimerRoutine execution + gDoneEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (NULL == gDoneEvent){ + return false; + } + + // Set a timer to call the timer routine in 10 seconds. + if (!CreateTimerQueueTimer( &hTimer, 0, (WAITORTIMERCALLBACK)TimerRoutine, this, 0, 1000 / CPCTimerHandler::csm_nTicksPerSecond, 0)) + { + return false; + } + + if (WaitForSingleObject(gDoneEvent, INFINITE) != WAIT_OBJECT_0) + return false; + + DeleteTimerQueueTimer(0, hTimer,0); + + CloseHandle(gDoneEvent); + + + return true; + }*/ + +void CPCTimerHandler::run(){ + DWORD stReq = 0; // in us + LARGE_INTEGER stReqTimeVal = { 0, 0 }; + + LARGE_INTEGER stFrequenzy = { 0, 0 }; // clocks per second + LARGE_INTEGER stElapsed1 = { 0, 0 }; + LARGE_INTEGER stElapsed2 = { 0, 0 }; + LARGE_INTEGER stError = { 0, 0 }; + LARGE_INTEGER stISum = { 0, 0 }; + LARGE_INTEGER stWaittime = { 0, 0 }; + + QueryPerformanceFrequency(&stFrequenzy); + QueryPerformanceCounter(&stElapsed1); + + stReqTimeVal.QuadPart = stFrequenzy.QuadPart / CPCTimerHandler::csm_nTicksPerSecond; + //stReqTimeVal = 1000000 / CPCTimerHandler::csm_nTicksPerSecond; + + while(m_bAlive){ + stWaittime.QuadPart *= 1000; // calculate in ms, not sec + stReq = (stWaittime.QuadPart / stFrequenzy.QuadPart); // calculate elapsed time in ms + + // dont give up the thread if we still have to do some ticks(some os have 10ms minimum threadtime) + if(stReq > 0){ + Sleep(stReq); + } + nextTick(); + + // sample new time + stElapsed2.QuadPart = stElapsed1.QuadPart; + QueryPerformanceCounter(&stElapsed1); + + // calulate controler error: Diff - Setupvalue = Error + stError.QuadPart = stElapsed1.QuadPart - stElapsed2.QuadPart; + stError.QuadPart = stReqTimeVal.QuadPart - stError.QuadPart; + + // I-controller + stISum.QuadPart += stError.QuadPart; + + // calculate new Output + stWaittime.QuadPart = stReqTimeVal.QuadPart + stISum.QuadPart; + if(stWaittime.QuadPart < 0){ + stWaittime.QuadPart = 0; + } + } +} + +void CPCTimerHandler::enableHandler(void){ + start(); +} + +void CPCTimerHandler::disableHandler(void){ + end(); +} + +void CPCTimerHandler::setPriority(int pa_nPriority){ + //TODO think on hwo to handle this. +} + +int CPCTimerHandler::getPriority(void) const{ + //TODO think on hwo to handle this. + return 1; +} diff --git a/src/arch/win32/pctimeha.h b/src/arch/win32/pctimeha.h new file mode 100644 index 000000000..c709059e9 --- /dev/null +++ b/src/arch/win32/pctimeha.h @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _PCTIMEHA_H_ +#define _PCTIMEHA_H_ + +#include "thread.h" +#include "../timerha.h" + +/*! \ingroup win32_hal + *\ingroup EXTEVHAND + *\brief the timer handler for the pc architecture. +*/ +class CPCTimerHandler : public CTimerHandler, public CThread{ + private: + /*!\brief default time base of the used timer. in useconds. + */ + static const TForteInt32 csm_nTicksPerSecond; + /*!\brief callback function for the system timer + */ + + public: + CPCTimerHandler(); + + virtual ~CPCTimerHandler(); + + virtual void run(); + + /*!\brief Enables this event source + * + */ + virtual void enableHandler(void); + /*!\brief Disable this event source + */ + virtual void disableHandler(void); + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority); + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const; + + /*! \brief Get the time base of the runtime + * + * \return internal runtime ticks per millisecond + */ + virtual TForteUInt32 getTicksPerSecond(void){ return csm_nTicksPerSecond; }; + + +}; + +#endif /*PCTIMEHA_H_*/ diff --git a/src/arch/win32/serlayer/CMakeLists.txt b/src/arch/win32/serlayer/CMakeLists.txt new file mode 100644 index 000000000..dbf20a43e --- /dev/null +++ b/src/arch/win32/serlayer/CMakeLists.txt @@ -0,0 +1,15 @@ +#******************************************************************************* +# * Copyright (c) 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Martin Melik-Merkumians - initial API and implementation and/or initial documentation +# *******************************************************************************/ +forte_add_network_layer(SER OFF "ser" CWin32SerComLayer cwin32sercomlayer "Enable Forte serial line communication") +if(FORTE_COM_SER) + forte_add_sourcefile_hcpp( cwin32sercomhandler ) + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +endif(FORTE_COM_SER) \ No newline at end of file diff --git a/src/arch/win32/serlayer/cwin32sercomhandler.cpp b/src/arch/win32/serlayer/cwin32sercomhandler.cpp new file mode 100644 index 000000000..95bb4a5f8 --- /dev/null +++ b/src/arch/win32/serlayer/cwin32sercomhandler.cpp @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik-Merkumians, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "cwin32sercomhandler.h" +#include "cwin32sercomlayer.h" +#include +#include +#define WIN32_LEAN_AND_MEAN +#include + +DEFINE_SINGLETON(CWin32SerComHandler); + +CWin32SerComHandler::CWin32SerComHandler() { +} + +CWin32SerComHandler::~CWin32SerComHandler(){ + this->end(); +} + +void CWin32SerComHandler::registerSerComLayer(CWin32SerComLayer *pa_poComLayer){ + m_oSync.lock(); + m_lstComLayerList.push_back(pa_poComLayer); + m_oSync.unlock(); + if(!isAlive()){ + this->start(); + } + resumeSelfSuspend(); +} + +void CWin32SerComHandler::unregisterSerComLayer(CWin32SerComLayer *pa_poComLayer){ + m_oSync.lock(); + + TCWin32SerComLayerContainer::Iterator itRunner(m_lstComLayerList.begin()); + TCWin32SerComLayerContainer::Iterator itRefNode(m_lstComLayerList.end()); + TCWin32SerComLayerContainer::Iterator itEnd(m_lstComLayerList.end()); + + while(itRunner != itEnd){ + if(*itRunner == pa_poComLayer){ + if(itRefNode == itEnd){ + m_lstComLayerList.pop_front(); + } + else{ + m_lstComLayerList.eraseAfter(itRefNode); + } + break; + } + + itRefNode = itRunner; + ++itRunner; + } + m_oSync.unlock(); +} + +void CWin32SerComHandler::run(){ + while(isAlive()){ + + if(true == m_lstComLayerList.isEmpty()){ + selfSuspend(); + } + + m_oSync.lock(); + TCWin32SerComLayerContainer::Iterator itEnd(m_lstComLayerList.end()); + for(TCWin32SerComLayerContainer::Iterator itRunner = m_lstComLayerList.begin(), itCurrent = m_lstComLayerList.begin(); itRunner != itEnd;){ + itCurrent = itRunner; + ++itRunner; + + m_oSync.unlock(); + if(forte::com_infra::e_Nothing != (*itCurrent)->recvData(0,0)){ + startNewEventChain((*itCurrent)->getCommFB()); + } + m_oSync.lock(); + } + m_oSync.unlock(); + Sleep(1000); + } + +} diff --git a/src/arch/win32/serlayer/cwin32sercomhandler.h b/src/arch/win32/serlayer/cwin32sercomhandler.h new file mode 100644 index 000000000..746b7944d --- /dev/null +++ b/src/arch/win32/serlayer/cwin32sercomhandler.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik-Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include <../../../core/extevhan.h> +#include <../../../core/utils/singlet.h> +#include "../../../core/fortelist.h" + +#ifndef CWIN32SERCOMHANDLER_H_ +#define CWIN32SERCOMHANDLER_H_ + +class CWin32SerComLayer; + +class CWin32SerComHandler : public CExternalEventHandler, public CThread{ + DECLARE_SINGLETON(CWin32SerComHandler) + public: + + void registerSerComLayer(CWin32SerComLayer *pa_poComLayer); + void unregisterSerComLayer(CWin32SerComLayer *pa_poComLayer); + + /* functions needed for the external event handler interface */ + void enableHandler(void){ + start(); + } + + void disableHandler(void){ + end(); + } + + void setPriority(int){ + //currently we are doing nothing here. + //TODO We should adjust the thread priority. + } + + int getPriority(void) const{ + //the same as for setPriority + return 0; + } + + private: + void run(); + + typedef CSinglyLinkedList TCWin32SerComLayerContainer; + + TCWin32SerComLayerContainer m_lstComLayerList; + CSyncObject m_oSync; +}; + +#endif /* CWIN32SERCOMLAYER_H_ */ diff --git a/src/arch/win32/serlayer/cwin32sercomlayer.cpp b/src/arch/win32/serlayer/cwin32sercomlayer.cpp new file mode 100644 index 000000000..acf08f481 --- /dev/null +++ b/src/arch/win32/serlayer/cwin32sercomlayer.cpp @@ -0,0 +1,160 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik-Merkumians, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "cwin32sercomlayer.h" +#include +#include +#include "cwin32sercomhandler.h" + +CWin32SerComLayer::CWin32SerComLayer(forte::com_infra::CComLayer* pa_poUpperLayer, + forte::com_infra::CCommFB * pa_poFB) : + forte::com_infra::CComLayer(pa_poUpperLayer, pa_poFB), m_unBufFillSize(0) { + m_hSerial = INVALID_HANDLE_VALUE; +} + +CWin32SerComLayer::~CWin32SerComLayer() { + closeConnection(); +} + + +forte::com_infra::EComResponse CWin32SerComLayer::recvData(const void *, unsigned int ) { + m_eInterruptResp = forte::com_infra::e_Nothing; + + DWORD dwBytesRead = 0; + if(ReadFile(m_hSerial, m_acRecvBuffer, m_unMaxRecvBuffer-1, &dwBytesRead, NULL)) + { //TODO: Failure handling and send INITO- + if (0 < dwBytesRead) + { + m_unBufFillSize = dwBytesRead; + m_eInterruptResp = forte::com_infra::e_ProcessDataOk; + m_poFb->interruptCommFB(this); + } else{ + m_eInterruptResp = forte::com_infra::e_ProcessDataRecvFaild; + } + } + return m_eInterruptResp; +} + +forte::com_infra::EComResponse CWin32SerComLayer::processInterrupt(){ + if(forte::com_infra::e_ProcessDataOk == m_eInterruptResp){ + switch (m_eConnectionState){ + case forte::com_infra::e_Connected: + if (0 == m_poTopLayer) { + CIEC_ANY *apoRDs = m_poFb->getRDs(); + unsigned int nrRDs = m_poFb->getNumRD(); + switch(apoRDs[0].getDataTypeID()) { + case CIEC_ANY::e_STRING: + static_cast(apoRDs[0]).fromUTF8(m_acRecvBuffer, m_unBufFillSize, false); + break; + } + } + else if((0 < m_unBufFillSize) && (0 != m_poTopLayer)) { + m_eInterruptResp = m_poTopLayer->recvData(m_acRecvBuffer, m_unBufFillSize); + m_unBufFillSize = 0; + } + break; + case forte::com_infra::e_Disconnected: + case forte::com_infra::e_Listening: + case forte::com_infra::e_ConnectedAndListening: + default: + break; + } + } + return m_eInterruptResp; +} + +void CWin32SerComLayer::closeConnection() { + CWin32SerComHandler::getInstance().unregisterSerComLayer(this); + CloseHandle(m_hSerial); +} + +forte::com_infra::EComResponse CWin32SerComLayer::sendData(void *pa_pvData, unsigned int pa_unSize) +{ + DWORD dwBytesWritten= 0, dwWaitResult = 0; + TConstIEC_ANYPtr apoSDs = static_cast (pa_pvData); + for (unsigned int i = 0; i < pa_unSize; ++i) + { + if (apoSDs[i].getDataTypeID() == CIEC_ANY::e_STRING) + { + unsigned int nToBeSent= static_cast(apoSDs[i]).length(); + if(!WriteFile(m_hSerial, static_cast(apoSDs[i]).getValue(), nToBeSent, &dwBytesWritten, NULL)) + { + return forte::com_infra::e_ProcessDataSendFailed; + } + if(dwBytesWritten != static_cast(apoSDs[i]).length()) + { + return forte::com_infra::e_ProcessDataSendFailed; + } + } + } + return forte::com_infra::e_ProcessDataOk; +} + + +forte::com_infra::EComResponse CWin32SerComLayer::openConnection(char *pa_acLayerParameter) { + //Create Serial Com Handle + m_hSerial = CreateFile(pa_acLayerParameter, + GENERIC_READ | GENERIC_WRITE, + 0, + 0, + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + 0); + if(INVALID_HANDLE_VALUE == m_hSerial) { + if(ERROR_FILE_NOT_FOUND == GetLastError()) { + return forte::com_infra::e_ProcessDataNoSocket; + } + return forte::com_infra::e_ProcessDataInvalidObject; + } + + DCB dcbSerialParams = {0}; + + dcbSerialParams.DCBlength = sizeof(dcbSerialParams); + + if(!GetCommState(m_hSerial, &dcbSerialParams)) { + return forte::com_infra::e_ProcessDataNoSocket; + } + + dcbSerialParams.BaudRate = CBR_19200; + dcbSerialParams.ByteSize = 8; + dcbSerialParams.StopBits = ONESTOPBIT; + dcbSerialParams.Parity = NOPARITY; + + if(!SetCommState(m_hSerial, &dcbSerialParams)) { + return forte::com_infra::e_ProcessDataNoSocket; + } + + //Timeouts for non-blocking behaviour + COMMTIMEOUTS timeouts = {0}; + //Read timeouts + timeouts.ReadIntervalTimeout = 50; + timeouts.ReadTotalTimeoutConstant = 50; + timeouts.ReadTotalTimeoutMultiplier = 10; + //Write timeouts + timeouts.WriteTotalTimeoutConstant = 50; + timeouts.WriteTotalTimeoutMultiplier = 10; + + if(!SetCommTimeouts(m_hSerial, &timeouts)) { + return forte::com_infra::e_ProcessDataNoSocket; + } + + switch (m_poFb->getComServiceType()){ + case forte::com_infra::e_Server: + case forte::com_infra::e_Client: + CWin32SerComHandler::getInstance().registerSerComLayer(this); + m_eConnectionState = forte::com_infra::e_Connected; + break; + case forte::com_infra::e_Publisher: + break; + case forte::com_infra::e_Subscriber: + break; + } + return forte::com_infra::e_InitOk; +} diff --git a/src/arch/win32/serlayer/cwin32sercomlayer.h b/src/arch/win32/serlayer/cwin32sercomlayer.h new file mode 100644 index 000000000..aef5d7381 --- /dev/null +++ b/src/arch/win32/serlayer/cwin32sercomlayer.h @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik-Merkumians, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include + +#include + +#ifndef CWIN32SERCOMLAYER_H_ +#define CWIN32SERCOMLAYER_H_ + +class CEventSourceFB; + +class CWin32SerComLayer : public forte::com_infra::CComLayer{ + public: + CWin32SerComLayer(forte::com_infra::CComLayer* pa_poUpperLayer, forte::com_infra::CCommFB * pa_poFB); + virtual ~CWin32SerComLayer (); + + virtual forte::com_infra::EComResponse processInterrupt(); + + virtual void closeConnection(); + virtual forte::com_infra::EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); + /*! \brief Perform reading from serial interface + * + * @return if not e_Nothing something was read and the FB should get an external event + */ + virtual forte::com_infra::EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + + protected: + private: + virtual forte::com_infra::EComResponse openConnection(char *pa_acLayerParameter); + HANDLE m_hSerial; + static const unsigned int m_unMaxRecvBuffer = 22; + + forte::com_infra::EComResponse m_eInterruptResp; + char m_acRecvBuffer[m_unMaxRecvBuffer]; + unsigned int m_unBufFillSize; + +}; + +#endif /* CWIN32SERCOMLAYER_H_ */ diff --git a/src/arch/win32/sockhand.h b/src/arch/win32/sockhand.h new file mode 100644 index 000000000..7a49bb140 --- /dev/null +++ b/src/arch/win32/sockhand.h @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef SOCKHAND_H_ +#define SOCKHAND_H_ + +#ifndef IN +#define IN +#endif + +#ifndef OUT +#define OUT +#endif + +#include +#include +#include +//these include needs to be last +#include "../fdselecthand.h" +#include "../bsdsocketinterf.h" +#include "../gensockhand.h" + +typedef CGenericIPComSocketHandler CIPComSocketHandler; + +#endif /* SOCKHAND_H_ */ diff --git a/src/arch/win32/sync.cpp b/src/arch/win32/sync.cpp new file mode 100644 index 000000000..7e50e0b29 --- /dev/null +++ b/src/arch/win32/sync.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "sync.h" + +CPCSyncObject::CPCSyncObject(){ + InitializeCriticalSection(&m_oMutexHandle); +} + +CPCSyncObject::~CPCSyncObject(){ + DeleteCriticalSection(&m_oMutexHandle); + //TODO handle return value +} diff --git a/src/arch/win32/sync.h b/src/arch/win32/sync.h new file mode 100644 index 000000000..a113d52bc --- /dev/null +++ b/src/arch/win32/sync.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Martin Melik-Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SYNC_H_ +#define _SYNC_H_ + +#define WIN32_LEAN_AND_MEAN + #include + +#define CSyncObject CPCSyncObject //allows that doxygen can generate better documenation + + +/*! \ingroup win32_hal + * \brief The sync object implementation for the win32 thread interface. + * + * In the win32 version a CRITICAL_SECTION is used for the sync object. + * + */ + +class CPCSyncObject{ + private: + protected: + //! The win32 CRITICAL_SECTION handle of the operating system. + CRITICAL_SECTION m_oMutexHandle; + + public: + CPCSyncObject(); + ~CPCSyncObject(); + /*!\brief Lock the resource coming after the lock command + * + * This function blocks until it will get the lock for the coming critical section. + */ + void lock(void){ + EnterCriticalSection(&m_oMutexHandle); + //TODO handle return value + }; + //!Free the resource coming after the lock command + void unlock(void){ + LeaveCriticalSection(&m_oMutexHandle); + //TODO handle return value + }; +}; + +#endif /*SYNC_H_*/ diff --git a/src/arch/win32/thread.cpp b/src/arch/win32/thread.cpp new file mode 100644 index 000000000..04de5ff50 --- /dev/null +++ b/src/arch/win32/thread.cpp @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2014 ACIN, Profactor GmbH, AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "thread.h" +#include "../devlog.h" + +DWORD WINAPI CWin32Thread::threadFunction(LPVOID arguments){ + // Get pointer to CThread object out of void pointer + CWin32Thread *pThread = (CWin32Thread *) arguments; + + // if pointer is ok + if(0 != pThread){ + pThread->m_bAlive = true; + pThread->run(); + pThread->m_bAlive = false; + pThread->m_nThreadHandle = 0; + } + else{ + DEVLOG_ERROR("pThread pointer is 0!"); + } + return 0; +} + +CWin32Thread::CWin32Thread(long pa_nStackSize) : + m_bAlive(false), m_nThreadHandle(0), m_nStackSize(pa_nStackSize), m_nThreadID(~0x0ul){ + + m_hSelfSuspendSemaphore = CreateSemaphore(NULL, 0, 10, NULL); + + if(0 == m_hSelfSuspendSemaphore){ + DEVLOG_ERROR("Could not initialize suspend semphore: %d\n", GetLastError()); + } +} + +CWin32Thread::~CWin32Thread(){ + if(0 != m_nThreadHandle){ + end(); + } + CloseHandle(m_hSelfSuspendSemaphore); +} + +bool CWin32Thread::isAlive(void) const{ + return m_bAlive; +} + +void CWin32Thread::setDeadline(const CIEC_TIME &pa_roVal){ + m_oDeadline = pa_roVal; +//under the win32 currently it makes no sense to set any priority. +//It will not be considered. +} + +const CIEC_TIME &CWin32Thread::getDeadline(void) const{ + return m_oDeadline; +} + +void CWin32Thread::start(void){ + if(0 == m_nThreadHandle){ + + m_nThreadHandle = CreateThread(0, // default security attributes + m_nStackSize, // use default stack size + threadFunction, // thread function name + this, // argument to thread function + 0, // use default creation flags + &m_nThreadID); // returns the thread identifier + + if(0 == m_nThreadHandle){ + DEVLOG_ERROR("Error could not create the thread!"); + } + } +} + +void CWin32Thread::selfSuspend(void){ + WaitForSingleObject(m_hSelfSuspendSemaphore, INFINITE); +} + +void CWin32Thread::resumeSelfSuspend(void){ + ReleaseSemaphore(m_hSelfSuspendSemaphore, 1, 0); +} + +void CWin32Thread::end(void){ + m_bAlive = false; + resumeSelfSuspend(); + join(); +} + +void CWin32Thread::join(void){ + //check if the thread is still running and that we are not calling join from inside the thread + if((0 != m_nThreadHandle) && (GetCurrentThreadId() != m_nThreadID)){ + WaitForSingleObject(m_nThreadHandle, INFINITE); + } +} diff --git a/src/arch/win32/thread.h b/src/arch/win32/thread.h new file mode 100644 index 000000000..528d6b0c9 --- /dev/null +++ b/src/arch/win32/thread.h @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _THREAD_H_ +#define _THREAD_H_ + +#define WIN32_LEAN_AND_MEAN +#include +#include "../datatype.h" +#include "../../core/datatypes/forte_time.h" + + +/** \ingroup FORTE-HAL + * \defgroup win32_hal PC FORTE Hardware Abstraction Layer + * + * \brief The FORTE-HAL implementation for normal win32 + * + */ + +/*! \ingroup win32_hal + * \brief The thread implementation for the win32 thread interface. + * + */ +class CWin32Thread{ + public: + /*! \brief Constructor of the Thread class + * + * Does all the necessary steps in order to get the thread running with the start()-method + * @param pa_nStackSize the Size of the stack the thread is allowed to use. 0 means use system default stack size. + */ + CWin32Thread(long pa_nStackSize = 0); + + /*! \brief Stops and destroys thread. + * + * Will stop the execution if running and destroy the thread including all system specific data. + */ + virtual ~CWin32Thread(); + + /*! \brief Indicates if the thread is allowed to execute. + * + * This functions checks if the Thread is still executing user code in its run()-method. + * \return true if there the run method is active. + */ + bool isAlive(void) const; + + //!Set the deadline of the thread. + void setDeadline(const CIEC_TIME &m_roVal); + + //!Get the current deadline of the thread. + const CIEC_TIME &getDeadline(void) const; + + /*! \brief starts the Thread + * + * By calling this method the execution in the run()-Method will be started. If necessary additional data + * can be created here. Because of inheritance reasons the best place for executing create is in this method. + */ + void start(); + + /*! \brief Resumes a suspended Thread + */ + void resumeSelfSuspend(); + + /*! \brief Stops the execution of the thread + * + * This function immediately stops the execution of the thread (setting m_bAlive to false) and waits till + * this is finished. + */ + void end(void); + + /*! \brief Waits for the Thread to finish its execution. + * + * This function waits till the execution in the thread decides to end the execution. Blocks the caller!!! + */ + void join(void); // Waits + + protected: + /*! \brief Flag that indicates if the Thread is alive. + * + * This flag has two main purposes: + * -# indicate for other classes if the thread is still executing + * -# use in the run()-method to check if the thread is still allowed to execute (e.g. while(isAlive()) ). + * This is important for stopping and destroying threads. + */ + bool m_bAlive; + + /*!\brief Function that is given to the system thread support that should be called for the thread. + * + * this function will call the run method of the thread instance. + */ + //static void * threadFunction(void *arguments); + static DWORD WINAPI threadFunction(LPVOID arguments); + + /*! \brief Suspends the thread. + * + * Suspends the execution of the thread until resumeSelfSuspend(), end(), or join() is called. + */ + void selfSuspend(void); + + private: + /*! \brief Abstract method for the code to execute in the thread. + * + * This thread class has to provide means that the code a inheriting class will add to the run()-method will + * be executed in a separated thread regarding the creator of the CThread class. + * + * The inheriting class has to fulfill the following rules when using the run method: + * - To end the thread execution simple leave the run()-method + * - In order to allow the deletion and stopping of the thread add frequent checks to isAlive and end the + * execution if isAlive() returns false. + */ + virtual void run() = 0; + + //!deadline the thread needs to be finish its execution. 0 means unconstrained. + CIEC_TIME m_oDeadline; + + /*! \brief data needed for win32 scheduling system to identify the thread. + */ + HANDLE m_nThreadHandle; + + /*! \brief the 'real' thread ID of the started thread + */ + DWORD m_nThreadID; + + //! Semaphore to handle the self suspend mechanism required for FORTE-Threads more reliable + HANDLE m_hSelfSuspendSemaphore; + + /*! \brief Size of the stack used by this thread. + */ + long m_nStackSize; + + //we don't want that threads can be copied or assigned therefore the copy constructor and assignment operator are declared private + //but not implemented + CWin32Thread(const CWin32Thread&); + CWin32Thread& operator = (const CWin32Thread &); +}; + +typedef CWin32Thread CThread; //allows that doxygen can generate better documentation + +#endif /*THREAD_H_*/ + diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt new file mode 100644 index 000000000..7004b3c64 --- /dev/null +++ b/src/core/CMakeLists.txt @@ -0,0 +1,33 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2015 Profactor GmbH, ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Micheal Hofmann, Alois Zoitl, Gerhard Ebenhofer, Monika Wenger +# * - initial implementation and rework communication infrastructure +# *******************************************************************************/ +############################################################################# +# Core +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +forte_add_subdirectory(cominfra) +forte_add_subdirectory(datatypes) +forte_add_subdirectory(utils) + +forte_add_sourcefile_hcpp(conn dataconn eventconn) + +forte_add_sourcefile_h (esfb.h event.h mgmcmd.h fortenode.h fortelist.h convert_functions.h) +forte_add_sourcefile_hcpp(basicfb cfb device devexec ) +forte_add_sourcefile_hcpp(extevhan funcbloc fbcontainer if2indco ) +forte_add_sourcefile_hcpp(resource stringdict typelib ecet) +forte_add_sourcefile_hcpp(adapterconn adapter iec61131_functions) + +if(FORTE_SUPPORT_MONITORING) + forte_add_sourcefile_hcpp(monitoring) +endif(FORTE_SUPPORT_MONITORING) + + diff --git a/src/core/adapter.cpp b/src/core/adapter.cpp new file mode 100644 index 000000000..18cffca41 --- /dev/null +++ b/src/core/adapter.cpp @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "adapter.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "adapter_gen.cpp" +#endif +#include "adapterconn.h" +#include "ecet.h" + +CAdapter::CAdapter(CResource *pa_poSrcRes, + const SFBInterfaceSpec *pa_pstInterfaceSpecSocket, const CStringDictionary::TStringId pa_nInstanceNameId, const SFBInterfaceSpec *pa_pstInterfaceSpecPlug, + bool pa_bIsPlug, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) : + CFunctionBlock( pa_poSrcRes, + (pa_bIsPlug) ? pa_pstInterfaceSpecPlug : pa_pstInterfaceSpecSocket, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData), + m_bIsPlug(pa_bIsPlug), + m_poPeer(0), + m_aoLocalDIs(m_aoDIs), + m_poAdapterConn(0){ + + setupEventEntryList(); +} + +CAdapter::~CAdapter() { + if (m_bIsPlug) { + if (m_poAdapterConn != 0) { + delete m_poAdapterConn; + } + } + else { + if (m_poAdapterConn != 0) { + m_poAdapterConn->setSocket(0); + } + } + delete[] m_astEventEntry; +} + +void CAdapter::setParentFB(CFunctionBlock *pa_poParentFB, TForteUInt8 pa_nParentAdapterlistID) { + m_nParentAdapterListEventID = static_cast((pa_nParentAdapterlistID+1)<<8);; + + for(TForteUInt16 i = 0; i < m_pstInterfaceSpec->m_nNumEOs; ++i){ + m_astEventEntry[i].mFB = pa_poParentFB; + m_astEventEntry[i].mPortId = static_cast(m_nParentAdapterListEventID + i); + } + + if(isPlug()){ + //the plug is in charge of managing the adapter connection + m_poAdapterConn = new CAdapterConnection(this, pa_nParentAdapterlistID, this); + } +} + +bool CAdapter::connect(CAdapter *pa_poPeer, CAdapterConnection *pa_poAdConn) { + bool bRetVal = false; + if (m_poPeer == 0) { + m_poPeer = pa_poPeer; + m_aoDIs = pa_poPeer->m_aoDOs; //TODO: change is adapters of subtypes may be connected + m_poAdapterConn = pa_poAdConn; + bRetVal = true; + } + + return bRetVal; +} + +bool CAdapter::disconnect(CAdapterConnection *pa_poAdConn) { + if ((pa_poAdConn!=0) && (pa_poAdConn != m_poAdapterConn)){ + return false; //connection requesting disconnect is not equal to established connection + } + m_poPeer=0; + m_aoDIs = m_aoLocalDIs; + if(isSocket()){ + m_poAdapterConn = 0; + } + return true; +} + +bool CAdapter::isCompatible(CAdapter *pa_poPeer) { + //Need to check any adapter here as we don't know which adapter side is used for checking compatibility + return ((getFBTypeId() == pa_poPeer->getFBTypeId()) || + ((getFBTypeId() == g_nStringIdANY_ADAPTER) && (g_nStringIdANY_ADAPTER != pa_poPeer->getFBTypeId())) || + ((getFBTypeId() != g_nStringIdANY_ADAPTER) && (g_nStringIdANY_ADAPTER == pa_poPeer->getFBTypeId()))); +} + +void CAdapter::executeEvent(int pa_nEIID) { + if (0 != m_poPeer) { + if (0 != m_poPeer->m_astEventEntry[pa_nEIID].mFB) { + m_poInvokingExecEnv->addEventEntry(&(m_poPeer->m_astEventEntry[pa_nEIID])); + } else { + m_poPeer->m_poInvokingExecEnv = m_poInvokingExecEnv; + m_poPeer->sendOutputEvent(pa_nEIID); + } + } +} + +void CAdapter::setupEventEntryList(){ + m_astEventEntry = new SEventEntry[m_pstInterfaceSpec->m_nNumEOs]; +} diff --git a/src/core/adapter.h b/src/core/adapter.h new file mode 100644 index 000000000..ea0fac55f --- /dev/null +++ b/src/core/adapter.h @@ -0,0 +1,133 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ADAPTER_H_ +#define _ADAPTER_H_ + +#include "funcbloc.h" + +class CAdapterConnection; + +#define ADAPTER_CTOR(fbclass) \ + fbclass(CStringDictionary::TStringId pa_anAdapterInstanceName, CResource *pa_poSrcRes, bool pa_bIsPlug) : \ + CAdapter( pa_poSrcRes, &scm_stFBInterfaceSpecSocket, pa_anAdapterInstanceName, &scm_stFBInterfaceSpecPlug, pa_bIsPlug, m_anFBConnData, m_anFBVarsData) + + +#define FORTE_ADAPTER_DATA_ARRAY(a_nNumEIs, a_nNumEOs, a_nNumDIs, a_nNumDOs, a_nNumAdapters) \ + union{ \ + TForteByte m_anFBConnData[genAdapterFBConnDataSizeTemplate::value]; \ + };\ + union{ \ + TForteByte m_anFBVarsData[genFBVarsDataSizeTemplate::value]; \ + }; + + +/*!\ingroup CORE\brief Class for handling adapters. + * + */ +class CAdapter: public CFunctionBlock { + public: + /*!\brief The main constructor for an adapter instance. + */ + //TODO: think on interface + CAdapter(CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpecSocket, const CStringDictionary::TStringId pa_nInstanceNameId, const SFBInterfaceSpec *pa_pstInterfaceSpecPlug, bool pa_bIsPlug, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData); + virtual ~CAdapter(); + + /*!\brief Returns if Adapter instance is a Plug + */ + bool isPlug() { + return m_bIsPlug; + } + ; + + /*!\brief Returns if Adapter instance is a Socket + */ + bool isSocket() { + return !m_bIsPlug; + } + ; + + void setParentFB(CFunctionBlock *pa_poParentFB, TForteUInt8 pa_nParentAdapterlistID); + + /*! \brief Connects adapter to peer adapter + * + * With this command the adapter is connected to a complementary adapter instance (peer). + * The data output pointers are "redirected" to the data inputs of the peer. + * \param pa_poPeer Pointer to the peer to connect to. + * \param pa_poAdConn Pointer to the connecting adapter connection. + * \return success of establishment of connection + */ + virtual bool connect(CAdapter *pa_poPeer, CAdapterConnection *pa_poAdConn); + + /*! \brief Disconnects adapter from peer adapter + * + * With this command the adapter is disconnected from a complementary adapter instance (peer). + * The redirection of data output pointers is removed. + * \param pa_poAdConn Pointer to the connecting adapter connection. + * \return success of disconnection + */ + virtual bool disconnect(CAdapterConnection *pa_poAdConn = 0); + + /*! \brief Returns the compatibility of the adapter to another adapter + * + * This method will evaluate the compatibility of this adapter to another one. + * Only instances of compatible adapter types may be interconnected. + * \param pa_poPeer Pointer to a potential peer, whose compatibility has to be checked. + * \return compatibility status + */ + bool isCompatible(CAdapter *pa_poPeer); + + /*! provides access to the interface spec used for the specific adatpter instnace (i.e., plug or socket) + * Is required mainly by the anyadapter + */ + const SFBInterfaceSpec* getAdapterInterfaceSpec(){ + return m_pstInterfaceSpec; + } + + CAdapter *getPeer(){ + return m_poPeer; + } + + CAdapterConnection *getAdapterConnection() const { + return m_poAdapterConn; + } + + protected: + template + struct genAdapterFBConnDataSizeTemplate { + enum { + value = genFBConnDataSizeTemplate<((ta_nNumEIs < ta_nNumEOs) ? ta_nNumEOs : ta_nNumEIs), + ((ta_nNumDIs < ta_nNumDOs) ? ta_nNumDOs : ta_nNumDIs), + ((ta_nNumDIs < ta_nNumDOs) ? ta_nNumDOs : ta_nNumDIs)>::value + }; + }; + + static size_t genAdapterFBConnDataSize(unsigned int pa_nNumEIs, unsigned int pa_nNumEOs, unsigned int pa_nNumDIs, unsigned int pa_nNumDOs){ + return genFBConnDataSize(((pa_nNumEIs < pa_nNumEOs) ? pa_nNumEOs : pa_nNumEIs), + ((pa_nNumDIs < pa_nNumDOs) ? pa_nNumDOs : pa_nNumDIs), + ((pa_nNumDIs < pa_nNumDOs) ? pa_nNumDOs : pa_nNumDIs)); //for outputs data connections are stored in this array, as plugs and sockets have invoerted size wee need to use the max here. unfortunately not very efficient. should be reconsidered. + } + + + TForteUInt16 m_nParentAdapterListEventID; + + private: + virtual void executeEvent(int pa_nEIID); + void setupEventEntryList(); + + bool m_bIsPlug; + CAdapter *m_poPeer; + CIEC_ANY *m_aoLocalDIs; + CAdapterConnection *m_poAdapterConn; + SEventEntry *m_astEventEntry; //! the event entry list to start the event chain +}; + +#endif /*_ADAPTER_H_*/ diff --git a/src/core/adapterconn.cpp b/src/core/adapterconn.cpp new file mode 100644 index 000000000..6f415bed3 --- /dev/null +++ b/src/core/adapterconn.cpp @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "adapterconn.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "adapterconn_gen.cpp" +#endif +#include "funcbloc.h" +#include "adapter.h" + +CAdapterConnection::CAdapterConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId, + CAdapter *paPlug) : + CConnection(paSrcFB, paSrcPortId), + mPlug(paPlug), + mSocket(0){ +} + +CAdapterConnection::~CAdapterConnection(){ + performDisconnect(); +} + +EMGMResponse CAdapterConnection::connect(CFunctionBlock *paDstFB, + CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + + TPortId portId = paDstFB->getAddapterPortId(paDstPortNameId); + if(cg_unInvalidPortId != portId){ + if(!isConnected()){ + CAdapter *socket = paDstFB->getAdapter(paDstPortNameId); + if((socket->isSocket()) && (socket->isCompatible(mPlug))){ + if(((mPlug->connect(socket, this)) && (socket->connect(mPlug, this)))){ + mSocket = socket; + addDestination(SConnectionPoint(paDstFB, portId)); + retVal = e_RDY; + } + else{ + mPlug->disconnect(); + socket->disconnect(); + retVal = e_INVALID_OBJECT; + } + } + else{ + retVal = e_INVALID_OBJECT; + } + } + else{ + retVal = e_INVALID_STATE; + } + } + return retVal; +} + +EMGMResponse CAdapterConnection::connectToCFBInterface(CFunctionBlock *, CStringDictionary::TStringId ){ + return e_INVALID_OPERATION; //currently we are not supporting adapter connections accross interface boundaries +} + +#ifndef FORTE_CLASS_0 +EMGMResponse CAdapterConnection::disconnect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + + TPortId portId = paDstFB->getAddapterPortId(paDstPortNameId); + if(cg_unInvalidPortId != portId){ + retVal = CConnection::removeDestination(SConnectionPoint(paDstFB, portId)); + if(e_RDY == retVal){ + performDisconnect(); + } + } + return retVal; +} + +#endif + +void CAdapterConnection::performDisconnect(){ + if(mPlug != 0){ + mPlug->disconnect(this); + } + + if(mSocket != 0){ + mSocket->disconnect(this); + mSocket = 0; + } +} diff --git a/src/core/adapterconn.h b/src/core/adapterconn.h new file mode 100644 index 000000000..d0800d94d --- /dev/null +++ b/src/core/adapterconn.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ADAPTERCONN_H_ +#define _ADAPTERCONN_H_ + +#include "./datatypes/forte_any.h" +#include "conn.h" + +class CAdapter; + +/*! \ingroup CORE\brief Class for handling a adapter connection. + */ +class CAdapterConnection : public CConnection{ + public: + CAdapterConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId, CAdapter *paPlug); + virtual ~CAdapterConnection(); + + virtual EMGMResponse connect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); + virtual EMGMResponse connectToCFBInterface(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); + +#ifndef FORTE_CLASS_0 + virtual EMGMResponse disconnect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); +#endif + + CAdapter *getPlug(){ + return mPlug; + } + + void setSocket(CAdapter *pa_poSocket){ + mSocket = pa_poSocket; + } + + CAdapter *getSocket(){ + return mSocket; + } + + private: + void performDisconnect(); + + CAdapter *mPlug; + CAdapter *mSocket; + +}; + +typedef CAdapterConnection *TAdapterConnectionPtr; + +#endif /*_ADAPTERCONN_H_*/ diff --git a/src/core/anyadapter.cpp b/src/core/anyadapter.cpp new file mode 100644 index 000000000..30e1dbe64 --- /dev/null +++ b/src/core/anyadapter.cpp @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "anyadapter.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "anyadapter_gen.cpp" +#endif + +DEFINE_ADAPTER_TYPE(CAnyAdapter, g_nStringIdANY_ADAPTER) + +const SFBInterfaceSpec CAnyAdapter::scm_stFBInterfaceSpec = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + +CAnyAdapter::CAnyAdapter(CStringDictionary::TStringId pa_anAdapterInstanceName, CResource *pa_poSrcRes, bool pa_bIsPlug) : + CAdapter(pa_poSrcRes, &scm_stFBInterfaceSpec, pa_anAdapterInstanceName, &scm_stFBInterfaceSpec, pa_bIsPlug, 0, 0){ + memset(&m_stCurrentFBInterfaceSpec, 0, sizeof(SFBInterfaceSpec)); +} + +CAnyAdapter::~CAnyAdapter(){ +} + +bool CAnyAdapter::connect(CAdapter *pa_poPeer, CAdapterConnection *pa_poAdConn){ + //mirror the peer's interface definition + m_stCurrentFBInterfaceSpec.m_nNumEIs = pa_poPeer->getAdapterInterfaceSpec()->m_nNumEOs; + m_stCurrentFBInterfaceSpec.m_aunEINames = pa_poPeer->getAdapterInterfaceSpec()->m_aunEONames; + m_stCurrentFBInterfaceSpec.m_anEIWith = pa_poPeer->getAdapterInterfaceSpec()->m_anEOWith; + m_stCurrentFBInterfaceSpec.m_anEIWithIndexes = pa_poPeer->getAdapterInterfaceSpec()->m_anEOWithIndexes; + m_stCurrentFBInterfaceSpec.m_nNumEOs = pa_poPeer->getAdapterInterfaceSpec()->m_nNumEIs; + m_stCurrentFBInterfaceSpec.m_aunEONames = pa_poPeer->getAdapterInterfaceSpec()->m_aunEINames; + m_stCurrentFBInterfaceSpec.m_anEOWith = pa_poPeer->getAdapterInterfaceSpec()->m_anEIWith; + m_stCurrentFBInterfaceSpec.m_anEOWithIndexes = pa_poPeer->getAdapterInterfaceSpec()->m_anEIWithIndexes; + m_stCurrentFBInterfaceSpec.m_nNumDIs = pa_poPeer->getAdapterInterfaceSpec()->m_nNumDOs; + m_stCurrentFBInterfaceSpec.m_aunDINames = pa_poPeer->getAdapterInterfaceSpec()->m_aunDONames; + m_stCurrentFBInterfaceSpec.m_aunDIDataTypeNames = pa_poPeer->getAdapterInterfaceSpec()->m_aunDODataTypeNames; + m_stCurrentFBInterfaceSpec.m_nNumDOs = pa_poPeer->getAdapterInterfaceSpec()->m_nNumDIs; + m_stCurrentFBInterfaceSpec.m_aunDONames = pa_poPeer->getAdapterInterfaceSpec()->m_aunDINames; + m_stCurrentFBInterfaceSpec.m_aunDODataTypeNames = pa_poPeer->getAdapterInterfaceSpec()->m_aunDIDataTypeNames; + + + TForteByte *acFBConnData = new TForteByte[genAdapterFBConnDataSize(m_stCurrentFBInterfaceSpec.m_nNumEIs, m_stCurrentFBInterfaceSpec.m_nNumEOs, m_stCurrentFBInterfaceSpec.m_nNumDIs, m_stCurrentFBInterfaceSpec.m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize(m_stCurrentFBInterfaceSpec.m_nNumDIs, m_stCurrentFBInterfaceSpec.m_nNumDOs)]; + + setupFBInterface(&m_stCurrentFBInterfaceSpec, acFBConnData, acFBVarsData, true); + + return CAdapter::connect(pa_poPeer, pa_poAdConn); +} + +bool CAnyAdapter::disconnect(CAdapterConnection *pa_poAdConn){ + bool bRetVal = CAdapter::disconnect(pa_poAdConn); + + //clean interface data and reset to empty interface + freeAllData(); + setupFBInterface(&scm_stFBInterfaceSpec, 0, 0, false); + + return bRetVal; +} diff --git a/src/core/anyadapter.h b/src/core/anyadapter.h new file mode 100644 index 000000000..fdf173017 --- /dev/null +++ b/src/core/anyadapter.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef ANYADAPTER_H_ +#define ANYADAPTER_H_ + +#include "adapter.h" + +/*! \brief A generic adapter that behaves similar to the ANY data type and allows all other adapters to be connected. + * + * The main use of such an adapter is in service interfaces that provide generic services based on the adapter connected. + */ + +class CAnyAdapter : public CAdapter{ + DECLARE_ADAPTER_TYPE(CAnyAdapter) + + public: + CAnyAdapter(CStringDictionary::TStringId pa_anAdapterInstanceName, CResource *pa_poSrcRes, bool pa_bIsPlug); + virtual ~CAnyAdapter(); + + virtual bool connect(CAdapter *pa_poPeer, CAdapterConnection *pa_poAdConn); + virtual bool disconnect(CAdapterConnection *pa_poAdConn); + + //! Helper functions allowing to retrieve interface information from any_adpaters TODO look for Doxygen grouping syntax + TForteUInt8 getNumEIs(){ + return m_pstInterfaceSpec->m_nNumEIs; + } + + const TForteInt16* getEIWithIndexes(){ + return m_pstInterfaceSpec->m_anEIWithIndexes; + } + + const TDataIOID* getEIWiths(){ + return m_pstInterfaceSpec->m_anEIWith; + } + + TForteUInt8 getNumDIs(){ + return m_pstInterfaceSpec->m_nNumDIs; + } + + const CStringDictionary::TStringId* getDataInputNames(){ + return m_pstInterfaceSpec->m_aunDINames; + } + + TIEC_ANYPtr getDataInputs(){ + return getDI(0); + } + + TForteUInt8 getNumDOs(){ + return m_pstInterfaceSpec->m_nNumDOs; + } + + const CStringDictionary::TStringId* getDataOutputNames(){ + return m_pstInterfaceSpec->m_aunDONames; + } + + TIEC_ANYPtr getDataOutputs(){ + return getDO(0); + } + + protected: + + private: + static const SFBInterfaceSpec scm_stFBInterfaceSpec; //! interface spec for the empty interface of an any adapter will be used for plug and socket + + //!Interface specification to be used when configured + SFBInterfaceSpec m_stCurrentFBInterfaceSpec; +}; + +#endif /* ANYADAPTER_H_ */ diff --git a/src/core/basicfb.cpp b/src/core/basicfb.cpp new file mode 100644 index 000000000..c1471e312 --- /dev/null +++ b/src/core/basicfb.cpp @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "basicfb.h" + +CBasicFB::CBasicFB(CResource *pa_poSrcRes, + const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, + const SInternalVarsInformation *pa_pstVarInternals, + TForteByte *pa_acFBConnData, TForteByte *pa_acBasicFBVarsData) : + CFunctionBlock(pa_poSrcRes, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acBasicFBVarsData), + m_nECCState(0), + cm_pstVarInternals(pa_pstVarInternals){ + + if((0 != cm_pstVarInternals) && (0 != pa_acBasicFBVarsData)){ + if(cm_pstVarInternals->m_nNumIntVars){ + pa_acBasicFBVarsData += + genFBVarsDataSize(m_pstInterfaceSpec->m_nNumDIs, m_pstInterfaceSpec->m_nNumDOs, m_pstInterfaceSpec->m_nNumAdapters); + + m_aoInternals = reinterpret_cast(pa_acBasicFBVarsData); + + const CStringDictionary::TStringId *pnDataIds = cm_pstVarInternals->m_aunIntVarsDataTypeNames; + for(int i = 0; i < cm_pstVarInternals->m_nNumIntVars; ++i){ + createDataPoint(&pnDataIds, pa_acBasicFBVarsData); + pa_acBasicFBVarsData += sizeof(CIEC_ANY); + } + } + } + else{ + m_aoInternals = 0; + } +} + +CBasicFB::~CBasicFB(){ + if(0 != m_aoInternals){ + for(int i = 0; i < cm_pstVarInternals->m_nNumIntVars; ++i){ + getVarInternal(i)->~CIEC_ANY(); + } + } +} + +CIEC_ANY *CBasicFB::getVar(CStringDictionary::TStringId *paNameList, + unsigned int paNameListSize){ + CIEC_ANY *poRetVal = CFunctionBlock::getVar(paNameList, paNameListSize); + if((0 == poRetVal) && (1 == paNameListSize)){ + poRetVal = getInternalVar(*paNameList); + if(0 == poRetVal){ + //TODO consider if this can also be an string ID in a differnt way + if(!strcmp("$ECC", CStringDictionary::getInstance().get(*paNameList))){ + poRetVal = &m_nECCState; + } + } + } + return poRetVal; +} + +EMGMResponse CBasicFB::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse nRetVal = CFunctionBlock::changeFBExecutionState(pa_unCommand); + if((e_RDY == nRetVal) && (cg_nMGM_CMD_Reset == pa_unCommand)){ + m_nECCState = 0; + } + return nRetVal; +} + +CIEC_ANY *CBasicFB::getInternalVar(CStringDictionary::TStringId pa_nInternalName){ + CIEC_ANY *retVal = 0; + if(0 != cm_pstVarInternals){ + TPortId unVarId = + getPortId(pa_nInternalName, cm_pstVarInternals->m_nNumIntVars, cm_pstVarInternals->m_aunIntVarsNames); + if(cg_unInvalidPortId != unVarId){ + retVal = getVarInternal(unVarId); + } + } + return retVal; +} + diff --git a/src/core/basicfb.h b/src/core/basicfb.h new file mode 100644 index 000000000..554a0280f --- /dev/null +++ b/src/core/basicfb.h @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Gunnar Grabmair, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _BASICFB_H_ +#define _BASICFB_H_ + +#include "funcbloc.h" +#include "./datatypes/forte_uint.h" + +#ifndef FORTE_BASIC_FB_DATA_ARRAY //with this check we can overwrite this define in a platform specific file (e.g., config.h) + +/*! Define that adds the data array to a Basic FB + * May be overwritten by a platform specific version that adapts for example some alignment requirements + */ +#define FORTE_BASIC_FB_DATA_ARRAY(a_nNumEOs, a_nNumDIs, a_nNumDOs, a_nNumIntVars, a_nNumAdapters) \ + union{ \ + TForteByte m_anFBConnData[genFBConnDataSizeTemplate::value]; \ + };\ + union{ \ + TForteByte m_anFBVarsData[genBasicFBVarsDataSizeTemplate::value]; \ + }; + +#endif + +/*!\ingroup CORE + * \brief structure to hold the data needed for creating the internal vars + * + */ +struct SInternalVarsInformation{ + TPortId m_nNumIntVars; //!< Number of internal vars + const CStringDictionary::TStringId * const m_aunIntVarsNames; //!< List of the internalvarsnames + const CStringDictionary::TStringId * const m_aunIntVarsDataTypeNames; //!< List of the data type names for the internal vars +}; + +/*!\ingroup CORE + * + * \brief Class for handling firmware basic function blocks. + */ +class CBasicFB : public CFunctionBlock{ + public: + /*!\brief The main constructur for a basic function block. + */ + CBasicFB(CResource *pa_poSrcRes, + const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, + const SInternalVarsInformation *pa_pstVarInternals, + TForteByte *pa_acFBConnData, TForteByte *pa_acBasicFBVarsData); + virtual ~CBasicFB(); + + virtual CIEC_ANY* getVar(CStringDictionary::TStringId *paNameList, + unsigned int paNameListSize); + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); + + template + struct genBasicFBVarsDataSizeTemplate{ + enum { + value = ((sizeof(TDataConnectionPtr) + sizeof(CIEC_ANY)) * ta_nNumIntVars + + genFBVarsDataSizeTemplate::value) + }; + }; + + static size_t genBasicFBVarsDataSize(unsigned int pa_nNumDIs, unsigned int pa_nNumDOs, + unsigned int pa_nNumIntVars, unsigned int pa_nNumAdapters = 0){ + return ((sizeof(TDataConnectionPtr) + sizeof(CIEC_ANY)) * pa_nNumIntVars + + genFBVarsDataSize(pa_nNumDIs, pa_nNumDOs, pa_nNumAdapters)); + } + ; + + protected: + /*! \brief Get the internal variable with given number + * + * Attention this function will not perform any range checks on the pa_nVarIntNum parameter! + * @param pa_nVarIntNum number of the internal variable starting with 0 + * @return pointer to the internal variable + */ + CIEC_ANY *getVarInternal(unsigned int pa_nVarIntNum){ + return m_aoInternals + pa_nVarIntNum; + } + + CIEC_UINT m_nECCState; //! the current state of the ecc. start value is 0 = initial state id + const SInternalVarsInformation * const cm_pstVarInternals; //!< struct holding the information on the internal vars. + private: + /*!\brief Get the pointer to a internal variable of the basic FB. + * + * \param pa_nInternalName StringId of the internal variable name. + * \return Pointer to the internal variable or 0. + */ + CIEC_ANY *getInternalVar(CStringDictionary::TStringId pa_nInternalName); + + CIEC_ANY *m_aoInternals; //!< A list of pointers to the internal variables. +}; + +#endif /*_BASICFB_H_*/ diff --git a/src/core/cfb.cpp b/src/core/cfb.cpp new file mode 100644 index 000000000..559faf9c1 --- /dev/null +++ b/src/core/cfb.cpp @@ -0,0 +1,351 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gunnar Grabmaier, Gerhard Ebenhofer, + * Martin Melik Merkumians, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "cfb.h" +#include "adapter.h" +#include "resource.h" +#include "utils/criticalregion.h" + +CCompositeFB::CCompositeFB(CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, const SCFB_FBNData * const pa_cpoFBNData, + TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) : + CFunctionBlock(pa_poSrcRes, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData), + cm_cpoFBNData(pa_cpoFBNData){ + + createInternalFBs(); + + createEventConnections(); + createDataConnections(); + setParams(); + + //remove adapter-references for CFB + for(TForteUInt8 i = 0; i < pa_pstInterfaceSpec->m_nNumAdapters; i++){ + if(0 != m_apoAdapters){ + ((CAdapter*) m_apoAdapters[i])->setParentFB(0, 0); + } + } + +} + +CCompositeFB::~CCompositeFB(){ + //CTypeLib &roTypeLib(CTypeLib::getInstance()); + if(cm_cpoFBNData->m_nNumFBs){ + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumFBs; ++i){ + delete m_apoInternalFBs[i]; + } + delete[] m_apoInternalFBs; + } + if(cm_cpoFBNData->m_nNumEventConnections){ + //only delet the interface to internal event connections all other connections are managed by their source's FBs + for(unsigned int i = 0; i < m_pstInterfaceSpec->m_nNumEIs; ++i){ + delete mInterface2InternalEventCons[i]; + } + delete[] m_apoEventConnections; + delete[] mInterface2InternalEventCons; + } + if(cm_cpoFBNData->m_nNumDataConnections){ + delete[] m_apoDataConnections; + delete[] mIf2InDConns; + delete[] m_apoIn2IfDConns; + } +} + +bool CCompositeFB::connectDI(TPortId paDIPortId, CDataConnection *paDataCon){ + bool retVal = false; + + if(cgInternal2InterfaceMarker & paDIPortId){ + paDIPortId &= cgInternal2InterfaceRemovalMask; + if(paDIPortId < m_pstInterfaceSpec->m_nNumDOs){ + m_apoIn2IfDConns[paDIPortId] = paDataCon; + retVal = true; + } + } + else if(paDIPortId < m_pstInterfaceSpec->m_nNumDIs){ + bool needsCloning = (getDI(paDIPortId)->getDataTypeID() == CIEC_ANY::e_ANY); + retVal = CFunctionBlock::connectDI(paDIPortId, paDataCon); + if((true == retVal) && (true == needsCloning) && (0 != paDataCon) + && (0 != paDataCon->getValue())){ + //if internal connected update the connections data type and maybe internal further connection points + (mIf2InDConns + paDIPortId)->setValue(getDI(paDIPortId)); + (mIf2InDConns + paDIPortId)->cloneInputInterfaceValue(); + } + } + return retVal; +} + +bool CCompositeFB::configureGenericDO(TPortId paDOPortId, const CIEC_ANY &paRefValue){ + bool bRetVal = CFunctionBlock::configureGenericDO(paDOPortId, paRefValue); + if(true == bRetVal){ + if(0 != m_apoIn2IfDConns[paDOPortId]){ + //issue a reconfiguration attempt so that all connection end points in this connection are also correctly configured + m_apoIn2IfDConns[paDOPortId]->connectToCFBInterface(this, paDOPortId); + } + } + return bRetVal; +} + +EMGMResponse CCompositeFB::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse nRetVal = CFunctionBlock::changeFBExecutionState(pa_unCommand); + for(unsigned int i = 0; ((i < cm_cpoFBNData->m_nNumFBs) && (e_RDY == nRetVal)); ++i){ + if(m_apoInternalFBs[i]){ + nRetVal = m_apoInternalFBs[i]->changeFBExecutionState(pa_unCommand); + } + } + //Update FB parameters that maybe got overwritten by default values of the FB + if((cg_nMGM_CMD_Reset == pa_unCommand) && (e_IDLE == getState())){ + setParams(); + } + return nRetVal; +} + +#ifdef FORTE_SUPPORT_MONITORING + +CFunctionBlock *CCompositeFB::getFB(forte::core::TNameIdentifier::CIterator &paNameListIt){ + CFunctionBlock *retVal = 0; + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumFBs; ++i){ + if(m_apoInternalFBs[i]->getInstanceNameId() == *paNameListIt){ + if(paNameListIt.isLastEntry()){ + retVal = m_apoInternalFBs[i]; + } else { + //we are looking for a child of this fB + ++paNameListIt; + retVal = m_apoInternalFBs[i]->getFB(paNameListIt); + } + } + } + if(0 == retVal){ + //check if it is an adapter of the function block + retVal = CFunctionBlock::getFB(paNameListIt); + } + return retVal; +} + +#endif + +CIEC_ANY *CCompositeFB::getVar(CStringDictionary::TStringId *paNameList, + unsigned int paNameListSize){ + CIEC_ANY *retVal = 0; + + if(1 > paNameListSize){ + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumFBs; ++i){ + if(*paNameList == m_apoInternalFBs[i]->getInstanceNameId()){ + paNameList++; + paNameListSize--; + retVal = m_apoInternalFBs[i]->getVar(paNameList, paNameListSize); + break; + } + } + } + else{ + retVal = CFunctionBlock::getVar(paNameList, paNameListSize); + } + + return retVal; +} + +void CCompositeFB::executeEvent(int pa_nEIID){ + if(cgInternal2InterfaceMarker & pa_nEIID){ + sendInternal2InterfaceOutputEvent(static_cast(pa_nEIID + & cgInternal2InterfaceRemovalMask)); + } + else{ + if(pa_nEIID < m_pstInterfaceSpec->m_nNumEIs){ + if(0 != mInterface2InternalEventCons[pa_nEIID]){ + mInterface2InternalEventCons[pa_nEIID]->triggerEvent(*m_poInvokingExecEnv); + } + } + } +} + +void CCompositeFB::sendInternal2InterfaceOutputEvent(int pa_nEOID){ + //handle sampling of internal 2 interface data connections + if((pa_nEOID < m_pstInterfaceSpec->m_nNumEOs) && (0 != m_pstInterfaceSpec->m_anEOWithIndexes)){ + if(-1 != m_pstInterfaceSpec->m_anEOWithIndexes[pa_nEOID]){ + const TDataIOID *poEOWithStart = + &(m_pstInterfaceSpec->m_anEOWith[m_pstInterfaceSpec->m_anEOWithIndexes[pa_nEOID]]); + + // TODO think on this lock + { + CCriticalRegion criticalRegion(getResource().m_oResDataConSync); + for(int i = 0; poEOWithStart[i] != 255; ++i){ + if(0 != m_apoIn2IfDConns[poEOWithStart[i]]){ + m_apoIn2IfDConns[poEOWithStart[i]]->readData(getDO(poEOWithStart[i])); + } + } + } + } + } + + sendOutputEvent(pa_nEOID); +} + +void CCompositeFB::createInternalFBs(){ + if(cm_cpoFBNData->m_nNumFBs){ + m_apoInternalFBs = new TFunctionBlockPtr[cm_cpoFBNData->m_nNumFBs]; + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumFBs; ++i){ + m_apoInternalFBs[i] = + CTypeLib::createFB(cm_cpoFBNData->m_pstFBInstances[i].m_nFBInstanceNameId, cm_cpoFBNData->m_pstFBInstances[i].m_nFBTypeNameId, getResourcePtr()); +#ifdef FORTE_SUPPORT_MONITORING + m_apoInternalFBs[i]->setContainer(this); +#endif + } + } +} + +void CCompositeFB::createEventConnections(){ + if(0 != cm_cpoFBNData->m_nNumEventConnections){ + prepareIf2InEventCons(); + m_apoEventConnections = new CEventConnection *[cm_cpoFBNData->m_nNumEventConnections]; //TODO for a major revison this list could be ommited but requires a change in the faned out connections + const SCFB_FBConnectionData *cpstCurrentConn; + CFunctionBlock *poSrcFB; + CFunctionBlock *poDstFB; + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumEventConnections; ++i){ + cpstCurrentConn = &(cm_cpoFBNData->m_pstEventConnections[i]); + //FIXME implement way to inform FB creator that creation failed + poSrcFB = getFunctionBlock(cpstCurrentConn->m_nSrcFBNum); + poDstFB = getFunctionBlock(cpstCurrentConn->m_nDstFBNum); + + if((0 != poSrcFB) && (0 != poDstFB)){ + if(this == poSrcFB){ + m_apoEventConnections[i] = + mInterface2InternalEventCons[getEIID(cpstCurrentConn->m_nSrcId)]; + } + else{ + m_apoEventConnections[i] = poSrcFB->getEOConection(cpstCurrentConn->m_nSrcId); + } + establishConnection(m_apoEventConnections[i], poDstFB, cpstCurrentConn->m_nDstId); + } + else{ + DEVLOG_ERROR("Could not create event connection in CFB"); + } + } + //now handle the fanned out connections + const SCFB_FBFannedOutConnectionData *cpstCurrentFannedConn; + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumFannedOutEventConnections; ++i){ + cpstCurrentFannedConn = &(cm_cpoFBNData->m_pstFannedOutEventConnections[i]); + poDstFB = getFunctionBlock(cpstCurrentFannedConn->m_nDstFBNum); + establishConnection(m_apoEventConnections[cpstCurrentFannedConn->m_nConnectionNum], + poDstFB, cpstCurrentFannedConn->m_nDstId); + } + } +} + +void CCompositeFB::prepareIf2InEventCons(){ + if(0 != m_pstInterfaceSpec->m_nNumEIs){ + mInterface2InternalEventCons = new TEventConnectionPtr[m_pstInterfaceSpec->m_nNumEIs]; + //FIXME find a way to avoid that each connection has to be allocated separately + for(TPortId i = 0; i < m_pstInterfaceSpec->m_nNumEIs; i++){ + mInterface2InternalEventCons[i] = new CEventConnection(this, i); + } + } +} + +void CCompositeFB::establishConnection(CConnection *paCon, CFunctionBlock *paDstFb, + CStringDictionary::TStringId paDstNameId){ + if(this == paDstFb){ + paCon->connectToCFBInterface(paDstFb, paDstNameId); + } + else{ + paCon->connect(paDstFb, paDstNameId); + } +} + +void CCompositeFB::createDataConnections(){ + if(cm_cpoFBNData->m_nNumDataConnections){ + if(m_pstInterfaceSpec->m_nNumDIs){ + prepareIf2InDataCons(); + } + if(m_pstInterfaceSpec->m_nNumDOs){ + m_apoIn2IfDConns = new CDataConnection *[m_pstInterfaceSpec->m_nNumDOs]; + for(TPortId i = 0; i < m_pstInterfaceSpec->m_nNumDOs; i++){ + m_apoIn2IfDConns[i] = 0; + } + } + + m_apoDataConnections = new CDataConnection *[cm_cpoFBNData->m_nNumDataConnections]; + const SCFB_FBConnectionData *cpstCurrentConn; + CFunctionBlock *poSrcFB; + CFunctionBlock *poDstFB; + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumDataConnections; ++i){ + cpstCurrentConn = &(cm_cpoFBNData->m_pstDataConnections[i]); + //FIXME implement way to inform FB creator that creation failed + poSrcFB = getFunctionBlock(cpstCurrentConn->m_nSrcFBNum); + poDstFB = getFunctionBlock(cpstCurrentConn->m_nDstFBNum); + + if((0 != poSrcFB) && (0 != poDstFB)){ + if(this == poSrcFB){ + m_apoDataConnections[i] = &(mIf2InDConns[getDIID(cpstCurrentConn->m_nSrcId)]); + } + else{ + m_apoDataConnections[i] = poSrcFB->getDOConnection(cpstCurrentConn->m_nSrcId); + } + establishConnection(m_apoDataConnections[i], poDstFB, cpstCurrentConn->m_nDstId); + } + else{ + DEVLOG_ERROR("Could not create event connection in CFB"); + } + } + //now handle the fanned out connections + const SCFB_FBFannedOutConnectionData *cpstCurrentFannedConn; + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumFannedOutDataConnections; ++i){ + cpstCurrentFannedConn = &(cm_cpoFBNData->m_pstFannedOutDataConnections[i]); + poDstFB = getFunctionBlock(cpstCurrentFannedConn->m_nDstFBNum); + + establishConnection(m_apoDataConnections[cpstCurrentFannedConn->m_nConnectionNum], + poDstFB, cpstCurrentFannedConn->m_nDstId); + } + } +} + +void CCompositeFB::prepareIf2InDataCons(){ + mIf2InDConns = new CInterface2InternalDataConnection[m_pstInterfaceSpec->m_nNumDIs]; + for(TPortId i = 0; i < m_pstInterfaceSpec->m_nNumDIs; i++){ + (mIf2InDConns + i)->setSource(this, i); + } +} + +void CCompositeFB::setParams(){ + const SCFB_FBParameter *pstCurrentParam; + for(unsigned int i = 0; i < cm_cpoFBNData->m_nNumParams; ++i){ + pstCurrentParam = &(cm_cpoFBNData->m_pstParams[i]); + CIEC_ANY *poDI = + m_apoInternalFBs[pstCurrentParam->m_nFBNum]->getDataInput(pstCurrentParam->m_nDINameID); + if(0 != poDI){ + poDI->fromString(pstCurrentParam->m_acParamValue); + } + else{ + DEVLOG_ERROR("Could not get date input for setting a parameter"); + } + } +} + +CFunctionBlock *CCompositeFB::getFunctionBlock(int pa_nFBNum){ + CFunctionBlock *poRetVal = 0; + if(-1 == pa_nFBNum){ + poRetVal = this; + } + else if(0 <= pa_nFBNum){ + if(scm_nAdapterMarker == (scm_nAdapterMarker & pa_nFBNum)){ + pa_nFBNum &= scm_nAdapterFBRange; + if(pa_nFBNum < m_pstInterfaceSpec->m_nNumAdapters){ + poRetVal = m_apoAdapters[pa_nFBNum]; + } + } + else{ + if(static_cast(pa_nFBNum) < cm_cpoFBNData->m_nNumFBs){ + poRetVal = m_apoInternalFBs[pa_nFBNum]; + } + } + } + return poRetVal; +} diff --git a/src/core/cfb.h b/src/core/cfb.h new file mode 100644 index 000000000..9ed5743cf --- /dev/null +++ b/src/core/cfb.h @@ -0,0 +1,161 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gunnar Grabmaier, Gerhard Ebenhofer, + * Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _CFB_H_ +#define _CFB_H_ + +#include "funcbloc.h" +#include "if2indco.h" + +struct SCFB_FBInstanceData { + CStringDictionary::TStringId m_nFBInstanceNameId; + CStringDictionary::TStringId m_nFBTypeNameId; +}; + +struct SCFB_FBConnectionData { + CStringDictionary::TStringId m_nSrcId; + int m_nSrcFBNum; + CStringDictionary::TStringId m_nDstId; + int m_nDstFBNum; +}; + +/*! \ingroup CORE + * \brief Connection data for a fanned out connection of a composite's FB network + * + * As fanned out connections are attached together they need different data than + * the first connection. + */ +struct SCFB_FBFannedOutConnectionData { + int m_nConnectionNum; //!(g_nStringIdNextFreeId / 2)); + eRetVal = queryTypeList(pa_oCommand, CTypeLib::getFBLibStart()); + break; + case cg_nMGM_CMD_QUERY_DTTypes: + eRetVal = queryTypeList(pa_oCommand, CTypeLib::getDTLibStart()); + break; + case cg_nMGM_CMD_QUERY_AdapterTypes: + eRetVal = queryTypeList(pa_oCommand, CTypeLib::getAdapterLibStart()); + break; +#endif + + + default: + eRetVal = e_UNSUPPORTED_CMD; + break; + } + } + return eRetVal; +} + + +EMGMResponse C61499Class1ObjectHandler::deleteConnection(SManagementCMD &paCommand){ + EMGMResponse retval = e_NO_SUCH_OBJECT; + + CFunctionBlock *srcFB = static_cast(&m_roHandlerOwner); + if(1 < paCommand.mFirstParamArraySize){ + //this is not a connection from the resource interface + srcFB = m_roHandlerOwner.getFB(paCommand.mFirstParam, paCommand.mFirstParamArraySize); + } + CFunctionBlock *dstFB = m_roHandlerOwner.getFB(paCommand.mSecondParam, paCommand.mSecondParamArraySize); + + if((0 != srcFB) && (0 != dstFB)){ // check if the named fbs are existing in this resource + TConnectionList::Iterator itRunner = m_lstpoConnectionList.begin(); + TConnectionList::Iterator itRefNode = m_lstpoConnectionList.end(); + + //TODO workaround till connection is updated to new mgm structure + TConnectionID nSrcId; + if(srcFB == &m_roHandlerOwner){ + nSrcId = paCommand.mFirstParam[1]; + }else{ + nSrcId = CConnection::genConPortId(paCommand.mFirstParam[0], paCommand.mFirstParam[1]); + } + TConnectionID nDestId = CConnection::genConPortId(paCommand.mSecondParam[0], paCommand.mSecondParam[1]); + + while(itRunner != m_lstpoConnectionList.end()){ + if((*itRunner)->getSourceId() == nSrcId){ + CConnection *poConToDel = *itRunner; + retval = poConToDel->disconnect(nDestId, *srcFB, *dstFB); + + if(poConToDel->isEmpty()){ + //this was the last fan of the connection remove it from the list + CTypeLib::deleteConnection(poConToDel); // if yes delete the connection as it point nowhere + if(itRefNode == m_lstpoConnectionList.end()){ + m_lstpoConnectionList.pop_front(); + } + else{ + m_lstpoConnectionList.eraseAfter(itRefNode); + } + } + + break; + } + + itRefNode = itRunner; + ++itRunner; + } + } + return retval; +} + +EMGMResponse C61499Class1ObjectHandler::createConnection(SManagementCMD &paCommand){ + EMGMResponse retval = e_NO_SUCH_OBJECT; + + CFunctionBlock *srcFB = static_cast(&m_roHandlerOwner); + if(1 < paCommand.mFirstParamArraySize){ + //this is not a connection from the resource interface + srcFB = m_roHandlerOwner.getFB(paCommand.mFirstParam, paCommand.mFirstParamArraySize); + } + CFunctionBlock *dstFB = m_roHandlerOwner.getFB(paCommand.mSecondParam, paCommand.mSecondParamArraySize); + + CConnection *newConnection = 0; + if((0 != srcFB) && (0 != dstFB)){ // check if the named fbs are existing in this resource + //TODO workaround till connection is updated to new mgm structure + TConnectionID nSrcId; + if(srcFB == &m_roHandlerOwner){ + nSrcId = paCommand.mFirstParam[0]; + }else{ + nSrcId = CConnection::genConPortId(paCommand.mFirstParam[0], paCommand.mFirstParam[1]); + } + TConnectionID nDestId = CConnection::genConPortId(paCommand.mSecondParam[0], paCommand.mSecondParam[1]); + + newConnection = getConnection(nSrcId); //try to find if there is already a connection with given source + + if(0 == newConnection){ + // there is no connection with given source try to create a new one + CStringDictionary::TStringId unOutNameId = CConnection::extractPortNameId(nSrcId); + if(srcFB == static_cast(&m_roHandlerOwner)){ + if(0 != m_roHandlerOwner.getDataInput(unOutNameId)){ + newConnection = new CInterface2InternalDataConnection(nSrcId, *srcFB, nDestId, *dstFB); + } + } + else{ + if(cg_nInvalidEventID != srcFB->getEOID(unOutNameId)){ + newConnection = new CEventConnection(nSrcId, *srcFB, nDestId, *dstFB); // it was an event connection to create + } + else{ + if(0 != srcFB->getDataOutput(unOutNameId)){ + newConnection = new CDataConnection(nSrcId, *srcFB, nDestId, *dstFB); // it was an data connection to create + } + else{ + if(0 != srcFB->getAdapter(unOutNameId)){ + newConnection = new CAdapterConnection(nSrcId, *srcFB, nDestId, *dstFB); + } + } + } + } + if(0 != newConnection){ + if(newConnection->isEmpty()){ //Check if it was the only destination this connection had + delete newConnection; // if yes delete the connection as it point nowhere + } + else{ + retval = e_RDY; + m_lstpoConnectionList.push_back(newConnection); + } + } + } + else{ // Connection exists, Dest. added to the Dest.-List + retval = newConnection->connectFannedOut(nDestId, *srcFB, *dstFB); //establish the connection + } + } + return retval; +} + +CConnection* C61499Class1ObjectHandler::getConnection(TConnectionID pa_nSrcId){ + CConnection* pRetVal = 0; + for(TConnectionList::Iterator it = m_lstpoConnectionList.begin(); it != m_lstpoConnectionList.end(); ++it){ + if(pa_nSrcId == (*(*it)).getSourceId()){ + pRetVal = (*it); + break; + } + } + return pRetVal; +} + +EMGMResponse C61499Class1ObjectHandler::deleteWholeFBNetwork(){ + //changeFBExecutionState(cg_nMGM_CMD_Kill); + + for(TConnectionList::Iterator itRunner(m_lstpoConnectionList.begin()); itRunner != m_lstpoConnectionList.end(); ++itRunner){ + CTypeLib::deleteConnection(*itRunner); + } + m_lstpoConnectionList.clearAll(); + + for(TObjInstanceList::Iterator itRunner(m_lstpoObjectInstanceList.begin()); itRunner != m_lstpoObjectInstanceList.end(); ++itRunner){ + CTypeLib::deleteFB(*itRunner); + } + m_lstpoObjectInstanceList.clearAll(); + return e_RDY; +} + + + +#ifdef FORTE_SUPPORT_QUERY_CMD +EMGMResponse C61499Class1ObjectHandler::executeQueryReq(SManagementCMD &paCommand){ //TConnectionID pa_nSrcId, TConnectionID &pa_nDestId, char *pa_pacResponse) { + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + TObjInstanceList::Iterator itRunner = m_lstpoObjectInstanceList.begin(); + + paCommand.m_oAdditionalParams.clear(); + + if(CStringDictionary::scm_nInvalidStringId == paCommand.mFirstParam[0]){ + if(CStringDictionary::scm_nInvalidStringId == paCommand.mSecondParam[0]){ + //fetch all fb instancenames of all types and return them + for(; itRunner != m_lstpoObjectInstanceList.end(); ++itRunner){ + paCommand.m_oAdditionalParams.append((*itRunner)->getInstanceName()); + paCommand.m_oAdditionalParams.append(",", 1); + } + eRetVal = e_RDY; + } + else{ + //fetch all fb instancenames of the defined type and return them + CTypeLib::CTypeEntry* FBTypes = CTypeLib::getFBLibStart(); + bool bFoundType = false; + do{ + if(FBTypes->getTypeNameId() == paCommand.mSecondParam[0]){ + bFoundType = true; + break; + } + FBTypes = FBTypes->m_poNext; + } while(0 != FBTypes); + + if(!bFoundType){ + eRetVal = e_UNSUPPORTED_TYPE; + } + else{ + for(; itRunner != m_lstpoObjectInstanceList.end(); ++itRunner){ + if((*itRunner)->getFBTypeId() == paCommand.mSecondParam[0]){ + paCommand.m_oAdditionalParams.append((*itRunner)->getInstanceName()); + paCommand.m_oAdditionalParams.append(",", 1); + } + } + eRetVal = e_RDY; + } + } + if(!paCommand.m_oAdditionalParams.empty()){ + paCommand.m_oAdditionalParams.assign(paCommand.m_oAdditionalParams.getValue(), static_cast(paCommand.m_oAdditionalParams.length() - 1)); + } + } + else{ // Query whether FB instancename exists + FB Type + if(CStringDictionary::scm_nInvalidStringId == paCommand.mSecondParam[0]){ + const char *acSourceName = CStringDictionary::getInstance().get(paCommand.mFirstParam[0]); + for(; itRunner != m_lstpoObjectInstanceList.end(); ++itRunner){ + paCommand.m_oAdditionalParams.assign((*itRunner)->getInstanceName(), static_cast(strlen((*itRunner)->getInstanceName()))); + if(!strcmp(paCommand.m_oAdditionalParams.getValue(), acSourceName)){ + //pa_oCommand.m_nSecondParam = (*itRunner)->getFBTypeId(); + paCommand.m_oAdditionalParams.clear(); //clear string (held FB-Name) + paCommand.m_oAdditionalParams.append(CStringDictionary::getInstance().get(static_cast((*itRunner)->getFBTypeId()))); + eRetVal = e_RDY; + break; + } + } + + if(eRetVal != e_RDY){ + paCommand.m_oAdditionalParams.clear(); //clear string (held FB-Name) + eRetVal = e_NO_SUCH_OBJECT; + } + } + else{ //type and instance-name given -> return status + const char *acSourceName = CStringDictionary::getInstance().get(static_cast(paCommand.mFirstParam[0])); + for(; itRunner != m_lstpoObjectInstanceList.end(); ++itRunner){ + paCommand.m_oAdditionalParams.assign((*itRunner)->getInstanceName(), static_cast(strlen((*itRunner)->getInstanceName()))); + if(!strcmp(paCommand.m_oAdditionalParams.getValue(), acSourceName)){ + paCommand.m_oAdditionalParams.clear(); //clear string (held FB-Name) + if(paCommand.mSecondParam[0] == (*itRunner)->getFBTypeId()){ + switch ((*itRunner)->getState()){ + case CFunctionBlock::e_IDLE: + paCommand.m_oAdditionalParams.append("IDLE", 4); + break; + case CFunctionBlock::e_RUNNING: + paCommand.m_oAdditionalParams.append("RUNNING", 7); + break; + case CFunctionBlock::e_STOPPED: + paCommand.m_oAdditionalParams.append("STOPPED", 7); + break; + case CFunctionBlock::e_KILLED: + paCommand.m_oAdditionalParams.append("KILLED", 6); + break; + default: + break; + } + eRetVal = e_RDY; + } + else{ + eRetVal = e_NO_SUCH_OBJECT; + } + break; + } + } + + if(eRetVal != e_RDY){ + eRetVal = e_NO_SUCH_OBJECT; + } + } + } + return eRetVal; +} + +EMGMResponse C61499Class1ObjectHandler::executeQueryCon(SManagementCMD &paCommand){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + TConnectionList::Iterator itRunner(m_lstpoConnectionList.begin()); + + paCommand.m_oAdditionalParams.reserve(90); + paCommand.m_oAdditionalParams.clear(); + + CIEC_STRING oTempString; + oTempString.reserve(50); + oTempString.clear(); + + if(CStringDictionary::scm_nInvalidStringId == paCommand.mFirstParam[0]){ + if(CStringDictionary::scm_nInvalidStringId == paCommand.mSecondParam[0]){ // both parameters are * + + for(; itRunner != m_lstpoConnectionList.end(); ++itRunner){ + oTempString.clear(); + oTempString.append(CStringDictionary::getInstance().get(CConnection::extractFBNameId((*itRunner)->getSourceId()))); + oTempString.append(".", 1); + oTempString.append(CStringDictionary::getInstance().get(CConnection::extractPortNameId((*itRunner)->getSourceId()))); + + CSinglyLinkedList::Iterator end = ((*itRunner)->getDestinationIds().end()); + for(CSinglyLinkedList::Iterator itDestRunner = ((*itRunner)->getDestinationIds().begin()); itDestRunner != end; ++itDestRunner){ + paCommand.m_oAdditionalParams.append("\n", 5); + } + } + eRetVal = e_RDY; + } + else{ //only first parameter is * + + for(; itRunner != m_lstpoConnectionList.end(); ++itRunner){ + oTempString.clear(); + oTempString.append(CStringDictionary::getInstance().get(CConnection::extractFBNameId((*itRunner)->getSourceId()))); + oTempString.append(".", 1); + oTempString.append(CStringDictionary::getInstance().get(CConnection::extractPortNameId((*itRunner)->getSourceId()))); + + CSinglyLinkedList::Iterator end = (*itRunner)->getDestinationIds().end(); + for(CSinglyLinkedList::Iterator itDestRunner = ((*itRunner)->getDestinationIds().begin()); itDestRunner != end; ++itDestRunner){ + if(*itDestRunner == paCommand.mSecondParam[0]){ + paCommand.m_oAdditionalParams.append(oTempString.getValue(), oTempString.length()); + paCommand.m_oAdditionalParams.append(",", 1); + break; + } + } + } + eRetVal = e_RDY; + } + } + else{ //first parameter is != * + + if(CStringDictionary::scm_nInvalidStringId == paCommand.mSecondParam[0]){ // only second parameter is * + for(; itRunner != m_lstpoConnectionList.end(); ++itRunner){ + if((*itRunner)->getSourceId() == paCommand.mFirstParam[0]){ + CSinglyLinkedList::Iterator end = (*itRunner)->getDestinationIds().end(); + for(CSinglyLinkedList::Iterator itDestRunner = (*itRunner)->getDestinationIds().begin(); itDestRunner != end; ++itDestRunner){ + paCommand.m_oAdditionalParams.append(CStringDictionary::getInstance().get(CConnection::extractFBNameId(*itDestRunner))); + paCommand.m_oAdditionalParams.append(".", 1); + paCommand.m_oAdditionalParams.append(CStringDictionary::getInstance().get(CConnection::extractPortNameId(*itDestRunner))); + paCommand.m_oAdditionalParams.append(",", 1); + } + break; // all destinations of this connection are included + } + } + eRetVal = e_RDY; + } + else{ //both parameters are != 0 + for(; itRunner != m_lstpoConnectionList.end(); ++itRunner){ + if((*itRunner)->getSourceId() == paCommand.mFirstParam[0]){ + CSinglyLinkedList::Iterator end = (*itRunner)->getDestinationIds().end(); + for(CSinglyLinkedList::Iterator itDestRunner = (*itRunner)->getDestinationIds().begin(); itDestRunner != end; ++itDestRunner){ + if((*itDestRunner) == paCommand.mSecondParam[0]){ + eRetVal = e_RDY; + break; // all destinations of this connection are included + } + } + if(e_RDY == eRetVal){ + break; + } + } + } + } + } + + if(!paCommand.m_oAdditionalParams.empty()){ + paCommand.m_oAdditionalParams.assign(paCommand.m_oAdditionalParams.getValue(), static_cast(paCommand.m_oAdditionalParams.length() - 1)); + } + + return eRetVal; +} + +EMGMResponse C61499Class1ObjectHandler::queryTypeList(SManagementCMD &pa_oCommand, CTypeLib::CTypeEntry * pa_LibTypeListStart){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + + pa_oCommand.m_oAdditionalParams.clear(); + + CTypeLib::CTypeEntry *poToFirst = pa_LibTypeListStart; + if(poToFirst != 0){ + pa_oCommand.m_oAdditionalParams.append(CStringDictionary::getInstance().get(((CTypeLib::CTypeEntry *) poToFirst)->getTypeNameId())); + while(poToFirst->m_poNext != 0){ + poToFirst = poToFirst->m_poNext; + pa_oCommand.m_oAdditionalParams.append(",", 1); + pa_oCommand.m_oAdditionalParams.append(CStringDictionary::getInstance().get(((CTypeLib::CTypeEntry *) poToFirst)->getTypeNameId())); + } + eRetVal = e_RDY; + } + return eRetVal; +} + +EMGMResponse C61499Class1ObjectHandler::queryTypeVersion(TForteUInt32, char*){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + return eRetVal; +} + +#endif + diff --git a/src/core/class1objhand.h b/src/core/class1objhand.h new file mode 100644 index 000000000..27c541d97 --- /dev/null +++ b/src/core/class1objhand.h @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Gerhard Ebenhofer, Ingo Hegny, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _CLASS1OBJHAND_H_ +#define _CLASS1OBJHAND_H_ + +#include "stringdict.h" +#include "funcbloc.h" +#include "conn.h" +#include "fortelist.h" +#include "mgmcmdstruct.h" + +/**\ingroup CORE + *Class handling all management commands and handling created objects like, FBs, Resources, Connections,... + * + */ +class C61499Class1ObjectHandler{ + public: + C61499Class1ObjectHandler(CResource& pa_roHandlerOwner); + + virtual ~C61499Class1ObjectHandler(); + + /*!\brief Execute the given management command + * + * Evaluates the m_sDestination parameter of the command if empty the resource tries + * to execute the management command if not it tries to apply the mgm command to a + * contained FB if possible. + * \param pa_oCommand internal representation of the management command + * \return response of the MGMCommand execution as defined in IEC 61499 + */ + virtual EMGMResponse executeMGMCommand(SManagementCMD &pa_oCommand); + + /*!\brief Create a new connection between source and destination + * + * @param pa_nSrcId ID of source of the connection fb.output + * @param pa_nDestId ID of destination of the connection fb.input + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse deleteConnection(SManagementCMD &paCommand); + +#ifdef FORTE_SUPPORT_QUERY_CMD + EMGMResponse queryTypeList(SManagementCMD &paCommand, CTypeLib::CTypeEntry * pa_LibTypeListStart); + EMGMResponse queryTypeVersion(TForteUInt32 pa_nSource, char* pa_sValue); + + /*!\brief Read a parameter value from a given FB + * + * @param pa_oCommand Structure including management-command and response + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse executeQueryReq(SManagementCMD &paCommand); + + /*! \brief query connections + * + * @param pa_oCommand Structure including management-command and response + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse executeQueryCon(SManagementCMD &paCommand); +#endif + + + /*!\brief check if there exists an connection with given source identifier in this resource + * + * \param pa_nSrcId source identifier of connection (FB.Output) + * \return pointer to connection if connection does not exist 0 + */ + CConnection* getConnection(TConnectionID pa_nSrcId); + + protected: + /** \brief Delete all FB instances + * + * @return e_RDY on success + */ + EMGMResponse deleteWholeFBNetwork(); + + /*! \brief Owner resource/device of the objecthandler + */ + CResource& m_roHandlerOwner; + + /*! \brief Type for storing the list of FB objects. + */ + + typedef CSinglyLinkedList TObjInstanceList; + /*! \brief List of the current instantiated FBs in this 61499 Object Handler (may also contain Resources). + * + */ + TObjInstanceList m_lstpoObjectInstanceList; + + /*! \brief Type for storing the list of connection. + */ + typedef CSinglyLinkedList TConnectionList; + + /*! \brief List of the current connections in this 61499 Object Handler. + */ + TConnectionList m_lstpoConnectionList; + + private: + C61499Class1ObjectHandler(); +}; + +#endif diff --git a/src/core/cominfra/CMakeLists.txt b/src/core/cominfra/CMakeLists.txt new file mode 100644 index 000000000..d138c4fc7 --- /dev/null +++ b/src/core/cominfra/CMakeLists.txt @@ -0,0 +1,29 @@ +################################################################################ + # Copyright (c) 2010-2014 fortiss, TU Wien ACIN and Profactor GmbH. + # All rights reserved. This program and the accompanying materials + # are made available under the terms of the Eclipse Public License v1.0 + # which accompanies this distribution, and is available at + # http://www.eclipse.org/legal/epl-v10.html + # + # Contributors: + # Alois Zoitl, Michael Hofmann + # - initial implementation and rework communication infrastructure + # Martin Melik-Merkumians, Monika Wenger + # - add raw communication layer for ONE STRING input and ONE STRING output + ################################################################################ + +############################################################################# +# Core +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +forte_add_sourcefile_h(comtypes.h comlayersmanager.h) +forte_add_sourcefile_hcpp(commfb comlayer) + +# Will be created in top-level-cmake-file +forte_add_sourcefile_with_path_cpp(${CMAKE_BINARY_DIR}/core/cominfra/comlayersmanager.cpp) # created file + +forte_add_network_layer(FBDK ON "fbdk" CFBDKASN1ComLayer fbdkasn1layer "Enable Forte Com FBDK") +forte_add_network_layer(ETH ON "ip" CIPComLayer ipcomlayer "Enable Forte Com Ethernet") +forte_add_network_layer(LOCAL ON "loc" CLocalComLayer localcomlayer "Enable Forte local communication") +forte_add_network_layer(RAW ON "raw" CRawDataComLayer rawdatacomlayer "Enable Forte raw communication") diff --git a/src/core/cominfra/comlayer.cpp b/src/core/cominfra/comlayer.cpp new file mode 100644 index 000000000..88d114c7e --- /dev/null +++ b/src/core/cominfra/comlayer.cpp @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2010-2014 fortiss, TU Wien ACIN and Profactor GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and rework communication infrastructure + * Michael Hofmann - rework communication infrastructure + *******************************************************************************/ +#include "comlayer.h" +#include "comlayersmanager.h" +#include "commfb.h" + +using namespace forte::com_infra; + +char *CComLayer::extractLayerIdAndParams(char *pa_acID, char **pa_pacParameter){ + char *acRunner = strchr(pa_acID, '['); + if(0 != acRunner){ + *acRunner = '\0'; + ++acRunner; + *pa_pacParameter = acRunner; + acRunner = strchr(acRunner, ']'); + if(0 != acRunner){ + *acRunner = '\0'; + ++acRunner; + + if('\0' != *acRunner){ + //this is not the end of the string + ++acRunner; //move the pointer beyond the separating '.' + } + } + } + return acRunner; +} + +CComLayer::CComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poComFB) : + m_eConnectionState(forte::com_infra::e_Disconnected), m_poTopLayer(pa_poUpperLayer), m_poBottomLayer(0), m_poFb(pa_poComFB){ + +} + +CComLayer::~CComLayer(){ + delete m_poBottomLayer; +} + +EComResponse CComLayer::openConnection(char *pa_acConnectionParams, char *pa_acRemainingConnectionID){ + EComResponse eRetVal = openConnection(pa_acConnectionParams); + if((!(scg_unComNegative & eRetVal)) && ('\0' != *pa_acRemainingConnectionID)){ + //There is a connection ID left + char *acRemainingConnectionID = extractLayerIdAndParams(pa_acRemainingConnectionID, &pa_acConnectionParams); + if('\0' != *pa_acRemainingConnectionID){ + if(m_poBottomLayer == 0){ + m_poBottomLayer = CComLayersManager::createCommunicationLayer(pa_acRemainingConnectionID, this, m_poFb); // create bottom layer + if(m_poBottomLayer == 0){ + eRetVal = e_InitInvalidId; + return eRetVal; + } + } + eRetVal = m_poBottomLayer->openConnection(pa_acConnectionParams, acRemainingConnectionID); + } + else{ + eRetVal = e_InitInvalidId; + } + } + + return eRetVal; +} + +EComResponse CComLayer::processInterrupt(){ + return e_Nothing; +} diff --git a/src/core/cominfra/comlayer.h b/src/core/cominfra/comlayer.h new file mode 100644 index 000000000..6c68b55f3 --- /dev/null +++ b/src/core/cominfra/comlayer.h @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2010-2014 fortiss, TU Wien ACIN and Profactor GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and rework communication infrastructure + * Michael Hofmann - rework communication infrastructure + * Ingo Hegny - fix doxygen-documentation inconsistencies + * Martin Melik-Merkumians - add serial communication layer for ONE input and ONE output + *******************************************************************************/ +#ifndef _COMLAYER_H_ +#define _COMLAYER_H_ + +#include "comtypes.h" + +namespace forte { + namespace com_infra { + + class CCommFB; + + class CComLayer{ + public: + virtual ~CComLayer(); + + /*!\brief Open the connection and create the whole communication stack + * + * This function will configure this layer and if necessary create necessary bottom layers. + * + * \param pa_acConnectionParams configuration data for this layer + * \param pa_acRemainingConnectionID layer ids configuration data of layers below this one + * if 0 or *pa_acRemainingConnectionID equals '0x00' than there is no + * further layer below this one. + * \return status of the opening process + * - e_InitOk of the opening process was successful + */ + EComResponse openConnection(char *pa_acConnectionParams, char *pa_acRemainingConnectionID); + + /*!\brief Close this layer. + * + * Implementations of this function should perform the actions necessary for closing the layer and than call + * the closeConnection() of the bottom layer. + */ + virtual void closeConnection() = 0; + + /*!\brief Take the given data and perform the necessary process for sending + * + * If necessary invoke bottom layer sendData functions. + * + * @param pa_pvData pointer to the data to be sent + * @param pa_unSize size of the data to be sent + * @return status of the sending process: + * - e_ProcessDataOk ... if sending process was successful + */ + virtual EComResponse sendData(void *pa_pvData, unsigned int pa_unSize) = 0; + + /*!\brief Take the given data and perform the necessary process for receiving data + * + * This function is called for processing the received data from bottom to top. Therefore + * if necessary invoke the top layer's receiveData function to hand on the processed data. + * + * @param pa_pvData pointer to the data received + * @param pa_unSize size of the data received + * @return status of the receiving process depends on if the layer is the bottom most layer: + * - Normal Layer: + * - e_ProcessDataOk ... if receiving process was successful + * - Bottom most layer + * - e_Nothing ... if the processing of the data does not require to send an external event to the FB + * - any other value requires that the ComFB is informed with an external event to further handle the received message + */ + virtual EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize) = 0; + + /*!\brief Finish to process the data received in a context outside the communication interrupt i.e. within the event chain of the ComFB. + * + * This function shall be used for finishing the data reception. + */ + virtual EComResponse processInterrupt(); + + + /*!\brief get the FB of this layer + */ + CCommFB *getCommFB(){ + return m_poFb; + } + + static char* extractLayerIdAndParams(char *pa_acID, char **pa_pacParameter); + + protected: + CComLayer(CComLayer* pa_poUpperLayer, CCommFB* pa_poComFB); + + EComConnectionState m_eConnectionState; + + CComLayer *m_poTopLayer; + CComLayer *m_poBottomLayer; + CCommFB *m_poFb; + private: + /*!\brief Configure the current layer and perform necessary means to setup the connection + * + * Depending on the layers functionality different things have to be performed here. + * This can range from doing nothing to establishing an TCP session. + * + * @param pa_acLayerParameter configuration data for this layer + * @return status of the opening process + * - e_InitOk of the opening process was successful + */ + virtual EComResponse openConnection(char *pa_acLayerParameter) = 0; + }; + + } +} + +#endif diff --git a/src/core/cominfra/comlayersmanager.cpp.in b/src/core/cominfra/comlayersmanager.cpp.in new file mode 100644 index 000000000..2c775b31c --- /dev/null +++ b/src/core/cominfra/comlayersmanager.cpp.in @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2010, 2011 ACIN and Profactor GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and rework communication infrastructure + * Ingo Hegny - moved encoding of adapter-event-ids to a single point + * Michael Hofmann - rework communication infrastructure + *******************************************************************************/ +#include +#include "comlayersmanager.h" +#include "commfb.h" +#include + +${LAYERMANAGER_INCLUDE} + +using namespace forte::com_infra; + +CComLayer* CComLayersManager::createCommunicationLayer(char *pa_acLayerIdentifier, CComLayer* pa_poUpperLayer, CCommFB * pa_poComFB){ + CComLayer* m_poNewLayer = 0; + ${LAYERMANAGER_INSTANCE} + + return m_poNewLayer; +} diff --git a/src/core/cominfra/comlayersmanager.h b/src/core/cominfra/comlayersmanager.h new file mode 100644 index 000000000..c260cd75e --- /dev/null +++ b/src/core/cominfra/comlayersmanager.h @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2011 TU Wien ACIN and Profactor GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and rework communication infrastructure + * Michael Hofmann - communication infrastructure based on layer + *******************************************************************************/ +#ifndef _COMLAYERSMANAGER_H_ +#define _COMLAYERSMANAGER_H_ + +#include "comtypes.h" + +namespace forte { + namespace com_infra { + + class CCommFB; + class CComLayer; + + /*!\brief Communication Layers Manager for communication with Server/Client and Publish/Subscriber + * + * The communication interface is separated into two part, the handler and the protocol + * The Hander is the interface for all function blocks which wants to communicate over + * a network. Every function block which wants to communicate has to be registered at the + * handler. A registration does not open any connection. Therefore the registration can be + * handled in the function block creation. The connection with a network is established with + * a INIT+ event. + * The protocol is a layered protocol-stack which has two interfaces. One for the communication + * with the upper layer and one with the underneath layer. The top layer is the network handler + * and the bottom layer is either the operating system or a protocol layer which is able to communicate + * directly with the network. + * The memory-allocation is always done by the underneath layer. Thus the upper layer can simple send + * data to a underlying layer. The underneath layer can notify the upper layer by calling the + * newDataAvailable-function. Then the upper layer has to get the data by calling the getDataPackage- + * function. The returned pointer has to be deleted by the upper layer. A smart-pointer like design + * is desirable. + */ + + class CComLayersManager{ + public: + static CComLayer* createCommunicationLayer(char *pa_acLayerIdentifier, CComLayer* pa_poUpperLayer, CCommFB * pa_poComFB); + + private: + CComLayersManager(void); + CComLayersManager(const CComLayersManager& pa_roVal); + }; + } +} +#endif diff --git a/src/core/cominfra/commfb.cpp b/src/core/cominfra/commfb.cpp new file mode 100644 index 000000000..713c06531 --- /dev/null +++ b/src/core/cominfra/commfb.cpp @@ -0,0 +1,345 @@ +/******************************************************************************* + * Copyright (c) 2006-2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Alois Zoitl, Michael Hofmann, Martin Melik Merkumians, + * Patrick Smejkal + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include +#include +#include "commfb.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "commfb_gen.cpp" +#endif +#include "../resource.h" +#include "comlayer.h" +#include "comlayersmanager.h" + +using namespace forte::com_infra; + +const CStringDictionary::TStringId CCommFB::scm_aunRequesterEventInputNameIds[2] = { g_nStringIdINIT, g_nStringIdREQ }; +const CStringDictionary::TStringId CCommFB::scm_aunRequesterEventOutputNameIds[2] = { g_nStringIdINITO, g_nStringIdCNF }; + +const CStringDictionary::TStringId CCommFB::scm_aunResponderEventInputNameIds[2] = { g_nStringIdINIT, g_nStringIdRSP }; +const CStringDictionary::TStringId CCommFB::scm_aunResponderEventOutputNameIds[2] = { g_nStringIdINITO, g_nStringIdIND }; + +const TForteInt16 CCommFB::scm_anEIWithIndexes[] = { 0, 3 }; +const TForteInt16 CCommFB::scm_anEOWithIndexes[] = { 0, 3, -1 }; + +const char * const CCommFB::scm_sResponseTexts[] = { "OK", "INVALID_ID", "TERMINATED", "INVALID_OBJECT", "DATA_TYPE_ERROR", "INHIBITED", "NO_SOCKET", "SEND_FAILED", "RECV_FAILED" }; + +CCommFB::CCommFB(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes, forte::com_infra::EComServiceType pa_eCommServiceType) : + CEventSourceFB(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0), m_eCommServiceType(pa_eCommServiceType), m_poTopOfComStack(0){ + setEventChainExecutor(getResource().getResourceEventExecution()); + m_unComInterruptQueueCount = 0; + m_nConfiguredFBTypeNameId = CStringDictionary::scm_nInvalidStringId; +} + +CCommFB::CCommFB(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, + TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData, forte::com_infra::EComServiceType pa_eCommServiceType) : + CEventSourceFB(pa_poSrcRes, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData), m_eCommServiceType(pa_eCommServiceType), m_poTopOfComStack(0){ + setEventChainExecutor(getResource().getResourceEventExecution()); + m_unComInterruptQueueCount = 0; + m_nConfiguredFBTypeNameId = CStringDictionary::scm_nInvalidStringId; +} + +CCommFB::~CCommFB(){ + closeConnection(); + + if(0 != m_pstInterfaceSpec){ + //Free the memory allocated for the interface + delete[] (m_pstInterfaceSpec->m_anEIWith); + delete[] (m_pstInterfaceSpec->m_anEOWith); + delete[] (m_pstInterfaceSpec->m_aunDINames); + delete[] (m_pstInterfaceSpec->m_aunDIDataTypeNames); + delete[] (m_pstInterfaceSpec->m_aunDONames); + delete[] (m_pstInterfaceSpec->m_aunDODataTypeNames); + } +} + +void CCommFB::executeEvent(int pa_nEIID){ + EComResponse eResp = e_Nothing; + + switch (pa_nEIID){ + case scm_nEventINITID: + if(true == QI()){ + eResp = openConnection(); + } + else{ + closeConnection(); + eResp = e_InitTerminated; + } + break; + case scm_nSendNotificationEventID: + if(true == QI()){ + if(m_eCommServiceType != e_Subscriber){ + if(0 != m_poTopOfComStack){ + eResp = m_poTopOfComStack->sendData(static_cast(getSDs()), m_pstInterfaceSpec->m_nNumDIs - 2); + if((eResp == e_ProcessDataOk) && (m_eCommServiceType != e_Publisher)){ + // client and server will not directly send a cnf/ind event + eResp = e_Nothing; + } + } + else{ + eResp = e_ProcessDataNoSocket; + } + } + } + else{ + eResp = e_ProcessDataInhibited; // we are not allowed to send data + } + break; + case cg_nExternalEventID: + eResp = receiveData(); + break; + default: + break; + } + + if(eResp & e_Terminated){ + if(m_eCommServiceType == e_Server){ + //servers will not send information on client termination and should silently start to listen again + eResp = e_Nothing; + } + else{ + //subscribers and clients will close the connection and inform the user + closeConnection(); + } + } + + if(e_Nothing != eResp){ + STATUS() = scm_sResponseTexts[eResp & 0xF]; + QO() = !(eResp & scg_unComNegative); + + if(scg_unINIT & eResp){ + sendOutputEvent(scm_nEventINITOID); + } + else{ + sendOutputEvent(scm_nReceiveNotificationEventID); + } + } +} + +bool CCommFB::configureFB(const char *pa_acConfigString){ + TIdentifier tempstring; + char *sParamA = 0; + char *sParamB = 0; + size_t inlength; + unsigned int i; + + TForteUInt8 nNumDIs; + CStringDictionary::TStringId* paun_DIDataTypeNames; + CStringDictionary::TStringId* paun_DINames; + TDataIOID* pan_EIWith; + + TForteUInt8 nNumDOs; + CStringDictionary::TStringId* paun_DODataTypeNames; + CStringDictionary::TStringId* paun_DONames; + TDataIOID* pan_EOWith; + + CStringDictionary::TStringId* paun_EINames; + CStringDictionary::TStringId* paun_EONames; + + TForteUInt8 nNumEIs = 2; + TForteUInt8 nNumEOs = 2; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + + memcpy(tempstring, pa_acConfigString, cg_nIdentifierLength); + tempstring[cg_nIdentifierLength] = '\0'; + inlength = strlen(tempstring); + for(i = 0; i < inlength - 1; i++){ // search first underscore + if(tempstring[i] == '_'){ + sParamA = sParamB = &(tempstring[i + 1]); + break; + } + } + if(sParamA != 0) // search for 2nd underscore + for(i = i + 1; i < inlength - 1; i++){ + if(tempstring[i] == '_'){ + tempstring[i] = '\0'; + sParamB = &(tempstring[i + 1]); + break; + } + } + + if(sParamB == 0) // no underscore found + return false; + + nNumDIs = 2; + nNumDOs = 2; + + if(forte::com_infra::e_DataInputs == (forte::com_infra::e_DataInputs & m_eCommServiceType)){ + //TODO: Check range of sParamA + nNumDIs = static_cast(nNumDIs + forte::core::util::strtol(sParamA, 0, 10)); + paun_DIDataTypeNames = new CStringDictionary::TStringId[nNumDIs]; + paun_DINames = new CStringDictionary::TStringId[nNumDIs]; + pan_EIWith = new TDataIOID[nNumDIs - 2 + 6]; + + generateGenericDataPointArrays("SD_", &(paun_DIDataTypeNames[2]), &(paun_DINames[2]), nNumDIs - 2); + } + else{ + paun_DIDataTypeNames = new CStringDictionary::TStringId[nNumDIs]; + paun_DINames = new CStringDictionary::TStringId[nNumDIs]; + pan_EIWith = new TDataIOID[6]; // = m_pstInterfaceSpec->m_nNumDIs - 2 + 6 + } + + pan_EIWith[0] = 0; + pan_EIWith[1] = 1; + pan_EIWith[2] = 255; + pan_EIWith[3] = 0; + pan_EIWith[4] = 1; + + for(i = 0; i < nNumDIs - 2U; i++){ + pan_EIWith[i + 5U] = static_cast(i + 2U); + } + pan_EIWith[i + 5] = 255; + + paun_DIDataTypeNames[0] = g_nStringIdBOOL; + paun_DINames[0] = g_nStringIdQI; +#ifdef FORTE_USE_WSTRING_DATATYPE + paun_DIDataTypeNames[1] = g_nStringIdWSTRING; +#else + paun_DIDataTypeNames[1] = g_nStringIdSTRING; +#endif + paun_DINames[1] = g_nStringIdID; + + if(forte::com_infra::e_DataOutputs == (forte::com_infra::e_DataOutputs & m_eCommServiceType)){ + //TODO: Check range of sParamA + nNumDOs = static_cast(nNumDOs + forte::core::util::strtol(sParamB, 0, 10)); + paun_DODataTypeNames = new CStringDictionary::TStringId[nNumDOs]; + paun_DONames = new CStringDictionary::TStringId[nNumDOs]; + pan_EOWith = new TDataIOID[nNumDOs - 2 + 6]; + + generateGenericDataPointArrays("RD_", &(paun_DODataTypeNames[2]), &(paun_DONames[2]), nNumDOs - 2); + } + else{ + paun_DODataTypeNames = new CStringDictionary::TStringId[nNumDOs]; + paun_DONames = new CStringDictionary::TStringId[nNumDOs]; + pan_EOWith = new TDataIOID[6]; + } + + pan_EOWith[0] = 0; + pan_EOWith[1] = 1; + pan_EOWith[2] = 255; + pan_EOWith[3] = 0; + pan_EOWith[4] = 1; + + for(i = 0; i < nNumDOs - 2U; i++){ + pan_EOWith[i + 5] = static_cast(i + 2); + } + pan_EOWith[i + 5] = 255; + + paun_DODataTypeNames[0] = g_nStringIdBOOL; + paun_DONames[0] = g_nStringIdQO; +#ifdef FORTE_USE_WSTRING_DATATYPE + paun_DODataTypeNames[1] = g_nStringIdWSTRING; +#else + paun_DODataTypeNames[1] = g_nStringIdSTRING; +#endif + paun_DONames[1] = g_nStringIdSTATUS; + + if(forte::com_infra::e_Requester == (forte::com_infra::e_Requester & m_eCommServiceType)){ + paun_EINames = const_cast(scm_aunRequesterEventInputNameIds); + paun_EONames = const_cast(scm_aunRequesterEventOutputNameIds); + } + else{ + if(forte::com_infra::e_Responder == (forte::com_infra::e_Responder & m_eCommServiceType)){ + paun_EINames = const_cast(scm_aunResponderEventInputNameIds); + paun_EONames = const_cast(scm_aunResponderEventOutputNameIds); + } + } + + setupFBInterface(new SFBInterfaceSpecforGenerics(nNumEIs, const_cast(paun_EINames), const_cast(pan_EIWith), scm_anEIWithIndexes, nNumEOs, const_cast(paun_EONames), const_cast(pan_EOWith), scm_anEOWithIndexes, nNumDIs, const_cast(paun_DINames), const_cast(paun_DIDataTypeNames), nNumDOs, const_cast(paun_DONames), const_cast(paun_DODataTypeNames)), new TForteByte[genFBConnDataSize(nNumEOs, nNumDIs, nNumDOs)], new TForteByte[genFBVarsDataSize(nNumDIs, nNumDOs)], true //we want that the FB will delete the two data arrays + ); + return true; +} + +EComResponse CCommFB::openConnection(){ + EComResponse eRetVal = e_InitInvalidId; + + if(0 == m_poTopOfComStack){ + size_t unLen = strlen(ID().getValue()); + char *acID; + + if(0 == strchr(ID().getValue(), ']')){ + acID = getDefaultIDString(); + } + else{ + acID = new char[unLen + 1]; + strcpy(acID, ID().getValue()); + } + + char *pa_acLayerParams; + char *acRemainingConnectionID = CComLayer::extractLayerIdAndParams(acID, &pa_acLayerParams); + if('\0' != acID){ + m_poTopOfComStack = CComLayersManager::createCommunicationLayer(acID, 0, this); + + if(m_poTopOfComStack != 0){ + eRetVal = m_poTopOfComStack->openConnection(pa_acLayerParams, acRemainingConnectionID); + if(e_InitOk != eRetVal){ + delete m_poTopOfComStack; + m_poTopOfComStack = 0; + } + } + } + delete[] acID; + } + else{ + eRetVal = e_InitOk; + } + return eRetVal; +} + +void CCommFB::closeConnection(){ + if(m_poTopOfComStack != 0){ + m_poTopOfComStack->closeConnection(); + delete m_poTopOfComStack; // this will close the whole communication stack + m_poTopOfComStack = 0; + } +} + +EComResponse CCommFB::receiveData(){ + EComResponse eResp; + EComResponse eRetVal = e_Nothing; + + unsigned int ComInterruptQueueCountCopy = m_unComInterruptQueueCount; + for(unsigned int i = 0; i < ComInterruptQueueCountCopy; ++i){ + eResp = m_apoInterruptQueue[i]->processInterrupt(); + if(eResp > eRetVal){ + eRetVal = eResp; + } + } + m_unComInterruptQueueCount -= ComInterruptQueueCountCopy; + for(unsigned int i = 0; i < m_unComInterruptQueueCount; ++i){ + m_apoInterruptQueue[i] = m_apoInterruptQueue[i + ComInterruptQueueCountCopy]; + } + + return eRetVal; +} + +void CCommFB::interruptCommFB(CComLayer *pa_poComLayer){ + if(cg_unCommunicationInterruptQueueSize > m_unComInterruptQueueCount){ + m_apoInterruptQueue[m_unComInterruptQueueCount] = pa_poComLayer; + m_unComInterruptQueueCount++; + } + else{ + //TODO to many interrupts received issue error msg + } +} + +char * CCommFB::getDefaultIDString(){ + const char *acOrgID = ID().getValue(); + char * acRetVal = new char[strlen(acOrgID) + 12]; + strcpy(acRetVal, "fbdk[].ip["); + strcat(acRetVal, acOrgID); + strcat(acRetVal, "]"); + return acRetVal; +} diff --git a/src/core/cominfra/commfb.h b/src/core/cominfra/commfb.h new file mode 100644 index 000000000..c42e70d1a --- /dev/null +++ b/src/core/cominfra/commfb.h @@ -0,0 +1,148 @@ +/******************************************************************************* + * Copyright (c) 2006-2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Thomas Strasser, Alois Zoitl, Michael Hofmann, + * Martin Melik-Merkumians, Ingo Hegny, Patrick Smejkal + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _COMMFB_H_ +#define _COMMFB_H_ + +#include +#include "../esfb.h" +#include "../datatypes/forte_bool.h" +#ifdef FORTE_USE_WSTRING_DATATYPE +#include "../datatypes/forte_wstring.h" +#else +#include "../datatypes/forte_string.h" +#endif +#include "comtypes.h" + +namespace forte { + namespace com_infra { + + class CComLayer; + + class CCommFB : public CEventSourceFB{ + public: + virtual ~CCommFB(); + + /*!\brief The getFBType method is used by the Query command to get the instances correct type name (eg. "CLIENT_3_2") + * \return pointer to typename string + */ + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + forte::com_infra::EComServiceType getComServiceType() const{ + return m_eCommServiceType; + } + + unsigned int getNumSD() const{ + return m_pstInterfaceSpec->m_nNumDIs - 2; + } + + unsigned int getNumRD() const{ + return m_pstInterfaceSpec->m_nNumDOs - 2; + } + + CIEC_ANY *getSDs(){ + return getDI(2); + } + + CIEC_ANY *getRDs(){ + return getDO(2); + } + + void interruptCommFB(CComLayer *pa_poComLayer); + + CIEC_BOOL& QI() { + return *static_cast(getDI(0)); + } + +#ifdef FORTE_USE_WSTRING_DATATYPE + CIEC_WSTRING& ID() { + return *static_cast(getDI(1)); + } + + CIEC_WSTRING& STATUS() { + return *static_cast(getDO(1)); + } +#else + //TODO after fixing discussion on the new compliance profile fix these values to STRING + CIEC_STRING& ID() { + return *static_cast(getDI(1)); + } + + CIEC_STRING& STATUS() { + return *static_cast(getDO(1)); + } +#endif + + CIEC_BOOL& QO() { + return *static_cast(getDO(0)); + } + + protected: + CCommFB(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes, forte::com_infra::EComServiceType pa_eCommServiceType); + + CCommFB(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, + TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData, forte::com_infra::EComServiceType pa_eCommServiceType); + + /*!\brief The configureFB method is used by the typelib to parametrize the number of inputs/outputs + * \param pa_acConfigString : the string containing the requested typename (eg. "CLIENT_3_2" + */ + bool configureFB(const char *pa_acConfigString); + + void executeEvent(int pa_nEIID); + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nSendNotificationEventID = 1; + static const TEventID scm_nReceiveNotificationEventID = 1; + + static const unsigned int scm_QI_ID = 0; //Input ID 0 for QI Input + static const unsigned int scm_QO_ID = 0; //Output ID 0 for QO Output + static const unsigned int scm_ID_ID = 1; //Input ID 1 for ID Input + static const unsigned int scm_STATUS_ID = 1; //Output ID 1 for STATUS Output + + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + private: + static const CStringDictionary::TStringId scm_aunRequesterEventInputNameIds[]; + static const CStringDictionary::TStringId scm_aunRequesterEventOutputNameIds[]; + + static const CStringDictionary::TStringId scm_aunResponderEventInputNameIds[]; + static const CStringDictionary::TStringId scm_aunResponderEventOutputNameIds[]; + + static const TForteInt16 scm_anEIWithIndexes[]; + static const TForteInt16 scm_anEOWithIndexes[]; + + static const char * const scm_sResponseTexts[]; + + EComResponse openConnection(); + void closeConnection(); + EComResponse receiveData(); + /*! If the ID string does not contain [] indicating that there is a layer setup given this Function is called to + * to generate an default layer configuration. This function may be overwriten by special Comfbs to provide their + * own default layer config. See for example GEN_PUBL or GEN_SUBL. + * @return id with layer configuration + */ + virtual char * getDefaultIDString(); + + forte::com_infra::EComServiceType m_eCommServiceType; + forte::com_infra::CComLayer *m_poTopOfComStack; + unsigned int m_unComInterruptQueueCount; //!< number of triggers pending from the network + CComLayer *m_apoInterruptQueue[cg_unCommunicationInterruptQueueSize]; + }; + + } +} + +#endif //_COMMFB_H_ diff --git a/src/core/cominfra/comtypes.h b/src/core/cominfra/comtypes.h new file mode 100644 index 000000000..d4eead9a8 --- /dev/null +++ b/src/core/cominfra/comtypes.h @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2010-2013 TU Wien ACIN. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and rework communication infrastructure + * Martin Melik-Merkumians - fix typo in forte::com_infra::EComConnectionState + *******************************************************************************/ +#ifndef _COMTYPES_H_ +#define _COMTYPES_H_ + +#include + +namespace forte { + //TODO maybe add core namespace depending on namespace support of older c++ compilers + namespace com_infra { + + static const unsigned int scg_unINIT = 0x10; + static const unsigned int scg_unProcessData = 0x20; + static const unsigned int scg_unComNegative = 0x40; + + enum EComResponseType{ + e_InitPositive = scg_unINIT, e_ProcessDataPositive = scg_unProcessData, e_InitNegative = scg_unINIT | scg_unComNegative, e_ProcessDataNegative = scg_unProcessData | scg_unComNegative + }; + + enum EComResponseMsgIds{ + e_Ok = 0, + e_InvalidId = 1, + e_Terminated = 2, + e_InvalidObject = 3, + e_DataTypeError = 4, + e_Inhibited = 5, + e_NoSocket = 6, + e_SendFailed = 7, + e_RecvFailed = 8 + }; + + enum EComResponse{ + e_Nothing = 0, + e_InitOk = e_InitPositive | e_Ok, + e_ProcessDataOk = e_ProcessDataPositive | e_Ok, + e_InitInvalidId = e_InitNegative | e_InvalidId, + e_InitTerminated = e_InitNegative | e_Terminated, + e_ProcessDataInvalidObject = e_ProcessDataNegative | e_InvalidObject, + e_ProcessDataDataTypeError = e_ProcessDataNegative | e_DataTypeError, + e_ProcessDataInhibited = e_ProcessDataNegative | e_Inhibited, + e_ProcessDataNoSocket = e_ProcessDataNegative | e_NoSocket, + e_ProcessDataSendFailed = e_ProcessDataNegative | e_SendFailed, + e_ProcessDataRecvFaild = e_ProcessDataNegative | e_RecvFailed + }; + + /*!\brief Enum for different Communication FB types + * Only lower nibble is used, 1st bit 1 = Data inputs, 2nd bit 1 = Data outputs, 3rd bit 0 = Responder, + * 3rd bit 1 = Requester + */ + enum EComParameterTypes{ + e_Responder = 0, //b00000000, + e_DataInputs = 1, // b00000001, + e_DataOutputs = 2,// b00000010, + e_Requester = 4 //b00000100 + }; + + enum EComServiceType{ + e_Publisher = e_Requester | e_DataInputs, //!< e_Publisher + e_Subscriber = e_Responder | e_DataOutputs, //!< e_Subscriber + e_Server = e_Responder | e_DataInputs | e_DataOutputs, //!< e_Server + e_Client = e_Requester | e_DataInputs | e_DataOutputs + //!< e_Client + }; + + enum EComConnectionState{ + e_Disconnected, e_Listening, e_ConnectedAndListening, e_Connected + }; + + struct SRetBuffers{ + TForteUInt32 m_unTopGetDataSize; + TForteUInt32 m_unBottomGetDataSize; + }; + +} +} +#endif diff --git a/src/core/cominfra/fbdkasn1layer.cpp b/src/core/cominfra/fbdkasn1layer.cpp new file mode 100644 index 000000000..4e944f0b0 --- /dev/null +++ b/src/core/cominfra/fbdkasn1layer.cpp @@ -0,0 +1,896 @@ +/******************************************************************************* + * Copyright (c) 2010-2013 TU Wien ACIN, Profactor GmbH, nxtControl GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Michael Hofmann, Stanislav Meduna, + * Martin Melik Merkumians + * - initial implementation, rework communication infrastructure, bug fixes + *******************************************************************************/ +#include +#include "fbdkasn1layer.h" +#include "commfb.h" +#include "../datatypes/forte_string.h" +#include "../datatypes/forte_wstring.h" +#include "../datatypes/forte_array.h" +#include "../../arch/timerha.h" + +using namespace forte::com_infra; + +CFBDKASN1ComLayer::CFBDKASN1ComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poComFB) : + CComLayer(pa_poUpperLayer, pa_poComFB), mStatSerBuf(0), mStatSerBufSize(0), mDeserBuf(0), mDeserBufSize(0), mDeserBufPos(0), mDIPos(0), mDOPos(0){ + + if(0 != pa_poComFB){ + unsigned int sdNum = pa_poComFB->getNumSD(); + CIEC_ANY *apoSDs = pa_poComFB->getSDs(); + for(unsigned int i = 0; i < sdNum; ++i){ + if(apoSDs != 0){ + TForteByte typeSize = csm_aDataTags[apoSDs->getDataTypeID()][1]; + if(typeSize != 255){ + mStatSerBufSize += typeSize + 1; + } + ++apoSDs; + } + } + + unsigned int rdNum = pa_poComFB->getNumRD(); + CIEC_ANY *apoRDs = pa_poComFB->getRDs(); + for(unsigned int i = 0; i < rdNum; ++i){ + if(0 != apoRDs){ + TForteByte typeSize = csm_aDataTags[apoRDs->getDataTypeID()][1]; + if(typeSize != 255){ + mDeserBufSize += typeSize + 1; + } + } + ++apoRDs; + } + + mStatSerBuf = new TForteByte[mStatSerBufSize]; + mDeserBuf = new TForteByte[mDeserBufSize]; + } +} + +CFBDKASN1ComLayer::~CFBDKASN1ComLayer(){ + delete[] mStatSerBuf; + delete[] mDeserBuf; +} + +EComResponse CFBDKASN1ComLayer::openConnection(char *){ + //We don't need layer specific parameters + return e_InitOk; +} + +void CFBDKASN1ComLayer::closeConnection(){ + // we don't need to do anything specific on closing when closing the connection + //so directly close the bottom layer if there + if(0 != m_poBottomLayer){ + m_poBottomLayer->closeConnection(); + } +} + +void CFBDKASN1ComLayer::resizeDeserBuffer(unsigned int pa_size){ + //FIXME use realloc here + TForteByte *newBuf = new TForteByte[pa_size]; + for(unsigned int i = 0; i < mDeserBufPos; i++){ + newBuf[i] = mDeserBuf[i]; + } + delete[] mDeserBuf; + mDeserBuf = newBuf; + mDeserBufSize = pa_size; +} + +EComResponse CFBDKASN1ComLayer::sendData(void *pa_pvData, unsigned int pa_unSize){ + EComResponse eRetVal = e_ProcessDataNoSocket; + + if(m_poBottomLayer != 0){ + TConstIEC_ANYPtr apoSDs = static_cast (pa_pvData); + unsigned int unNeededBufferSize = 0; + + for(unsigned int i = 0; i < pa_unSize; ++i){ + if((apoSDs + i) == 0){ + return e_ProcessDataDataTypeError; + } + + unNeededBufferSize += getRequiredSerializationSize(apoSDs[i]); + + } + TForteByte *paUsedBuffer = 0; + TForteByte *paDynSerBuffer = 0; + //FIXME grow buffer instead of allocating every time a new one + if(unNeededBufferSize <= mStatSerBufSize){ + paUsedBuffer = mStatSerBuf; + } + else{ + paDynSerBuffer = new TForteByte[unNeededBufferSize]; + paUsedBuffer = paDynSerBuffer; + } + + int ser_size = -1; //stays negative if no Buffer for serialization is provided or error occurs while serialization + + if (0 != paUsedBuffer) { + ser_size = serializeFBDataPointArray(paUsedBuffer, unNeededBufferSize, apoSDs, pa_unSize); + } + + if(ser_size > 0){ + eRetVal = m_poBottomLayer->sendData(paUsedBuffer, ser_size); + } + else{ // serialize failed + eRetVal = e_ProcessDataDataTypeError; + DEVLOG_ERROR("CAsn1Layer:: serializeData failed\n"); + } + + if(0 != paDynSerBuffer){ + delete[] paDynSerBuffer; + } + } + + return eRetVal; +} + +EComResponse CFBDKASN1ComLayer::recvData(const void *pa_pvData, unsigned int pa_unSize){ + TForteByte *recvData = (TForteByte *) pa_pvData; + TForteByte *usedBuffer = 0; + EComResponse eRetVal = e_Nothing; + + if(m_poFb != 0){ + CIEC_ANY *apoRDs = m_poFb->getRDs(); + unsigned int unNumRD = m_poFb->getNumRD(); + unsigned int usedBufferSize = 0; + + // TODO: only copy if necessary + if(mDeserBufPos == 0){ + usedBuffer = recvData; + usedBufferSize = pa_unSize; + } + else{ + if((pa_unSize + mDeserBufPos) > mDeserBufSize){ + resizeDeserBuffer(pa_unSize + mDeserBufPos); + } + memcpy((mDeserBuf + mDeserBufPos), recvData, pa_unSize); + usedBuffer = mDeserBuf; + mDeserBufPos = mDeserBufPos + pa_unSize; + usedBufferSize = mDeserBufPos; + } + int nBuf; + while(usedBufferSize != 0){ + if(unNumRD == 0){ + nBuf = 1; + } + else{ + if((apoRDs + mDOPos) != 0){ + nBuf = deserializeDataPoint(usedBuffer, usedBufferSize, apoRDs[mDOPos]); + } + else{ + DEVLOG_ERROR("Data type error\n"); + eRetVal = e_ProcessDataDataTypeError; + break; + } + } + + // deserialize failed, copy data into buffer for next package + if(nBuf <= 0){ + if(-2 == nBuf){ + //We had a data type problem + eRetVal = e_ProcessDataDataTypeError; + break; + } + else{ + if(usedBuffer == recvData){ + if((mDeserBufSize) < usedBufferSize){ + resizeDeserBuffer(usedBufferSize); + } + memcpy(mDeserBuf, usedBuffer, usedBufferSize); + mDeserBufPos = usedBufferSize; + } + nBuf = usedBufferSize; + } + } + else{ + mDOPos++; + mDeserBufPos = 0; // TODO: MH: think on this + } + + usedBufferSize -= nBuf; + usedBuffer += nBuf; + + // required if e.g. the first element is an bool and the second element is "fragmented" - otherwise the resize in the buffer will not be resized + recvData += nBuf; + + if(mDOPos >= unNumRD){ + mDOPos = 0; + eRetVal = e_ProcessDataOk; + //FIXME if at this point data is left it is from a second run. Better first deliver this packet and afterwards handle second run + } + } + } + return eRetVal; +} + +/*Initialization csm_aDataTags array + * + */ +const TForteByte CFBDKASN1ComLayer::csm_aDataTags[][2] = { +//!< {Tag, Size of data + tag size}; Size == 255 means unknown +//TODO: consider size=0 for unknown + { e_APPLICATION + e_PRIMITIVE + e_ANY_TAG, 255 }, { e_APPLICATION + e_PRIMITIVE + e_BOOL_TAG, 1 }, { e_APPLICATION + e_PRIMITIVE + e_SINT_TAG, 2 }, { e_APPLICATION + e_PRIMITIVE + e_INT_TAG, 3 }, { e_APPLICATION + e_PRIMITIVE + e_DINT_TAG, 5 }, { e_APPLICATION + e_PRIMITIVE + e_LINT_TAG, 9 }, { e_APPLICATION + e_PRIMITIVE + e_USINT_TAG, 2 }, { e_APPLICATION + e_PRIMITIVE + e_UINT_TAG, 3 }, { e_APPLICATION + e_PRIMITIVE + e_UDINT_TAG, 5 }, { e_APPLICATION + e_PRIMITIVE + e_ULINT_TAG, 9 }, { e_APPLICATION + e_PRIMITIVE + e_BYTE_TAG, 2 }, { e_APPLICATION + e_PRIMITIVE + e_WORD_TAG, 3 }, { e_APPLICATION + e_PRIMITIVE + e_DWORD_TAG, 5 }, { e_APPLICATION + e_PRIMITIVE + e_LWORD_TAG, 9 }, { + e_APPLICATION + e_PRIMITIVE + e_DATE_TAG, 9 }, { e_APPLICATION + e_PRIMITIVE + e_TIME_OF_DAY_TAG, 9 }, { e_APPLICATION + e_PRIMITIVE + e_DATE_AND_TIME_TAG, 9 }, { e_APPLICATION + e_PRIMITIVE + e_TIME_TAG, 9 }, { e_APPLICATION + e_PRIMITIVE + e_REAL_TAG, 5 }, { e_APPLICATION + e_PRIMITIVE + e_LREAL_TAG, 9 }, { e_APPLICATION + e_PRIMITIVE + e_STRING_TAG, 255 }, { e_APPLICATION + e_PRIMITIVE + e_WSTRING_TAG, 255 }, { e_APPLICATION + e_CONSTRUCTED + e_DerivedData_TAG, 255 }, { e_APPLICATION + e_CONSTRUCTED + e_DirectlyDerivedData_TAG, 255 }, { e_APPLICATION + e_CONSTRUCTED + e_EnumeratedData_TAG, 255 }, { e_APPLICATION + e_CONSTRUCTED + e_SubrangeData_TAG, 255 }, { e_APPLICATION + e_CONSTRUCTED + e_ARRAY_TAG, 255 }, { e_APPLICATION + e_CONSTRUCTED + e_STRUCT_TAG, 255 } }; + +int CFBDKASN1ComLayer::serializeDataPointArray(TForteByte *pa_pcBytes, unsigned int pa_nStreamSize, TConstIEC_ANYPtr *pa_apoData, unsigned int pa_nDataNum){ + int nRetVal = -1; + if(0 == pa_nDataNum){ + serializeNull(pa_pcBytes); + nRetVal = 1; + } + else{ + int nRemainingBytes = pa_nStreamSize; + int nBuf; + nRetVal = 0; + for(unsigned int i = 0; i < pa_nDataNum; i++){ + if(0 != (pa_apoData[i])){ + nBuf = serializeDataPoint(pa_pcBytes, nRemainingBytes, *pa_apoData[i]); + if(0 < nBuf){ + nRetVal += nBuf; + nRemainingBytes -= nBuf; + pa_pcBytes += nBuf; + } + else{ + nRetVal = -1; + break; + } + } + else{ + nRetVal = -1; + break; + } + } + } + return nRetVal; +} + +int CFBDKASN1ComLayer::serializeDataPoint(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ANY &pa_roCIECData){ + int nRetVal = -1; + if(0 < pa_nStreamSize){ + serializeTag(pa_pcBytes, pa_roCIECData); + nRetVal = serializeValue(pa_pcBytes + 1, pa_nStreamSize - 1, pa_roCIECData); + if(0 <= nRetVal){ + ++nRetVal; //add one for the tag + } + } + return nRetVal; +} + +int CFBDKASN1ComLayer::serializeFBDataPointArray(TForteByte* pa_pcBytes, unsigned int pa_nStreamSize, TConstIEC_ANYPtr pa_aoData, unsigned int pa_nDataNum){ + int nRetVal = -1; + if(0 == pa_nDataNum){ + serializeNull(pa_pcBytes); + nRetVal = 1; + } + else{ + int nRemainingBytes = pa_nStreamSize; + int nBuf; + nRetVal = 0; + for(unsigned int i = 0; i < pa_nDataNum; i++){ + if(0 != (pa_aoData + i)){ + nBuf = serializeDataPoint(pa_pcBytes, nRemainingBytes, pa_aoData[i]); + if(0 < nBuf){ + nRetVal += nBuf; + nRemainingBytes -= nBuf; + pa_pcBytes += nBuf; + } + else{ + nRetVal = -1; + break; + } + } + else{ + nRetVal = -1; + break; + } + } + } + return nRetVal; +} + +void CFBDKASN1ComLayer::serializeTag(TForteByte* pa_pcBytes, const CIEC_ANY &pa_roCIECData){ +#ifdef FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES + if (CIEC_ANY::e_External == pa_roCIECData.getDataTypeID()) { + pa_pcBytes[0] = pa_roCIECData.getTag(); + } else { +#endif /* FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES */ + if (CIEC_ANY::e_STRUCT != pa_roCIECData.getDataTypeID()) { + pa_pcBytes[0] = csm_aDataTags[pa_roCIECData.getDataTypeID()][0]; + } + else { + //get ASN1-tag from implementing datatype for STRUCT-datatypes + pa_pcBytes[0] = ((CIEC_STRUCT&) pa_roCIECData).getASN1StructType(); + } + //TODO add bool stuff here +#ifdef FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES + } +#endif/* FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES */ + +} + +int CFBDKASN1ComLayer::serializeValue(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ANY &pa_roCIECData){ + int nRetVal = -1; + + CIEC_ANY::EDataTypeID eDataType = pa_roCIECData.getDataTypeID(); + + if((CIEC_ANY::e_BOOL < eDataType && eDataType <= CIEC_ANY::e_DATE_AND_TIME)||(CIEC_ANY::e_REAL == eDataType)||(CIEC_ANY::e_LREAL == eDataType)){ + //Simple data types except bool can be handled the same way + nRetVal = serializeValueSimpleDataType(pa_pcBytes, pa_nStreamSize, pa_roCIECData); + } + else{ + switch (eDataType){ + case CIEC_ANY::e_BOOL: + if(!((CIEC_BOOL &) pa_roCIECData).operator bool()){ + //data of bool is encoded in the tag; if CIEC_BOOL == false => Tag must be e_APPLICATION + e_PRIMITIVE + pa_pcBytes[-1] = static_cast(pa_pcBytes[-1] - static_cast(e_BOOL_TAG)); + } + nRetVal = 0; + break; + case CIEC_ANY::e_TIME: + nRetVal = serializeValueTime(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#ifdef FORTE_USE_WSTRING_DATATYPE + case CIEC_ANY::e_WSTRING: + nRetVal = serializeValueWString(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#endif + case CIEC_ANY::e_STRING: + nRetVal = serializeValueString(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#ifdef FORTE_SUPPORT_ARRAYS + case CIEC_ANY::e_ARRAY: + nRetVal = serializeArray(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#endif /* FORTE_SUPPORT_ARRAYS */ + case CIEC_ANY::e_STRUCT: + nRetVal = serializeValueStruct(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#ifdef FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES + case CIEC_ANY::e_External: + nRetVal = pa_roCIECData.serializeCustomType(pa_pcBytes, pa_nStreamSize); + break; +#endif /* FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES */ + + default: + break; + } + } + + return nRetVal; +} + +int CFBDKASN1ComLayer::serializeValueSimpleDataType(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ANY & pa_roDataPoint){ + int nRetVal = csm_aDataTags[pa_roDataPoint.getDataTypeID()][1]; + --nRetVal; //Length of the tag + + if(nRetVal <= pa_nStreamSize){ + const TForteByte* acDataPtr = pa_roDataPoint.getConstDataPtr(); + + #ifdef FORTE_LITTLE_ENDIAN + #if defined(__ARMEL__) && ! defined(__VFP_FP__) // Little endian ARM with old mixed endian FPA float ABI needs to swap + if(CIEC_ANY::e_LREAL == pa_roDataPoint.getDataTypeID()) { + TForteUInt32 anSwapped[2]; + anSwapped[0] = reinterpret_cast(acDataPtr)[1]; + anSwapped[1] = reinterpret_cast(acDataPtr)[0]; + acDataPtr = reinterpret_cast(&anSwapped[0]); + } + #endif + for(int i = 0; i < nRetVal; i++){ + pa_pcBytes[(nRetVal - 1) - i] = acDataPtr[i]; + } + #endif + + #ifdef FORTE_BIG_ENDIAN + if(CIEC_ANY::e_REAL != pa_roDataPoint.getDataTypeID()){ + for (int i = 0; i < nRetVal; i++){ + pa_pcBytes[(nRetVal - 1) - i] = acDataPtr[(sizeof(CIEC_ANY::TLargestUIntValueType) - 1)-i]; + } + } + else{ + for (unsigned int i = 0; i < nRetVal; i++){ + pa_pcBytes[(nRetVal - 1) - i] = acDataPtr[(sizeof(TForteFloat) - 1) - i]; + } + } + #endif + } + else{ + nRetVal = -1; + } + + return nRetVal; +} + +int CFBDKASN1ComLayer::serializeValueTime(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_TIME & pa_roTime){ + int nRetVal = -1; + if(8 <= pa_nStreamSize){ + TForteInt64 timeInMicroSeconds = pa_roTime.getInMicroSeconds(); + pa_pcBytes[0] = (TForteByte) (timeInMicroSeconds >> 56) & 0xFF; + pa_pcBytes[1] = (TForteByte) (timeInMicroSeconds >> 48) & 0xFF; + pa_pcBytes[2] = (TForteByte) (timeInMicroSeconds >> 40) & 0xFF; + pa_pcBytes[3] = (TForteByte) (timeInMicroSeconds >> 32) & 0xFF; + pa_pcBytes[4] = (TForteByte) (timeInMicroSeconds >> 24) & 0xFF; + pa_pcBytes[5] = (TForteByte) (timeInMicroSeconds >> 16) & 0xFF; + pa_pcBytes[6] = (TForteByte) (timeInMicroSeconds >> 8) & 0xFF; + pa_pcBytes[7] = (TForteByte) (timeInMicroSeconds) & 0xFF; + nRetVal = 8; + } + return nRetVal; +} + +int CFBDKASN1ComLayer::serializeValueString(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_STRING & pa_roString){ + int nRetVal = -1; + TForteUInt16 unStringLen = pa_roString.length(); + if(unStringLen + 2 <= pa_nStreamSize){ + pa_pcBytes[0] = (TForteByte) ((unStringLen >> 8) & 0x00FF); + pa_pcBytes[1] = (TForteByte) (unStringLen & 0x00FF); + pa_pcBytes += 2; + memcpy(pa_pcBytes, pa_roString.getValue(), unStringLen); + nRetVal = unStringLen + 2; + } + return nRetVal; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +int CFBDKASN1ComLayer::serializeValueWString(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_WSTRING & pa_roWString){ + int nRetVal = -1; + + if (pa_nStreamSize < 2) + return -1; + + nRetVal = pa_roWString.toUTF16(pa_pcBytes + 2, pa_nStreamSize - 2); + if (nRetVal < 0 || nRetVal > 131070) + return -1; + + pa_pcBytes[0] = (TForteByte) ((nRetVal >> 9) & 0x00FF); + pa_pcBytes[1] = (TForteByte) ((nRetVal >> 1) & 0x00FF); + nRetVal += 2; + + return nRetVal; +} +#endif + +#ifdef FORTE_SUPPORT_ARRAYS + +int CFBDKASN1ComLayer::serializeArray(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ARRAY &pa_roArray){ + int nRetVal = -1; + TForteUInt16 nArraySize = pa_roArray.size(); + + //Number of array elements + pa_pcBytes[0] = (TForteByte) ((nArraySize >> 8) & 0x00FF); + pa_pcBytes[1] = (TForteByte) (nArraySize & 0x00FF); + + pa_pcBytes += 2; + //TODO should we check if the array has size zero? + + + if( CIEC_ANY::e_BOOL == pa_roArray[0]->getDataTypeID()){ + //bool arrays are special + nRetVal = 2; // array len + pa_nStreamSize -= nRetVal; + for(TForteUInt16 i = 0; i < nArraySize; i++){ //serialize elements + int nSerSize = serializeDataPoint(pa_pcBytes, pa_nStreamSize, *pa_roArray[i]); + if(0 < nSerSize){ + nRetVal += nSerSize; + pa_pcBytes += nSerSize; + pa_nStreamSize -= nSerSize; + } + else{ + nRetVal = -1; + break; + } + } + } + else{ + serializeTag(pa_pcBytes, *pa_roArray[0]); + + nRetVal = 2 + 1; // array len + contained data tag + pa_nStreamSize -= nRetVal; + + ++pa_pcBytes; + for(TForteUInt16 i = 0; i < nArraySize; i++){ //serialize elements + int nSerSize = serializeValue(pa_pcBytes, pa_nStreamSize, *pa_roArray[i]); + if(-1 == nSerSize){ + nRetVal = -1; + break; + } + nRetVal += nSerSize; + pa_nStreamSize -= nSerSize; + pa_pcBytes += nSerSize; //shift buffer array + } + + } + return nRetVal; +} +#endif + +int CFBDKASN1ComLayer::serializeValueStruct(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_STRUCT & pa_roStruct) { + int nStreamUsed = 0; + int nTotalStreamUsed = 0; + + int nStructSize = pa_roStruct.getStructSize(); + + for (int i = 0; i < nStructSize; i++){ + const CIEC_ANY& ro_val = (pa_roStruct.getMembers())[i]; + if (CIEC_ANY::e_BOOL == ro_val.getDataTypeID()) { + //Handle BOOL-values differently, since value is encoded in tag + nStreamUsed = serializeDataPoint(pa_pcBytes, pa_nStreamSize, ro_val); + } + else { + nStreamUsed = serializeValue(pa_pcBytes, pa_nStreamSize, ro_val); + } + + + if(-1 == nStreamUsed) { + nTotalStreamUsed = -1; + break; + } + pa_nStreamSize -= nStreamUsed; + pa_pcBytes += nStreamUsed; + nTotalStreamUsed += nStreamUsed; + } + return nTotalStreamUsed; +} + +bool CFBDKASN1ComLayer::deserializeDataPointArray(const TForteByte* pa_pcBytes, unsigned int pa_nStreamSize, TIEC_ANYPtr *pa_apoData, unsigned int pa_nDataNum){ + bool bRetval = true; + if(0 == pa_nDataNum){ + bRetval = ((pa_nStreamSize == 1) && (isNull(pa_pcBytes))); + } + else{ + int nBuf; + for(unsigned int i = 0; i < pa_nDataNum; ++i){ + if(0 == pa_apoData[i]){ + bRetval = false; + break; + } + nBuf = deserializeDataPoint(pa_pcBytes, pa_nStreamSize, *pa_apoData[i]); + if(nBuf <= 0){ + // we could not deserialize the data of we have a to small packet + // with the compliance profile for feasibility demonstration's protocol we can not determine packet order + // and therefore not handle + bRetval = false; + break; + } + pa_nStreamSize -= nBuf; + pa_pcBytes += nBuf; + } + } + return bRetval; +} + +int CFBDKASN1ComLayer::deserializeDataPoint(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ANY &pa_roCIECData){ + int nRetVal = -1; + if(0 < pa_nStreamSize){ + if(e_APPLICATION == (pa_pcBytes[0] & e_APPLICATION)){ + if(deserializeTag(*pa_pcBytes, pa_roCIECData)){ + nRetVal = deserializeValue(pa_pcBytes + 1, pa_nStreamSize - 1, pa_roCIECData) + 1; + } + else{ + DEVLOG_ERROR("Datatype error\n"); + nRetVal = -2; + } + } + } + return nRetVal; +} + +bool CFBDKASN1ComLayer::deserializeTag(const TForteByte pa_cByte, CIEC_ANY &pa_roCIECData){ + bool bRetVal; + CIEC_ANY::EDataTypeID eDataType = pa_roCIECData.getDataTypeID(); + + switch(eDataType){ + case CIEC_ANY::e_BOOL: + bRetVal = (((e_APPLICATION + e_PRIMITIVE) == pa_cByte) || ((e_APPLICATION + e_PRIMITIVE + CIEC_ANY::e_BOOL) == pa_cByte)); + if(bRetVal){ + static_cast(pa_roCIECData) = (csm_aDataTags[CIEC_ANY::e_BOOL][0] == pa_cByte); + } + break; + case CIEC_ANY::e_STRUCT: + bRetVal = (static_cast(pa_roCIECData).getASN1StructType() == pa_cByte); + break; +#ifdef FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES + case CIEC_ANY::e_External: + bRetVal = pa_roCIECData.deserializeTag(pa_cByte); + break; +#endif /* FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES */ + + default: + bRetVal = (csm_aDataTags[eDataType][0] == pa_cByte); + break; + } + return bRetVal; +} + +int CFBDKASN1ComLayer::deserializeValue(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ANY &pa_roCIECData){ + int nRetVal = -1; + CIEC_ANY::EDataTypeID eDataType = pa_roCIECData.getDataTypeID(); + + if((CIEC_ANY::e_BOOL < eDataType && eDataType <= CIEC_ANY::e_DATE_AND_TIME)||(CIEC_ANY::e_REAL == eDataType)||(CIEC_ANY::e_LREAL == eDataType)){//e_ANY to e_DATE_AND_TIME can be handled the same way + nRetVal = deserializeValueSimpleDataType(pa_pcBytes, pa_nStreamSize, pa_roCIECData); + } + else{ + switch (eDataType){ + case CIEC_ANY::e_BOOL: + //bool data is decoded in the bool tag + nRetVal = 0; + break; + case CIEC_ANY::e_TIME: + nRetVal = deserializeValueTime(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#ifdef FORTE_USE_WSTRING_DATATYPE + case CIEC_ANY::e_WSTRING: + nRetVal = deserializeValueWString(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#endif + case CIEC_ANY::e_STRING: + nRetVal = deserializeValueString(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#ifdef FORTE_SUPPORT_ARRAYS + case CIEC_ANY::e_ARRAY: + nRetVal = deserializeArray(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; +#endif /* FORTE_SUPPORT_ARRAYS*/ + case CIEC_ANY::e_STRUCT: + nRetVal = deserializeValueStruct(pa_pcBytes, pa_nStreamSize, static_cast(pa_roCIECData)); + break; + +#ifdef FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES + case CIEC_ANY::e_External: + nRetVal = pa_roCIECData.deserializeCustomType(pa_pcBytes, pa_nStreamSize); + break; +#endif /* FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES */ + default: + break; + } + } + return nRetVal; +} + +int CFBDKASN1ComLayer::deserializeValueSimpleDataType(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ANY &pa_roIECData){ + int nRetVal = -1; + int nValueSize = csm_aDataTags[pa_roIECData.getDataTypeID()][1] - 1; + + if(pa_nStreamSize >= nValueSize){ + TForteByte *acDataPtr = pa_roIECData.getDataPtr(); + + //setting m_uAnyData to 0 + *((CIEC_ANY::TLargestUIntValueType *) acDataPtr) = 0; + + //we only need to check for SINT, INT, and DINT as LINT will fill all bytes + if(pa_roIECData.getDataTypeID() <= CIEC_ANY::e_DINT){ + if(pa_pcBytes[0] & 0x80){ + //we received a negative number set all bits to true + *((CIEC_ANY::TLargestIntValueType *) acDataPtr) = -1; + } + } + + #ifdef FORTE_LITTLE_ENDIAN + for(int i = 0; i < nValueSize; i++){ + acDataPtr[i] = pa_pcBytes[(nValueSize - 1) - i]; + } + #if defined(__ARMEL__) && ! defined(__VFP_FP__) // Little endian ARM with old mixed endian FPA float ABI needs to swap + if(CIEC_ANY::e_LREAL == pa_roIECData.getDataTypeID()) { + TForteUInt32 nTmp = reinterpret_cast(acDataPtr)[1]; + ((TForteUInt32 *) acDataPtr)[1] = reinterpret_cast(acDataPtr)[0]; + reinterpret_cast(acDataPtr)[0] = nTmp; + } + #endif + #endif + #ifdef FORTE_BIG_ENDIAN + if(CIEC_ANY:: e_REAL != pa_roIECData.getDataTypeID()){ + for (unsigned int i=0; i < nValueSize;i++){ + acDataPtr[(sizeof(CIEC_ANY::TLargestUIntValueType) - 1) - i] = pa_pcBytes[(nValueSize - 1) - i]; + } + } + else{ //FLOAT must be processed this way, because it is always saved in the first 4 bytes + for (unsigned int i = 0; i < nValueSize; i++){ + acDataPtr[(sizeof(TForteFloat) - 1) - i] = pa_pcBytes[(nValueSize - 1) - i]; + } + } + #endif + nRetVal = nValueSize; + } + return nRetVal; +} + +int CFBDKASN1ComLayer::deserializeValueTime(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_TIME &pa_roIECData){ + int nRetVal = -1; + if(pa_nStreamSize >= 8){ + TForteInt64 timeInMicroSeconds = ((((TForteInt64) pa_pcBytes[0]) << 56) & 0xFF00000000000000LL) + ((((TForteInt64) pa_pcBytes[1]) << 48) & 0x00FF000000000000LL) + ((((TForteInt64) pa_pcBytes[2]) << 40) & 0x0000FF0000000000LL) + ((((TForteInt64) pa_pcBytes[3]) << 32) & 0x000000FF00000000LL) + ((((TForteInt64) pa_pcBytes[4]) << 24) & 0x00000000FF000000) + ((((TForteInt64) pa_pcBytes[5]) << 16) & 0x0000000000FF0000) + ((((TForteInt64) pa_pcBytes[6]) << 8) & 0x000000000000FF00) + (((TForteInt64) pa_pcBytes[7]) & 0x00000000000000FF); + pa_roIECData.setFromMicroSeconds(timeInMicroSeconds); + nRetVal = 8; + } + return nRetVal; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +int CFBDKASN1ComLayer::deserializeValueWString(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_WSTRING &pa_roIECData){ + int nRetVal = -1; + if(pa_nStreamSize >= 2){ + TForteUInt16 unStringSize = static_cast(((static_cast(pa_pcBytes[0]) << 8) & 0xFF00) + (static_cast(pa_pcBytes[1]) & 0x00FF)); + if(pa_nStreamSize >= (unStringSize * 2 + 2)){ + if (pa_roIECData.fromUTF16(pa_pcBytes + 2, unStringSize*2)) + nRetVal = unStringSize * 2 + 2; + } + } + return nRetVal; +} +#endif + +int CFBDKASN1ComLayer::deserializeValueString(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_STRING &pa_roIECData){ + int nRetVal = -1; + if(pa_nStreamSize >= 2){ + TForteUInt16 unStringSize = static_cast(((((TForteUInt16) pa_pcBytes[0]) << 8) & 0xFF00) + ((TForteUInt16) pa_pcBytes[1] & 0x00FF)); + if(pa_nStreamSize >= (unStringSize + 2)){ +// DEVLOG_INFO("reserve %i - pa_pcBytes[0]: 0x%x pa_pcBytes[1]: 0x%x \n", unStringSize, pa_pcBytes[0], pa_pcBytes[1]); + pa_roIECData.assign((const char*)&(pa_pcBytes[2]), unStringSize); + nRetVal = 2 + unStringSize; + } + } + return nRetVal; +} + +#ifdef FORTE_SUPPORT_ARRAYS + +int CFBDKASN1ComLayer::deserializeArray(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ARRAY &pa_roArray){ + int nRetVal = -1; + + if(pa_nStreamSize >= 2){ + TForteUInt16 nSize = static_cast(((((TForteUInt16) pa_pcBytes[0]) << 8) & 0xFF00) + ((TForteUInt16) pa_pcBytes[1] & 0x00FF)); + + //number of elements in ARRAY must be read from the incoming message + nRetVal = 2; + if(nSize > 0){ + if(pa_nStreamSize < 2){ + return -1; + } + int nValueLen; + pa_pcBytes += 2; + pa_nStreamSize -= 2; + + //TODO do we need to check if the array's size is bigger than 0 + if(CIEC_ANY::e_BOOL == pa_roArray[0]->getDataTypeID()){ + //bool arrays are special + nValueLen = deserializeValueBoolArray(pa_pcBytes, pa_nStreamSize, pa_roArray, nSize); + if(0 <= nValueLen){ + nRetVal += nValueLen; + } + else{ + nRetVal = nValueLen; + } + } + else{ + if(!deserializeTag(*pa_pcBytes, *pa_roArray[0])){ + return -1; + } + pa_pcBytes += 1; + pa_nStreamSize -= 1; + ++nRetVal; + CIEC_ANY *poBufVal = 0; + TForteUInt16 unArraySize = pa_roArray.size(); + + for(TForteUInt16 i = 0; i < nSize; ++i){ + if(i < unArraySize){ + nValueLen = deserializeValue(pa_pcBytes, pa_nStreamSize, *pa_roArray[i]); + } + else{ + if (poBufVal == 0) + poBufVal = pa_roArray[0]->clone(0); + nValueLen = deserializeValue(pa_pcBytes, pa_nStreamSize, *poBufVal); + } + //size of the elements is given by the array datatype + if(nValueLen <= 0) { + if (poBufVal != 0) + delete poBufVal; + return nValueLen; + } + pa_nStreamSize -= nValueLen; + pa_pcBytes += nValueLen; + nRetVal += nValueLen; + } + + if (poBufVal != 0) + delete poBufVal; + } + } + } + return nRetVal; +} + +int CFBDKASN1ComLayer::deserializeValueBoolArray(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ARRAY &pa_roArray, TForteUInt16 pa_unDecodedArraySize){ + int nRetVal = 0; + CIEC_BOOL oBoolVal; //buffer value for handling to large input data + + TForteUInt16 unArraySize = pa_roArray.size(); + int nValueLen; + + for(TForteUInt16 i = 0; i < pa_unDecodedArraySize; ++i){ + if(i < unArraySize){ + nValueLen = deserializeDataPoint(pa_pcBytes, pa_nStreamSize, *pa_roArray[i]); + } + else{ + nValueLen = deserializeDataPoint(pa_pcBytes, pa_nStreamSize, oBoolVal); + } + if(nValueLen <= 0){ + nRetVal = nValueLen; + break; + } + pa_pcBytes += nValueLen; + pa_nStreamSize -= nValueLen; + nRetVal += nValueLen; + } + return nRetVal; +} + +#endif + +int CFBDKASN1ComLayer::deserializeValueStruct(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_STRUCT &pa_roIECData){ + int nRetVal = 0; + int nValueLen; + + for (unsigned int i=0; i < pa_roIECData.getStructSize(); i++) { + CIEC_ANY& ro_val = (pa_roIECData.getMembers())[i]; + if (CIEC_ANY::e_BOOL == ro_val.getDataTypeID()) { + //Hanlde BOOL-datatype differently since value is encoded in tag + nValueLen = deserializeDataPoint(pa_pcBytes, pa_nStreamSize, ro_val); + } + else { + nValueLen = deserializeValue(pa_pcBytes, pa_nStreamSize, ro_val); + } + if(nValueLen <= 0){ + nRetVal = nValueLen; + break; + } + pa_nStreamSize -= nValueLen; + pa_pcBytes += nValueLen; + nRetVal += nValueLen; + } + return nRetVal; +} + + +unsigned int CFBDKASN1ComLayer::getRequiredSerializationSize(const CIEC_ANY &pa_roCIECData){ + unsigned int unRetVal = 0; + + switch (pa_roCIECData.getDataTypeID()){ + case CIEC_ANY::e_STRING: + unRetVal += ((CIEC_STRING&)pa_roCIECData).length() + 3; + break; +#ifdef FORTE_USE_WSTRING_DATATYPE + case CIEC_ANY::e_WSTRING: + unRetVal += ((CIEC_WSTRING&)pa_roCIECData).toUTF16(0, 0) + 3; + break; +#endif +#ifdef FORTE_SUPPORT_ARRAYS + case CIEC_ANY::e_ARRAY: + unRetVal += 3; + if (((CIEC_ARRAY&)pa_roCIECData).getElementDataTypeID() == CIEC_ANY::e_BOOL) + unRetVal += ((CIEC_ARRAY&)pa_roCIECData).size(); + else { + for(TForteUInt16 j = 0; j < ((CIEC_ARRAY&)pa_roCIECData).size(); ++j){ + unRetVal += getRequiredSerializationSize(*(((CIEC_ARRAY&)pa_roCIECData)[j])); + } + // First element with tag, subsequent ones without - adjust + unRetVal -= ((CIEC_ARRAY&)pa_roCIECData).size() - 1; + } + break; +#endif +#ifdef FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES + case CIEC_ANY::e_External: + unRetVal += pa_roCIECData.getRequiredSerializationSize(); + + break; +#endif /* FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES */ + + default: + unRetVal += csm_aDataTags[pa_roCIECData.getDataTypeID()][1]; + break; + } + return unRetVal; +} diff --git a/src/core/cominfra/fbdkasn1layer.h b/src/core/cominfra/fbdkasn1layer.h new file mode 100644 index 000000000..c4150006e --- /dev/null +++ b/src/core/cominfra/fbdkasn1layer.h @@ -0,0 +1,228 @@ +/******************************************************************************* + * Copyright (c) 2010-2013 fortiss, TU Wien ACIN and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and rework communication infrastructure, bug fixes + * Michael Hofmann - option for custom datatypes send by fbdkasn1layer + * Monika Wenger - rename datatype files to forte_datatype + * Ingo Hegny - serialize/deserialize for STRUCT, changed datatype for IP-communication + * Stanislav Meduna - make serializeNull and isNull public + *******************************************************************************/ +#ifndef _FBDKASN1LAYER_H_ +#define _FBDKASN1LAYER_H_ + +#include "comlayer.h" + +// serialize includes +#include "../datatypes/forte_any.h" +#include "../datatypes/forte_array.h" +#include "../datatypes/forte_wstring.h" +#include "../datatypes/forte_string.h" +#include "../datatypes/forte_struct.h" +#include "../../arch/devlog.h" + +class CIEC_TIME; +class CIEC_STRUCT; + +//forward declaration for the friend class fix (see below for explanations) +class LMS_USB_SRV; + +namespace forte { + namespace com_infra { + + class CFBDKASN1ComLayer : public CComLayer{ + public: + CFBDKASN1ComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB); + virtual ~CFBDKASN1ComLayer(); + + void closeConnection(); + EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); // top interface, called from top + EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); // bottom interface, called from bottom + + /*!\brief Serialize an array of IEC data points into a byte array + * + * @param pa_pcBytes destination array for the serialization + * @param pa_nStreamSize size of the destination array + * @param pa_apoData array of IEC data points + * @param pa_nDataNum length of the data point array + * @return on success the number of bytes written into the destination array, + * -1 on error. + */ + static int serializeDataPointArray(TForteByte* pa_pcBytes, unsigned int pa_nStreamSize, TConstIEC_ANYPtr *pa_apoData, unsigned int pa_nDataNum); + /*!\brief Serialize one IEC data point into a byte array + * + * @param pa_pcBytes destination array for the serialization + * @param pa_nStreamSize size of the destination array + * @param pa_roCIECData IEC data point + * @return on success the number of bytes written into the destination array, + * -1 on error. + */ + static int serializeDataPoint(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ANY &pa_roCIECData); + + + /*! \brief Serialization of the data value according to IEC 61499 Compliance Profile for + * Feasibility Demonstrations based on ISO/IEC 8825 (ASN.1). + * + * This function checks if enough bytes are available in the array. + * + * @param pa_pcBytes destination array for the serialization + * @param pa_nStreamSize size of the destination array + * @param pa_roCIECData IEC data point + * @return on success the number of bytes written into the destination array, + * -1 on error. + */ + static int serializeValue(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ANY &pa_roCIECData); + + /*!\brief Deserialize an array of IEC data points from a byte array + * + * @param pa_pcBytes target array for the deserialization + * @param pa_nStreamSize size of the target array + * @param pa_apoData array of IEC data points + * @param pa_nDataNum length of the data point array + * @return true on success + */ + static bool deserializeDataPointArray(const TForteByte* pa_pcBytes, unsigned int pa_nStreamSize, TIEC_ANYPtr *pa_apoData, unsigned int pa_nDataNum); + + /*!\brief Deserialize an array of IEC data points from a byte array + * + * @param pa_pcBytes target array for the deserialization + * @param pa_nStreamSize size of the target array + * @param pa_roCIECData array of IEC data points + * @return number of bytes used from the target array + * -1 on a general error, -2 if the tag does not fit + */ + static int deserializeDataPoint(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ANY &pa_roCIECData); + + /*! \brief Deserialization of the data value according to IEC 61499 Compliance Profile for + * Feasibility Demonstrations based on ISO/IEC 8825 (ASN.1). + * + * @param pa_pcBytes target array for the deserialization + * @param pa_nStreamSize size of the target array + * @param pa_roCIECData array of IEC data points + * @return number of bytes used from the target array + * -1 on a general error, -2 if the tag does not fit + */ + static int deserializeValue(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ANY &pa_roCIECData); + /*!\brief Serialize the Null tag into a byte array + * + * This operation will always take one byte + * @param pa_pcBytes destination array for the serialization + */ + static void serializeNull(TForteByte* pa_pcBytes){ + *pa_pcBytes = scm_nNull; + } + + static bool isNull(const TForteByte* pa_pcBytes){ + return *pa_pcBytes == scm_nNull; + } + + enum EDataTypeTags{ + e_ANY_TAG = 0, e_BOOL_TAG = 1, e_SINT_TAG = 2, e_INT_TAG = 3, e_DINT_TAG = 4, e_LINT_TAG = 5, e_USINT_TAG = 6, e_UINT_TAG = 7, e_UDINT_TAG = 8, e_ULINT_TAG = 9, e_REAL_TAG = 10, e_LREAL_TAG = 11, e_TIME_TAG = 12, e_DATE_TAG = 13, e_TIME_OF_DAY_TAG = 14, e_DATE_AND_TIME_TAG = 15, e_STRING_TAG = 16, e_BYTE_TAG = 17, e_WORD_TAG = 18, e_DWORD_TAG = 19, e_LWORD_TAG = 20, e_WSTRING_TAG = 21, e_DerivedData_TAG = 26, e_DirectlyDerivedData_TAG = 27, e_EnumeratedData_TAG = 28, e_SubrangeData_TAG = 29, e_ARRAY_TAG = 22, //according to the compliance profile + e_STRUCT_TAG = 31 + }; + /*! \ingroup COREDTS\brief ASN.1 tag classes + */ + enum EASN1TagClass{ + e_UNIVERSAL = 0, e_APPLICATION = 64, e_CONTEXT = 128, e_PRIVATE = 192 + }; + /*! \ingroup COREDTS\brief ASN.1 encoding types + */ + enum EASN1EncodingType{ + e_PRIMITIVE = 0, e_CONSTRUCTED = 32 + }; + + + protected: + private: + + static const TForteByte scm_nNull = 5; + const static TForteByte csm_aDataTags[][2]; + + /*!\brief Serialize an array of IEC data points from a FB into a byte array + * + * + * @param pa_pcBytes destination array for the serialization + * @param pa_nStreamSize size of the destination array + * @param pa_apoData array of IEC data points + * @param pa_nDataNum length of the data point array + * @return on success the number of bytes written into the destination array, + * -1 on error. + */ + static int serializeFBDataPointArray(TForteByte* pa_pcBytes, unsigned int pa_nStreamSize, TConstIEC_ANYPtr pa_aoData, unsigned int pa_nDataNum); + + + /*! \brief Serialization of data tag according to IEC 61499 Compliance Profile for + * Feasibility Demonstrations based on ISO/IEC 8825 (ASN.1). + * + * This operation will always take one byte. + * @param pa_pcBytes destination array for the serialization + * @param pa_roCIECData IEC data point + */ + static void serializeTag(TForteByte* pa_pcBytes, const CIEC_ANY &pa_roCIECData); + /** Specialization of the serialization of the data value for different data types. The interface behaves as + * described for static int serializeValue(TForteByte* pa_pcBytes, int pa_nStreamSize, TConstIEC_ANYPtr pa_pCIECData) + * @{*/ + static int serializeValueSimpleDataType(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ANY & pa_roDataPoint); + static int serializeValueTime(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_TIME & pa_roTime); + static int serializeValueString(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_STRING & pa_roString); +#ifdef FORTE_USE_WSTRING_DATATYPE + static int serializeValueWString(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_WSTRING & pa_roWString); +#endif + static int serializeValueStruct(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_STRUCT & pa_roWString); + #ifdef FORTE_SUPPORT_ARRAYS + static int serializeArray(TForteByte* pa_pcBytes, int pa_nStreamSize, const CIEC_ARRAY &pa_roArray); + #endif + /**@}*/ + + + + /*! \brief Deserialization of data tag according to IEC 61499 Compliance Profile for + * Feasibility Demonstrations based on ISO/IEC 8825 (ASN.1). + * \param pa_cByte byte that contains the received tag. + * \param pa_roCIECData IEC data point + * \return true if the tag matched the data point + */ + static bool deserializeTag(const TForteByte pa_cByte, CIEC_ANY &pa_roCIECData); + + + /** Specialization of the deserialization of the data value for different data types. The interface behaves as + * described for static int deserializeValue(const TForteByte* pa_pcBytes, int pa_nStreamSize, TIEC_ANYPtr pa_pCIECData) + * @{*/ + static int deserializeValueSimpleDataType(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ANY &pa_roIECData); + static int deserializeValueTime(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_TIME &pa_roIECData); +#ifdef FORTE_USE_WSTRING_DATATYPE + static int deserializeValueWString(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_WSTRING &pa_roIECData); +#endif + static int deserializeValueString(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_STRING &pa_roIECData); +#ifdef FORTE_SUPPORT_ARRAYS + static int deserializeArray(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ARRAY &pa_roArray); + static int deserializeValueBoolArray(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_ARRAY &pa_roArray, TForteUInt16 pa_unDecodedArraySize); +#endif + static int deserializeValueStruct(const TForteByte* pa_pcBytes, int pa_nStreamSize, CIEC_STRUCT &pa_roIECData); + /**@}*/ + + static unsigned int getRequiredSerializationSize(const CIEC_ANY &pa_roCIECData); + + EComResponse openConnection(char *pa_acLayerParameter); + void resizeDeserBuffer(unsigned int pa_size); + + + TForteByte *mStatSerBuf; + TForteUInt32 mStatSerBufSize; + + TForteByte *mDeserBuf; + TForteUInt32 mDeserBufSize; + unsigned int mDeserBufPos; + + TForteByte mDIPos; + TForteByte mDOPos; + }; + + } +} + +#endif diff --git a/src/core/cominfra/ipcomlayer.cpp b/src/core/cominfra/ipcomlayer.cpp new file mode 100644 index 000000000..8a3772d0d --- /dev/null +++ b/src/core/cominfra/ipcomlayer.cpp @@ -0,0 +1,233 @@ +/******************************************************************************* + * Copyright (c) 2010-2014 fortiss, TU Wien ACIN and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation, rework communication infrastructureand bug fixes + * Ingo Hegny - changed datatype for IP-communication + * Martin Melik-Merkumians - fix typo in forte::com_infra::EComConnectionState, serial communication support for WIN32 + * Michael Hofmann - fix for fragmented packets + * Patrik Smejkal - rename interrupt in interruptCCommFB + *******************************************************************************/ +#include "ipcomlayer.h" +#include "../../arch/devlog.h" +#include "commfb.h" +#include "../../core/datatypes/forte_dint.h" + +using namespace forte::com_infra; + +CIPComLayer::CIPComLayer(CComLayer* pa_poUpperLayer, CCommFB* pa_poComFB) : + CComLayer(pa_poUpperLayer, pa_poComFB), + m_nSocketID(CIPComSocketHandler::scm_nInvalidSocketDescriptor), + m_nListeningID(CIPComSocketHandler::scm_nInvalidSocketDescriptor), + m_eInterruptResp(e_Nothing), + m_unBufFillSize(0){ +} + +CIPComLayer::~CIPComLayer(){ +} + +void CIPComLayer::closeConnection(){ + DEVLOG_DEBUG("CSocketBaseLayer::closeConnection() \n"); + closeSocket(&m_nSocketID); + closeSocket(&m_nListeningID); + + m_eConnectionState = e_Disconnected; +} + +EComResponse CIPComLayer::sendData(void *pa_pvData, unsigned int pa_unSize){ + EComResponse eRetVal = e_ProcessDataOk; + + if((0 != m_poFb) && (CIPComSocketHandler::scm_nInvalidSocketDescriptor != m_nSocketID)){ + switch (m_poFb->getComServiceType()){ + case e_Server: + if(0 + >= CIPComSocketHandler::sendDataOnTCP(m_nSocketID, static_cast(pa_pvData), pa_unSize)){ + closeSocket(&m_nSocketID); + m_eConnectionState = e_Listening; + eRetVal = e_InitTerminated; + } + break; + case e_Client: + if(0 + >= CIPComSocketHandler::sendDataOnTCP(m_nSocketID, static_cast(pa_pvData), pa_unSize)){ + eRetVal = e_InitTerminated; + } + break; + case e_Publisher: + if(0 + >= CIPComSocketHandler::sendDataOnUDP(m_nSocketID, &m_tDestAddr, static_cast(pa_pvData), pa_unSize)){ + eRetVal = e_InitTerminated; + } + break; + case e_Subscriber: + //do nothing as subscribers do not send data + break; + } + } + return eRetVal; +} + +EComResponse CIPComLayer::processInterrupt(){ + if(e_ProcessDataOk == m_eInterruptResp){ + switch (m_eConnectionState){ + case e_Connected: + if((0 < m_unBufFillSize) && (0 != m_poTopLayer)){ + m_eInterruptResp = m_poTopLayer->recvData(m_acRecvBuffer, m_unBufFillSize); + m_unBufFillSize = 0; + } + break; + case e_Disconnected: + case e_Listening: + case e_ConnectedAndListening: + default: + break; + } + } + return m_eInterruptResp; +} + +EComResponse CIPComLayer::recvData(const void *pa_pvData, unsigned int){ + m_eInterruptResp = e_Nothing; + switch (m_eConnectionState){ + case e_Listening: + //TODO move this to the processInterrupt() + m_nSocketID = CIPComSocketHandler::acceptTCPConnection(m_nListeningID); + if(CIPComSocketHandler::scm_nInvalidSocketDescriptor != m_nSocketID){ + CIPComSocketHandler::getInstance().addComCallback(m_nSocketID, this); + m_eConnectionState = e_Connected; + } + break; + case e_Connected: + if(m_nSocketID == *(static_cast(pa_pvData))){ + handledConnectedDataRecv(); + } + else if(m_nListeningID + == *(static_cast(pa_pvData))){ + handleConnectionAttemptInConnected(); + } + break; + case e_ConnectedAndListening: + case e_Disconnected: + default: + break; + } + return m_eInterruptResp; +} + +EComResponse CIPComLayer::openConnection(char *pa_acLayerParameter){ + EComResponse eRetVal = e_InitInvalidId; + char *acPort = strchr(pa_acLayerParameter, ':'); + if(0 != acPort){ + *acPort = '\0'; + ++acPort; + + TForteUInt16 nPort = static_cast(forte::core::util::strtoul(acPort, 0, 10)); + + CIPComSocketHandler::TSocketDescriptor nSockDes = + CIPComSocketHandler::scm_nInvalidSocketDescriptor; + m_eConnectionState = e_Connected; + + switch (m_poFb->getComServiceType()){ + case e_Server: + nSockDes = m_nListeningID = + CIPComSocketHandler::openTCPServerConnection(pa_acLayerParameter, nPort); + m_eConnectionState = e_Listening; + break; + case e_Client: + nSockDes = m_nSocketID = + CIPComSocketHandler::openTCPClientConnection(pa_acLayerParameter, nPort); + break; + case e_Publisher: + nSockDes = m_nSocketID = + CIPComSocketHandler::openUDPSendPort(pa_acLayerParameter, nPort, &m_tDestAddr); + break; + case e_Subscriber: + nSockDes = m_nSocketID = + CIPComSocketHandler::openUDPReceivePort(pa_acLayerParameter, nPort); + break; + } + + if(CIPComSocketHandler::scm_nInvalidSocketDescriptor != nSockDes){ + if(e_Publisher != m_poFb->getComServiceType()){ + //Publishers should not be registered for receiving data + CIPComSocketHandler::getInstance().addComCallback(nSockDes, this); + } + eRetVal = e_InitOk; + } + else{ + m_eConnectionState = e_Disconnected; + } + } + return eRetVal; +} + +void CIPComLayer::closeSocket(CIPComSocketHandler::TSocketDescriptor *pa_nSocketID){ + if(CIPComSocketHandler::scm_nInvalidSocketDescriptor != *pa_nSocketID){ + CIPComSocketHandler::getInstance().removeComCallback(*pa_nSocketID); + CIPComSocketHandler::closeSocket(*pa_nSocketID); + *pa_nSocketID = CIPComSocketHandler::scm_nInvalidSocketDescriptor; + } +} + +void CIPComLayer::handledConnectedDataRecv(){ + // in case of fragmented packets, it can occur that the buffer is full, + // to avoid calling receiveDataFromTCP with a buffer size of 0 wait until buffer is larger 0 + while((cg_unIPLayerRecvBufferSize - m_unBufFillSize) <= 0){ +#ifdef WIN32 + Sleep(0); +#else + sleep(0); +#endif + } + if(CIPComSocketHandler::scm_nInvalidSocketDescriptor != m_nSocketID){ + // TODO: sync buffer and bufFillSize + int nRetVal = 0; + switch (m_poFb->getComServiceType()){ + case e_Server: + case e_Client: + nRetVal = + CIPComSocketHandler::receiveDataFromTCP(m_nSocketID, &m_acRecvBuffer[m_unBufFillSize], cg_unIPLayerRecvBufferSize + - m_unBufFillSize); + break; + case e_Publisher: + //do nothing as subscribers cannot receive data + break; + case e_Subscriber: + nRetVal = + CIPComSocketHandler::receiveDataFromUDP(m_nSocketID, &m_acRecvBuffer[m_unBufFillSize], cg_unIPLayerRecvBufferSize + - m_unBufFillSize); + break; + } + switch (nRetVal){ + case 0: + DEVLOG_INFO("Connection closed by peer\n"); + m_eInterruptResp = e_InitTerminated; + closeSocket (&m_nSocketID); + if(e_Server == m_poFb->getComServiceType()){ + //Move server into listening mode again + m_eConnectionState = e_Listening; + } + break; + case -1: + m_eInterruptResp = e_ProcessDataRecvFaild; + break; + default: + //we successfully received data + m_unBufFillSize += nRetVal; + m_eInterruptResp = e_ProcessDataOk; + break; + } + m_poFb->interruptCommFB(this); + } +} + +void CIPComLayer::handleConnectionAttemptInConnected(){ + //accept and immediately close the connection to tell the client that we are not available + //sofar the best option I've found for handling single connection servers + CIPComSocketHandler::TSocketDescriptor socketID = CIPComSocketHandler::acceptTCPConnection(m_nListeningID); + CIPComSocketHandler::closeSocket(socketID); +} diff --git a/src/core/cominfra/ipcomlayer.h b/src/core/cominfra/ipcomlayer.h new file mode 100644 index 000000000..3757ef58d --- /dev/null +++ b/src/core/cominfra/ipcomlayer.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2010-2015 fortiss, TU Wien ACIN and Profactor GmbH. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation, rework communication infrastructure and bug fixes + * Michael Hofmann - layer based communication infrastructure + *******************************************************************************/ +#ifndef IPCOMLAYER_H_ +#define IPCOMLAYER_H_ + +#include +#include "comlayer.h" +#include + +namespace forte { + + namespace com_infra { + + class CIPComLayer : public CComLayer{ + public: + CIPComLayer(CComLayer* pa_poUpperLayer, CCommFB* pa_poComFB); + virtual ~CIPComLayer(); + + EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); // top interface, called from top + EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + + EComResponse processInterrupt(); + + protected: + void closeConnection(); + + private: + static void closeSocket(CIPComSocketHandler::TSocketDescriptor *pa_nSocketID); + + EComResponse openConnection(char *pa_acLayerParameter); + void handledConnectedDataRecv(); + void handleConnectionAttemptInConnected(); + + CIPComSocketHandler::TSocketDescriptor m_nSocketID; + CIPComSocketHandler::TSocketDescriptor m_nListeningID; //!> to be used by server type connections. there the m_nSocketID will be used for the accepted connection. + CIPComSocketHandler::TUDPDestAddr m_tDestAddr; + EComResponse m_eInterruptResp; + char m_acRecvBuffer[cg_unIPLayerRecvBufferSize]; + unsigned int m_unBufFillSize; + }; + + } + +} + +#endif /* IPCOMLAYER_H_ */ diff --git a/src/core/cominfra/localcomlayer.cpp b/src/core/cominfra/localcomlayer.cpp new file mode 100644 index 000000000..5765f6306 --- /dev/null +++ b/src/core/cominfra/localcomlayer.cpp @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 fortiss and TU Wien ACIN. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and bug fixes + * Patrik Smejkal - rename interrupt in interruptCCommFB + *******************************************************************************/ +#include "localcomlayer.h" +#include "../resource.h" +#include "../device.h" +#include "../utils/criticalregion.h" + +using namespace forte::com_infra; + +CLocalComLayer::CLocalCommGroupsManager CLocalComLayer::sm_oLocalCommGroupsManager; + +CLocalComLayer::CLocalComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB) : + CComLayer(pa_poUpperLayer, pa_poFB), m_poLocalCommGroup(0){ +} + +CLocalComLayer::~CLocalComLayer(){ + closeConnection(); +} + +void CLocalComLayer::closeConnection(){ + if(0 != m_poLocalCommGroup){ + if(e_Publisher == m_poFb->getComServiceType()){ + sm_oLocalCommGroupsManager.unregisterPubl(m_poLocalCommGroup, this); + } + else{ + sm_oLocalCommGroupsManager.unregisterSubl(m_poLocalCommGroup, this); + } + } +} + +EComResponse CLocalComLayer::sendData(void *, unsigned int){ + CCriticalRegion criticalRegion(m_poFb->getResource().m_oResDataConSync); + CIEC_ANY *aSDs = m_poFb->getSDs(); + unsigned int unNumSDs = m_poFb->getNumSD(); + + // go through GroupList and trigger all Subscribers + for(CSinglyLinkedList::Iterator listiter(m_poLocalCommGroup->m_lSublList.begin()); listiter != m_poLocalCommGroup->m_lSublList.end(); ++listiter){ + setRDs((*listiter), aSDs, unNumSDs); + } + return e_ProcessDataOk; +} + +void CLocalComLayer::setRDs(CLocalComLayer *pa_poSublLayer, CIEC_ANY *pa_aSDs, unsigned int pa_unNumSDs){ + CSyncObject *poTargetResDataConSync = 0; + if(m_poFb->getResourcePtr() != pa_poSublLayer->m_poFb->getResourcePtr()){ + poTargetResDataConSync = &(pa_poSublLayer->m_poFb->getResourcePtr()->m_oResDataConSync); + poTargetResDataConSync->lock(); + } + + CIEC_ANY *aRDs = pa_poSublLayer->m_poFb->getRDs(); + + for(unsigned int i = 0; (i < pa_unNumSDs) && (i < pa_poSublLayer->m_poFb->getNumRD()); ++i){ + if(aRDs[i].getDataTypeID() == pa_aSDs[i].getDataTypeID()){ + aRDs[i].setValue(pa_aSDs[i]); + } + } + + pa_poSublLayer->m_poFb->interruptCommFB(pa_poSublLayer); + m_poFb->getResource().getDevice().getDeviceExecution().startNewEventChain(pa_poSublLayer->m_poFb); + + if(0 != poTargetResDataConSync){ + poTargetResDataConSync->unlock(); + } +} + +EComResponse CLocalComLayer::openConnection(char *pa_acLayerParameter){ + CStringDictionary::TStringId nId = CStringDictionary::getInstance().insert(pa_acLayerParameter); + + switch (m_poFb->getComServiceType()){ + case e_Server: + case e_Client: + break; + case e_Publisher: + m_poLocalCommGroup = sm_oLocalCommGroupsManager.registerPubl(nId, this); + break; + case e_Subscriber: + m_poLocalCommGroup = sm_oLocalCommGroupsManager.registerSubl(nId, this); + break; + } + return (0 != m_poLocalCommGroup) ? e_InitOk : e_InitInvalidId; +} + +/********************** CLocalCommGroupsManager *************************************/ +CLocalComLayer::SLocalCommGroup* CLocalComLayer::CLocalCommGroupsManager::registerPubl(const CStringDictionary::TStringId pa_nID, CLocalComLayer *pa_poLayer){ + CCriticalRegion criticalRegion(m_oSync); + SLocalCommGroup *poGroup = findLocalCommGroup(pa_nID); + if(0 == poGroup){ + poGroup = createLocalCommGroup(pa_nID); + } + poGroup->m_lPublList.push_back(pa_poLayer); + + return poGroup; +} + +void CLocalComLayer::CLocalCommGroupsManager::unregisterPubl(SLocalCommGroup *pa_poGroup, CLocalComLayer *pa_poLayer){ + CCriticalRegion criticalRegion(m_oSync); + removeListEntry(pa_poGroup->m_lPublList, pa_poLayer); + + if((pa_poGroup->m_lPublList.isEmpty()) && (pa_poGroup->m_lSublList.isEmpty())){ + removeCommGroup(pa_poGroup); + } + +} + +CLocalComLayer::SLocalCommGroup* CLocalComLayer::CLocalCommGroupsManager::registerSubl(const CStringDictionary::TStringId pa_nID, CLocalComLayer *pa_poLayer){ + CCriticalRegion criticalRegion(m_oSync); + SLocalCommGroup *poGroup = findLocalCommGroup(pa_nID); + if(0 == poGroup){ + poGroup = createLocalCommGroup(pa_nID); + } + poGroup->m_lSublList.push_back(pa_poLayer); + + return poGroup; +} + +void CLocalComLayer::CLocalCommGroupsManager::unregisterSubl(SLocalCommGroup *pa_poGroup, CLocalComLayer *pa_poLayer){ + CCriticalRegion criticalRegion(m_oSync); + removeListEntry(pa_poGroup->m_lSublList, pa_poLayer); + + if((pa_poGroup->m_lPublList.isEmpty()) && (pa_poGroup->m_lSublList.isEmpty())){ + removeCommGroup(pa_poGroup); + } +} + +CLocalComLayer::SLocalCommGroup* CLocalComLayer::CLocalCommGroupsManager::findLocalCommGroup(CStringDictionary::TStringId pa_nID){ + SLocalCommGroup *poGroup = 0; + + if(!m_lstLocalCommGroups.isEmpty()){ + CSinglyLinkedList::Iterator it = m_lstLocalCommGroups.begin(); + while(it != m_lstLocalCommGroups.end()){ + if((*it).m_nGroupName == pa_nID){ + poGroup = &(*it); + break; + } + ++it; + } + } + + return poGroup; +} + +CLocalComLayer::SLocalCommGroup* CLocalComLayer::CLocalCommGroupsManager::createLocalCommGroup(CStringDictionary::TStringId pa_nID){ + m_lstLocalCommGroups.push_front(SLocalCommGroup(pa_nID)); + CSinglyLinkedList::Iterator it = m_lstLocalCommGroups.begin(); + return &(*it); +} + +void CLocalComLayer::CLocalCommGroupsManager::removeListEntry(CSinglyLinkedList &pa_rlstList, CLocalComLayer *pa_poLayer){ + CSinglyLinkedList::Iterator itRunner = pa_rlstList.begin(); + CSinglyLinkedList::Iterator itRevNode = pa_rlstList.begin(); + + while(itRunner != pa_rlstList.end()){ + if((*itRunner) == pa_poLayer){ + if(itRevNode == pa_rlstList.end()){ + pa_rlstList.pop_front(); + } + else{ + pa_rlstList.eraseAfter(itRevNode); + } + break; + } + itRevNode = itRunner; + ++itRunner; + } +} + +void CLocalComLayer::CLocalCommGroupsManager::removeCommGroup(SLocalCommGroup *pa_poGroup){ + CSinglyLinkedList::Iterator itRunner = m_lstLocalCommGroups.begin(); + CSinglyLinkedList::Iterator itRevNode = m_lstLocalCommGroups.end(); + + while(itRunner != m_lstLocalCommGroups.end()){ + if((*itRunner).m_nGroupName == pa_poGroup->m_nGroupName){ + if(itRevNode == m_lstLocalCommGroups.end()){ + m_lstLocalCommGroups.pop_front(); + } + else{ + m_lstLocalCommGroups.eraseAfter(itRevNode); + } + break; + } + itRevNode = itRunner; + ++itRunner; + } +} + +char *CLocalComLayer::getDefaultLocalCommIdString(const char *pa_acIdValue){ + char * acRetVal = new char[strlen(pa_acIdValue) + 6]; + strcpy(acRetVal, "loc["); + strcat(acRetVal, pa_acIdValue); + strcat(acRetVal, "]"); + return acRetVal; +} diff --git a/src/core/cominfra/localcomlayer.h b/src/core/cominfra/localcomlayer.h new file mode 100644 index 000000000..528c254c5 --- /dev/null +++ b/src/core/cominfra/localcomlayer.h @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 fortiss and TU Wien ACIN. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef LOCALCOMLAYER_H_ +#define LOCALCOMLAYER_H_ + +#include "comlayer.h" +#include "commfb.h" +#include "../stringdict.h" +#include "../fortelist.h" +#include + +namespace forte { + + namespace com_infra { + + class CLocalComLayer : public CComLayer{ + + public: + static char *getDefaultLocalCommIdString(const char *pa_acIdValue); + + CLocalComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB); + virtual ~CLocalComLayer(); + + virtual void closeConnection(); + virtual EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); + virtual EComResponse recvData(const void *, unsigned int ){ + return e_ProcessDataOk; + } + + virtual EComResponse processInterrupt(){ + return e_ProcessDataOk; + } + + protected: + private: + virtual EComResponse openConnection(char *pa_acLayerParameter); + void setRDs(CLocalComLayer *pa_poSublLayer, CIEC_ANY *pa_aSDs, unsigned int pa_unNumSDs); + + struct SLocalCommGroup{ + + SLocalCommGroup(CStringDictionary::TStringId pa_nGroupName) : + m_nGroupName(pa_nGroupName), m_lPublList(), m_lSublList(){ + } + + SLocalCommGroup(const SLocalCommGroup& pa_roLocalCommGroup) : + m_nGroupName(pa_roLocalCommGroup.m_nGroupName), m_lPublList(), m_lSublList(){ + } + + ~SLocalCommGroup(){ + } + + CStringDictionary::TStringId m_nGroupName; + CSinglyLinkedList m_lPublList; + CSinglyLinkedList m_lSublList; + }; + + class CLocalCommGroupsManager{ + + public: + + SLocalCommGroup* registerPubl(const CStringDictionary::TStringId pa_nID, CLocalComLayer *pa_poLayer); + void unregisterPubl(SLocalCommGroup *pa_poGroup, CLocalComLayer *pa_poLayer); + + SLocalCommGroup* registerSubl(const CStringDictionary::TStringId pa_nID, CLocalComLayer *pa_poLayer); + void unregisterSubl(SLocalCommGroup *pa_poGroup, CLocalComLayer *pa_poLayer); + + protected: + private: + CLocalCommGroupsManager(){}; + + SLocalCommGroup* findLocalCommGroup(CStringDictionary::TStringId pa_nID); + SLocalCommGroup* createLocalCommGroup(CStringDictionary::TStringId pa_nID); + void removeCommGroup(SLocalCommGroup *pa_poGroup); + + static void removeListEntry(CSinglyLinkedList &pa_rlstList, CLocalComLayer *pa_poLayer); + + /*!\brief The Sync object used locking the access to the internal used datastructures + */ + CSyncObject m_oSync; + + CSinglyLinkedList m_lstLocalCommGroups; + + friend class CLocalComLayer; + + //not to be implemented + CLocalCommGroupsManager(const CLocalCommGroupsManager &); + CLocalCommGroupsManager &operator =(const CLocalCommGroupsManager&); + }; + + static CLocalCommGroupsManager sm_oLocalCommGroupsManager; + + + SLocalCommGroup *m_poLocalCommGroup; + }; + } + +} + +#endif /* LOCALCOMLAYER_H_ */ diff --git a/src/core/cominfra/rawdatacomlayer.cpp b/src/core/cominfra/rawdatacomlayer.cpp new file mode 100644 index 000000000..4b94a1282 --- /dev/null +++ b/src/core/cominfra/rawdatacomlayer.cpp @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2013-2015 TU Wien ACIN and fortiss. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians, Monika Wenger + * - initial implementation + *******************************************************************************/ +#include "rawdatacomlayer.h" +#include +#include + +namespace forte { + namespace com_infra { + + CRawDataComLayer::CRawDataComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB) : CComLayer(pa_poUpperLayer, pa_poFB){ + m_cTerminatorSybmol = '\n'; + } + + CRawDataComLayer::~CRawDataComLayer(){ + } + + void CRawDataComLayer::closeConnection(){ + if(0 != m_poBottomLayer){ + m_poBottomLayer->closeConnection(); + } + } + + EComResponse CRawDataComLayer::sendData( void *pa_pvData, unsigned int){ + temp.clear(); + TConstIEC_ANYPtr apoSDs = static_cast(pa_pvData); + temp.reserve(static_cast(static_cast(apoSDs[0]).length() + 1)); + temp = static_cast(apoSDs[0]); + temp.append(const_cast(&m_cTerminatorSybmol),1); + m_poBottomLayer->sendData(reinterpret_cast(temp.getValue()), temp.length()); + return e_ProcessDataOk; + } + + EComResponse CRawDataComLayer::recvData( const void *pa_pvData, unsigned int pa_unSize){ + if (0 == m_poTopLayer && m_poFb->getNumRD() == 1){ + m_poFb->getRDs()[0].saveAssign(CIEC_STRING(static_cast(pa_pvData))); + } + return e_ProcessDataOk; + } + + EComResponse CRawDataComLayer::openConnection(char *){ + switch (m_poFb->getComServiceType()){ + case e_Client: + case e_Publisher: + if(m_poFb->getNumSD() != 1 || (m_poFb->getNumSD() > 0 && CIEC_ANY::e_STRING != m_poFb->getSDs()[0].getDataTypeID())){ + return e_InitTerminated; + } + break; + case e_Server: + case e_Subscriber: + if(m_poFb->getNumRD() != 1 || (m_poFb->getNumRD() > 0 && CIEC_ANY::e_STRING != m_poFb->getRDs()[0].getDataTypeID())){ + return e_InitTerminated; + } + break; + } + return e_InitOk; + } + } /* namespace com_infra */ +} /* namespace forte */ diff --git a/src/core/cominfra/rawdatacomlayer.h b/src/core/cominfra/rawdatacomlayer.h new file mode 100644 index 000000000..9fa4fb7ee --- /dev/null +++ b/src/core/cominfra/rawdatacomlayer.h @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2013-2015 TU Wien ACIN and fortiss. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians, Monika Wenger + * - initial implementation + *******************************************************************************/ +#ifndef RAWDATACOMLAYER_H_ +#define RAWDATACOMLAYER_H_ + +#include "comlayer.h" +#include + +namespace forte { + namespace com_infra { + class CRawDataComLayer : public CComLayer{ + public: + CRawDataComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB); + virtual ~CRawDataComLayer(); + virtual void closeConnection(); + virtual EComResponse sendData( void *pa_pvData, unsigned int pa_unSize ); + virtual EComResponse recvData( const void *pa_pvData, unsigned int pa_unSize ); + virtual EComResponse openConnection( char *pa_acLayerParameter ); + private: + CIEC_STRING temp; + char m_cTerminatorSybmol; + }; + } /* namespace com_infra */ +} /* namespace forte */ +#endif /* RAWDATACOMLAYER_H_ */ diff --git a/src/core/conn.cpp b/src/core/conn.cpp new file mode 100644 index 000000000..a0a1e7157 --- /dev/null +++ b/src/core/conn.cpp @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Ingo Hegny, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "conn.h" +#include "stringdict.h" + +CConnection::CConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId) : + mSourceId(paSrcFB, paSrcPortId){ +} + +EMGMResponse CConnection::addDestination(const SConnectionPoint &paDestPoint){ + EMGMResponse retval = e_INVALID_STATE; + + if(!dstExists(paDestPoint)){ // check if there is up to now no such fan out with this destination + mDestinationIds.push_back(paDestPoint); + retval = e_RDY; + } + return retval; +} + +#ifndef FORTE_CLASS_0 +EMGMResponse CConnection::removeDestination(const SConnectionPoint &paDestPoint){ + EMGMResponse retval = e_INVALID_STATE; + + TDestinationIdList::Iterator itRunner = mDestinationIds.begin(); + TDestinationIdList::Iterator itRefNode = mDestinationIds.end(); + + while(itRunner != mDestinationIds.end()){ + if(paDestPoint == (*itRunner)){ + retval = e_RDY; + if(itRefNode == mDestinationIds.end()){ + mDestinationIds.pop_front(); + } + else{ + mDestinationIds.eraseAfter(itRefNode); + } + break; + } + itRefNode = itRunner; + ++itRunner; + } + + return retval; +} +#endif + +void CConnection::setSource(CFunctionBlock *paSrcFB, TPortId paSrcPortId){ + mSourceId.mFB = paSrcFB; + mSourceId.mPortId = paSrcPortId; +} + +bool CConnection::dstExists(const SConnectionPoint &paDestPoint){ + bool bRetVal = false; + for(TDestinationIdList::Iterator it = mDestinationIds.begin(); + it != mDestinationIds.end(); ++it){ + if(paDestPoint == (*it)){ + bRetVal = true; + break; + } + } + return bRetVal; +} + + diff --git a/src/core/conn.h b/src/core/conn.h new file mode 100644 index 000000000..a2da89fb1 --- /dev/null +++ b/src/core/conn.h @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * Michael Hofmann + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _CONN_H_ +#define _CONN_H_ + +#include "fortelist.h" +#include "mgmcmd.h" +#include "stringdict.h" + +//forward declaration of a few classes to reduce includefile dependencies +class CFunctionBlock; + +struct SConnectionPoint{ + CFunctionBlock *mFB; + TPortId mPortId; + + SConnectionPoint(CFunctionBlock *paFB, TPortId paPortId) : + mFB(paFB), mPortId(paPortId){ + } + + SConnectionPoint():mFB(0), mPortId(0) { + } + + bool operator==(const SConnectionPoint & paRight) const{ + return ((mFB == paRight.mFB) && (mPortId == paRight.mPortId)); + } +}; + +/*!\ingroup CORE \brief Base class for handling a connection. + */ + +class CConnection{ + public: + CConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId); + + virtual ~CConnection(){ + } + ; + /*! \brief Establishes a connection. + * + * With this command the connection is created and the FBs are set to appropriate states. + * As connections are stored at the function block outputs this mainly affects the destination of + * the connection. + * + * A child needs to implement this function! + * + * \param paDstFB the destination FB of this connection + * \param paDestPortNameId the input port name to which this connection should be connected to + * \return can be the following response: + * - e_RDY... creation went well. + * - e_NO_SUCH_OBJECT... The destination is not a valid input. + * - e_INVALID_STATE... The specified connection already exists. + */ + virtual EMGMResponse connect(CFunctionBlock *paDstFB, + CStringDictionary::TStringId paDstPortNameId) = 0; + + /*!\brief establish an event connection of a CFB to an event output of the CFB. + * + */ + virtual EMGMResponse connectToCFBInterface(CFunctionBlock *paDstFB, + CStringDictionary::TStringId paDstPortNameId) = 0; + +#ifndef FORTE_CLASS_0 + /*! \brief Disconnects the connection. + * + * With this command the connection is removed and the FBs are set to appropriate states. + * This mainly effects the destination of the connection as the source point is the storage + * for the connection object + * + * A child needs to implement this function! + * + * \param paDstFB the destination FB of this connection + * \param paDestPortNameId the input port name to from which this connection should be removed + * \return can be the following response: + * - e_RDY... creation went well. + * - e_NO_SUCH_OBJECT... The destination is not a valid input. + * - e_INVALID_STATE... this connection is not connected to the destination + */ + virtual EMGMResponse disconnect(CFunctionBlock *paDstFB, + CStringDictionary::TStringId paDstPortNameId) = 0; + #endif + + /*! \brief Check if there are destinations added to this connection + * + * \return TRUE if there is no destination in the connection. + */ + bool isEmpty(void) const{ + return mDestinationIds.isEmpty(); + } + + bool isConnected() const{ + return !isEmpty(); + } + + /*! \brief Get the source string of the connection + */ + const SConnectionPoint& getSourceId(void) const{ + return mSourceId; + } + + protected: + EMGMResponse addDestination(const SConnectionPoint &paDestPoint); + #ifndef FORTE_CLASS_0 + EMGMResponse removeDestination(const SConnectionPoint &paDestPoint); + #endif + + void setSource(CFunctionBlock *paSrcFB, TPortId paSrcPortId); + + //!Non const version + SConnectionPoint& getSourceId(void){ + return mSourceId; + } + + typedef CSinglyLinkedList TDestinationIdList; + + /*!\brief a list of destinations the connection is connected to. + * + * By storing a list of destinations an implicit support for fan-out is given. + * The destination is represented as string id the same way as the sourceId + */ + TDestinationIdList mDestinationIds; + + /*!\brief An identifier for the source of this connection + * + * The source is identified by a FB pointer and the port ID + */ + SConnectionPoint mSourceId; + + private: + + //! Check if there is already a connection within this connection with the same dst. + bool dstExists(const SConnectionPoint &paDestPoint); +}; + +#endif /*_CONN_H_*/ diff --git a/src/core/convert_functions.h b/src/core/convert_functions.h new file mode 100644 index 000000000..ab53f4482 --- /dev/null +++ b/src/core/convert_functions.h @@ -0,0 +1,2245 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Monika Wenger, Carolyn Oates, Patrick Smejkal, + * Matthias Plasch, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef CONVERT_FUNCTIONS_H_ +#define CONVERT_FUNCTIONS_H_ + +#include "datatypes/forte_any.h" +#include "datatypes/forte_bool.h" +#include "datatypes/forte_byte.h" +#include "datatypes/forte_dint.h" +#include "datatypes/forte_dword.h" +#include "datatypes/forte_int.h" +#include "datatypes/forte_lint.h" +#include "datatypes/forte_lreal.h" +#include "datatypes/forte_lword.h" +#include "datatypes/forte_real.h" +#include "datatypes/forte_sint.h" +#include "datatypes/forte_udint.h" +#include "datatypes/forte_uint.h" +#include "datatypes/forte_ulint.h" +#include "datatypes/forte_usint.h" +#include "datatypes/forte_word.h" +#include "datatypes/forte_string.h" +#include "datatypes/forte_wstring.h" +#include "datatypes/forte_time.h" +#include "datatypes/forte_time_of_day.h" +#include "datatypes/forte_date_and_time.h" +#include "datatypes/forte_date.h" +//#include +#include + +/*! \file + * This file implements the type conversion functions as defined by IEC 61131-3 in subclause 2.5.1.5.1 + */ + +//******************************************************************************************** +// DT_TO_** functions +//******************************************************************************************** +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_DATE DT_TO_DATE(const CIEC_DATE_AND_TIME &pa_roVal){ + TForteUInt64 nBuffer = pa_roVal; + time_t t = static_cast(nBuffer / 1000); +#if ! defined(WINCE) + struct tm *ptm = localtime(&t); +#else + struct tm *ptm = wceex_localtime(&t); +#endif + + if(ptm == 0) + return CIEC_DATE(0); + + ptm->tm_hour = 0; + ptm->tm_min = 0; + ptm->tm_sec = 0; + +#if ! defined(WINCE) + t = mktime(ptm); +#else + t = wceex_mktime(ptm); +#endif + + if(t == (time_t) -1) + return CIEC_DATE(0); + + return CIEC_DATE(t * 1000ULL); +} + +inline const CIEC_DATE_AND_TIME DATE_TO_DT(const CIEC_DATE &pa_roVal){ + //this should be sufficient + return CIEC_DATE_AND_TIME((TForteUInt64) pa_roVal); +} + +inline const CIEC_TIME_OF_DAY DT_TO_TOD(const CIEC_DATE_AND_TIME &pa_roVal){ + TForteUInt64 nBuffer = pa_roVal; + time_t t = static_cast(nBuffer / 1000); +#if ! defined(WINCE) + struct tm *ptm = localtime(&t); +#else + struct tm *ptm = wceex_localtime(&t); +#endif + + if(ptm == 0) + return CIEC_TIME_OF_DAY(0); + + ptm->tm_hour = 0; + ptm->tm_min = 0; + ptm->tm_sec = 0; + + return CIEC_TIME_OF_DAY((TForteUInt64) (ptm->tm_hour * 3600 + ptm->tm_min * 60 + ptm->tm_sec) * 1000ULL + (nBuffer % 1000)); +} +#endif + +//******************************************************************************************** +// WSTRING_TO_* functions +//******************************************************************************************** +#ifdef FORTE_USE_WSTRING_DATATYPE + inline const CIEC_BOOL WSTRING_TO_BOOL(const CIEC_WSTRING &pa_roVal){ + CIEC_BOOL tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_BYTE WSTRING_TO_BYTE(const CIEC_WSTRING &pa_roVal){ + CIEC_BYTE tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_DWORD WSTRING_TO_DWORD(const CIEC_WSTRING &pa_roVal){ + CIEC_DWORD tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_WORD WSTRING_TO_WORD(const CIEC_WSTRING &pa_roVal){ + CIEC_WORD tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_DINT WSTRING_TO_DINT(const CIEC_WSTRING &pa_roVal){ + CIEC_DINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_INT WSTRING_TO_INT(const CIEC_WSTRING &pa_roVal){ + CIEC_INT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_UINT WSTRING_TO_UINT(const CIEC_WSTRING &pa_roVal){ + CIEC_UINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_UDINT WSTRING_TO_UDINT(const CIEC_WSTRING &pa_roVal){ + CIEC_UDINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_USINT WSTRING_TO_USINT(const CIEC_WSTRING &pa_roVal){ + CIEC_USINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_STRING WSTRING_TO_STRING(const CIEC_WSTRING &pa_roVal){ + CIEC_STRING tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_TIME WSTRING_TO_TIME(const CIEC_WSTRING &pa_roVal){ + CIEC_TIME tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_SINT WSTRING_TO_SINT(const CIEC_WSTRING &pa_roVal){ + CIEC_SINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL WSTRING_TO_REAL(const CIEC_WSTRING &pa_roVal){ + CIEC_REAL tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE + inline const CIEC_LREAL WSTRING_TO_LREAL(const CIEC_WSTRING &pa_roVal){ + CIEC_LREAL tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LINT WSTRING_TO_LINT(const CIEC_WSTRING &pa_roVal){ + CIEC_LINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_LWORD WSTRING_TO_LWORD(const CIEC_WSTRING &pa_roVal){ + CIEC_LWORD tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } + + inline const CIEC_ULINT WSTRING_TO_ULINT(const CIEC_WSTRING &pa_roVal){ + CIEC_ULINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; + } +#endif +#endif + +//******************************************************************************************** +// STRING_TO_* functions +//******************************************************************************************** +inline const CIEC_INT STRING_TO_INT(const CIEC_STRING &pa_roVal){ + CIEC_INT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_UINT STRING_TO_UINT(const CIEC_STRING &pa_roVal){ + CIEC_UINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_USINT STRING_TO_USINT(const CIEC_STRING &pa_roVal){ + CIEC_USINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_SINT STRING_TO_SINT(const CIEC_STRING &pa_roVal){ + CIEC_SINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_DINT STRING_TO_DINT(const CIEC_STRING &pa_roVal){ + CIEC_DINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_UDINT STRING_TO_UDINT(const CIEC_STRING &pa_roVal){ + CIEC_UDINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_BOOL STRING_TO_BOOL(const CIEC_STRING &pa_roVal){ + CIEC_BOOL tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_BYTE STRING_TO_BYTE(const CIEC_STRING &pa_roVal){ + CIEC_BYTE tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_WORD STRING_TO_WORD(const CIEC_STRING &pa_roVal){ + CIEC_WORD tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_DWORD STRING_TO_DWORD(const CIEC_STRING &pa_roVal){ + CIEC_DWORD tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_TIME STRING_TO_TIME(const CIEC_STRING &pa_roVal){ + CIEC_TIME tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL STRING_TO_REAL(const CIEC_STRING &pa_roVal){ + CIEC_REAL tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL STRING_TO_LREAL(const CIEC_STRING &pa_roVal){ + CIEC_LREAL tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT STRING_TO_ULINT(const CIEC_STRING &pa_roVal){ + CIEC_ULINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_LINT STRING_TO_LINT(const CIEC_STRING &pa_roVal){ + CIEC_LINT tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} + +inline const CIEC_LWORD STRING_TO_LWORD(const CIEC_STRING &pa_roVal){ + CIEC_LWORD tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} +#endif + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING STRING_TO_WSTRING(const CIEC_STRING &pa_roVal){ + CIEC_WSTRING tempVal; + const char *pacBuffer = pa_roVal.getValue(); + tempVal.fromString(pacBuffer); + return tempVal; +} +#endif + +//******************************************************************************************** +// LREAL_TO_* functions +//******************************************************************************************** +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_BOOL LREAL_TO_BOOL(const CIEC_LREAL &pa_roVal){ + return CIEC_BOOL((TForteDFloat)0.0 != pa_roVal ? true : false); +} + +inline const CIEC_LWORD LREAL_TO_LWORD(const CIEC_LREAL &pa_roVal){ + return CIEC_LWORD( (0 < pa_roVal) ? (TForteLWord)pa_roVal : CIEC_LWORD::scm_nMinVal); +} + +inline const CIEC_BYTE LREAL_TO_BYTE(const CIEC_LREAL &pa_roVal){ + TForteByte nBuf = static_cast(pa_roVal); + if(CIEC_BYTE::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_BYTE::scm_nMaxVal; + } + else{ + if(CIEC_BYTE::scm_nMinVal > pa_roVal){ + nBuf = CIEC_BYTE::scm_nMinVal; + } + } + return CIEC_BYTE(nBuf); +} + +inline const CIEC_WORD LREAL_TO_WORD(const CIEC_LREAL &pa_roVal){ + TForteWord nBuf = static_cast(pa_roVal); + if(CIEC_WORD::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_WORD::scm_nMaxVal; + } + else{ + if(CIEC_WORD::scm_nMinVal > pa_roVal){ + nBuf = CIEC_WORD::scm_nMinVal; + } + } + return CIEC_WORD(nBuf); +} + +inline const CIEC_DWORD LREAL_TO_DWORD(const CIEC_LREAL &pa_roVal){ + TForteDWord nBuf = static_cast(pa_roVal); + if(CIEC_DWORD::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_DWORD::scm_nMaxVal; + } + else{ + if(CIEC_DWORD::scm_nMinVal > pa_roVal){ + nBuf = CIEC_DWORD::scm_nMinVal; + } + } + return CIEC_DWORD(nBuf); +} + +inline const CIEC_REAL LREAL_TO_REAL(const CIEC_LREAL &pa_roVal){ + CIEC_REAL tempVal; + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + return tempVal; +} + +inline const CIEC_USINT LREAL_TO_USINT(const CIEC_LREAL &pa_roVal){ + CIEC_USINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline const CIEC_UDINT LREAL_TO_UDINT(const CIEC_LREAL &pa_roVal){ + CIEC_UDINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline const CIEC_UINT LREAL_TO_UINT(const CIEC_LREAL &pa_roVal){ + CIEC_UINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline const CIEC_ULINT LREAL_TO_ULINT(const CIEC_LREAL &pa_roVal){ + CIEC_ULINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline CIEC_ANY::TLargestIntValueType lreal_to_xINT(const CIEC_LREAL &pa_roVal){ + CIEC_ANY::TLargestIntValueType temp; + #if defined(WIN32) + temp = (CIEC_ANY::TLargestIntValueType)floor(static_cast(pa_roVal) + 0.5); + #elif defined(VXWORKS) + temp = (CIEC_ANY::TLargestIntValueType)floor(static_cast(pa_roVal) + 0.5); + #else + temp = lroundf(static_cast(pa_roVal)); + #endif + if(static_cast(pa_roVal) > 0){ + if(((temp % 2) != 0) && ((static_cast(temp) - 0.5f) == static_cast(pa_roVal))){ + temp = temp - 1; + } + }else{ + if(((temp % 2) != 0) && ((static_cast(temp) + 0.5f) == static_cast(pa_roVal))){ + temp = temp + 1; + } + } + return temp; +} + +inline const CIEC_LINT LREAL_TO_LINT(const CIEC_LREAL &pa_roVal){ + return CIEC_LINT( static_cast(lreal_to_xINT(pa_roVal)) ); +} + +inline const CIEC_DINT LREAL_TO_DINT(const CIEC_LREAL &pa_roVal){ + return CIEC_DINT( static_cast(lreal_to_xINT(pa_roVal)) ); +} + +inline const CIEC_SINT LREAL_TO_SINT(const CIEC_LREAL &pa_roVal){ + return CIEC_SINT( static_cast(lreal_to_xINT(pa_roVal)) ); +} + +inline const CIEC_INT LREAL_TO_INT(const CIEC_LREAL &pa_roVal){ + return CIEC_INT( static_cast(lreal_to_xINT(pa_roVal))); +} + +inline const CIEC_STRING LREAL_TO_STRING(const CIEC_LREAL &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_LREAL::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_LREAL::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING LREAL_TO_WSTRING(const CIEC_LREAL &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_LREAL::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_LREAL::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME LREAL_TO_TIME(const CIEC_LREAL &pa_roVal){ + if(pa_roVal > 0){ + return CIEC_TIME(static_cast(pa_roVal * FORTE_TIME_BASE_UNITS_PER_SECOND)); + }else{ + return CIEC_TIME(static_cast(0)); + } +} +#endif + +//******************************************************************************************** +// REAL_TO_* functions +//******************************************************************************************** +#ifdef FORTE_USE_REAL_DATATYPE +inline CIEC_ANY::TLargestIntValueType real_to_xINT(const CIEC_REAL &pa_roVal){ + CIEC_ANY::TLargestIntValueType temp; + #if defined(WIN32) + temp = (CIEC_ANY::TLargestIntValueType)floor(static_cast(pa_roVal) + 0.5); + #elif defined(VXWORKS) + temp = (CIEC_ANY::TLargestIntValueType)floor(static_cast(pa_roVal) + 0.5); + #else + temp = lroundf(static_cast(pa_roVal)); + #endif + if(static_cast(pa_roVal) > 0){ + if(((temp % 2) != 0) && ((static_cast(temp) - 0.5f) == static_cast(pa_roVal))){ + temp = temp - 1; + } + }else{ + if(((temp % 2) != 0) && ((static_cast(temp) + 0.5f) == static_cast(pa_roVal))){ + temp = temp + 1; + } + } + return temp; +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT REAL_TO_LINT(const CIEC_REAL &pa_roVal){ + return CIEC_LINT( static_cast(real_to_xINT(pa_roVal)) ); +} + +inline const CIEC_LWORD REAL_TO_LWORD(const CIEC_REAL &pa_roVal){ + return CIEC_LWORD( (0 < pa_roVal) ? (TForteLWord)pa_roVal : CIEC_LWORD::scm_nMinVal); +} + +inline const CIEC_ULINT REAL_TO_ULINT(const CIEC_REAL &pa_roVal){ + CIEC_ULINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline const CIEC_LREAL REAL_TO_LREAL(const CIEC_REAL &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +inline const CIEC_DINT REAL_TO_DINT(const CIEC_REAL &pa_roVal){ + return CIEC_DINT( static_cast(real_to_xINT(pa_roVal)) ); +} + +inline const CIEC_SINT REAL_TO_SINT(const CIEC_REAL &pa_roVal){ + return CIEC_SINT( static_cast(real_to_xINT(pa_roVal)) ); +} + +inline const CIEC_INT REAL_TO_INT(const CIEC_REAL &pa_roVal){ + return CIEC_INT( static_cast(real_to_xINT(pa_roVal))); +} + +inline const CIEC_USINT REAL_TO_USINT(const CIEC_REAL &pa_roVal){ + CIEC_USINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline const CIEC_UINT REAL_TO_UINT(const CIEC_REAL &pa_roVal){ + CIEC_UINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline const CIEC_UDINT REAL_TO_UDINT(const CIEC_REAL &pa_roVal){ + CIEC_UDINT tempVal; + if(0 < pa_roVal){ + CIEC_ANY::specialCast(const_cast(pa_roVal), tempVal); + } + return tempVal; +} + +inline const CIEC_STRING REAL_TO_STRING(const CIEC_REAL &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_REAL::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_REAL::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING REAL_TO_WSTRING(const CIEC_REAL &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_REAL::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_REAL::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME REAL_TO_TIME(const CIEC_REAL &pa_roVal){ + if(pa_roVal > 0){ + return CIEC_TIME(static_cast(pa_roVal * FORTE_TIME_BASE_UNITS_PER_SECOND)); + }else{ + return CIEC_TIME(static_cast(0)); + } +} + +inline const CIEC_BOOL REAL_TO_BOOL(const CIEC_REAL &pa_roVal){ + return CIEC_BOOL((TForteFloat)0.0 != pa_roVal ? true : false); +} + +inline const CIEC_BYTE REAL_TO_BYTE(const CIEC_REAL &pa_roVal){ + TForteByte nBuf = static_cast(pa_roVal); + if(CIEC_BYTE::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_BYTE::scm_nMaxVal; + } + else{ + if(CIEC_BYTE::scm_nMinVal > pa_roVal){ + nBuf = CIEC_BYTE::scm_nMinVal; + } + } + return CIEC_BYTE(nBuf); +} + +inline const CIEC_WORD REAL_TO_WORD(const CIEC_REAL &pa_roVal){ + TForteWord nBuf = static_cast(pa_roVal); + if(CIEC_WORD::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_WORD::scm_nMaxVal; + } + else{ + if(CIEC_WORD::scm_nMinVal > pa_roVal){ + nBuf = CIEC_WORD::scm_nMinVal; + } + } + return CIEC_WORD(nBuf); +} + +inline const CIEC_DWORD REAL_TO_DWORD(const CIEC_REAL &pa_roVal){ + TForteDWord nBuf = static_cast(pa_roVal); + if(CIEC_DWORD::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_DWORD::scm_nMaxVal; + } + else{ + if(CIEC_DWORD::scm_nMinVal > pa_roVal){ + nBuf = CIEC_DWORD::scm_nMinVal; + } + } + return CIEC_DWORD(nBuf); +} +#endif + +//******************************************************************************************** +// TIME_TO_* functions +//******************************************************************************************** +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_BYTE TIME_TO_BYTE(const CIEC_TIME &pa_roVal){ + return CIEC_BYTE(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_WORD TIME_TO_WORD(const CIEC_TIME &pa_roVal){ + return CIEC_WORD(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_DWORD TIME_TO_DWORD(const CIEC_TIME &pa_roVal){ + return CIEC_DWORD(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_UDINT TIME_TO_UDINT(const CIEC_TIME &pa_roVal){ + return CIEC_UDINT(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_UINT TIME_TO_UINT(const CIEC_TIME &pa_roVal){ + return CIEC_UINT(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_SINT TIME_TO_SINT(const CIEC_TIME &pa_roVal){ + return CIEC_SINT(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_USINT TIME_TO_USINT(const CIEC_TIME &pa_roVal){ + return CIEC_USINT(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_DINT TIME_TO_DINT(const CIEC_TIME &pa_roVal){ + return CIEC_DINT(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_INT TIME_TO_INT(const CIEC_TIME &pa_roVal){ + return CIEC_INT(static_cast(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} +#else +inline const CIEC_BYTE TIME_TO_BYTE(const CIEC_TIME &pa_roVal){ + return CIEC_BYTE(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_WORD TIME_TO_WORD(const CIEC_TIME &pa_roVal){ + return CIEC_WORD(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_DWORD TIME_TO_DWORD(const CIEC_TIME &pa_roVal){ + return CIEC_DWORD(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_UDINT TIME_TO_UDINT(const CIEC_TIME &pa_roVal){ + return CIEC_UDINT(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_UINT TIME_TO_UINT(const CIEC_TIME &pa_roVal){ + return CIEC_UINT(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_SINT TIME_TO_SINT(const CIEC_TIME &pa_roVal){ + return CIEC_SINT(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_USINT TIME_TO_USINT(const CIEC_TIME &pa_roVal){ + return CIEC_USINT(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_DINT TIME_TO_DINT(const CIEC_TIME &pa_roVal){ + return CIEC_DINT(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} + +inline const CIEC_INT TIME_TO_INT(const CIEC_TIME &pa_roVal){ + return CIEC_INT(static_cast(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND)); +} +#endif + +inline const CIEC_BOOL TIME_TO_BOOL(const CIEC_TIME &pa_roVal){ + return CIEC_BOOL(0 != pa_roVal.getInMiliSeconds() ? true : false); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD TIME_TO_LWORD(const CIEC_TIME &pa_roVal){ + return CIEC_LWORD(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +inline const CIEC_LINT TIME_TO_LINT(const CIEC_TIME &pa_roVal){ + return CIEC_LINT(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +inline const CIEC_ULINT TIME_TO_ULINT(const CIEC_TIME &pa_roVal){ + return CIEC_ULINT(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL TIME_TO_REAL(const CIEC_TIME &pa_roVal){ +#ifdef FORTE_USE_64BIT_DATATYPES + return CIEC_REAL(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND); +#else + return CIEC_REAL(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND); +#endif +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL TIME_TO_LREAL(const CIEC_TIME &pa_roVal){ +#ifdef FORTE_USE_64BIT_DATATYPES + return CIEC_LREAL(static_cast(pa_roVal.operator TForteInt64()) /FORTE_TIME_BASE_UNITS_PER_SECOND); +#else + return CIEC_LREAL(static_cast(pa_roVal.operator TForteInt32()) /FORTE_TIME_BASE_UNITS_PER_SECOND); +#endif +} +#endif + +inline const CIEC_STRING TIME_TO_STRING(const CIEC_TIME &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_TIME::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_TIME::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING TIME_TO_WSTRING(const CIEC_TIME &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_TIME::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_TIME::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +//******************************************************************************************** +// BOOL_TO_* functions +//******************************************************************************************** +inline const CIEC_BYTE BOOL_TO_BYTE(const CIEC_BOOL &pa_roVal){ + return CIEC_BYTE((TForteByte)((true == pa_roVal) ? 1 : 0)); +} + +inline const CIEC_DINT BOOL_TO_DINT(const CIEC_BOOL &pa_roVal){ + return CIEC_DINT((TForteInt32)((true == pa_roVal) ? 1 : 0)); +} + +inline const CIEC_DWORD BOOL_TO_DWORD(const CIEC_BOOL &pa_roVal){ + return CIEC_DWORD((TForteDWord)((true == pa_roVal) ? 1 : 0)); +} + +inline const CIEC_INT BOOL_TO_INT(const CIEC_BOOL &pa_roVal){ + return CIEC_INT((TForteInt16)((true == pa_roVal) ? 1 : 0)); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT BOOL_TO_LINT(const CIEC_BOOL &pa_roVal){ + return CIEC_LINT((TForteInt64) (true == pa_roVal) ? 1 : 0); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL BOOL_TO_LREAL(const CIEC_BOOL &pa_roVal){ + return CIEC_LREAL((TForteDFloat) (true == pa_roVal) ? 1.0 : 0.0); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD BOOL_TO_LWORD(const CIEC_BOOL &pa_roVal){ + return CIEC_LWORD((TForteLWord) (true == pa_roVal) ? 1 : 0); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL BOOL_TO_REAL(const CIEC_BOOL &pa_roVal){ + return CIEC_REAL((TForteFloat) (true == pa_roVal) ? 1.0f : 0.0f); +} +#endif + +inline const CIEC_SINT BOOL_TO_SINT(const CIEC_BOOL &pa_roVal){ + return CIEC_SINT((TForteInt8)((true == pa_roVal) ? 1 : 0)); +} + +inline const CIEC_UDINT BOOL_TO_UDINT(const CIEC_BOOL &pa_roVal){ + return CIEC_UDINT((TForteUInt32) (true == pa_roVal) ? 1 : 0); +} + +inline const CIEC_UINT BOOL_TO_UINT(const CIEC_BOOL &pa_roVal){ + return CIEC_UINT((TForteUInt16)((true == pa_roVal) ? 1 : 0)); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT BOOL_TO_ULINT(const CIEC_BOOL &pa_roVal){ + return CIEC_ULINT((TForteUInt64) (true == pa_roVal) ? 1 : 0); +} +#endif + +inline const CIEC_USINT BOOL_TO_USINT(const CIEC_BOOL &pa_roVal){ + return CIEC_USINT((TForteUInt8)( (true == pa_roVal) ? 1 : 0)); +} + +inline const CIEC_WORD BOOL_TO_WORD(const CIEC_BOOL &pa_roVal){ + return CIEC_WORD((TForteWord)((true == pa_roVal) ? 1 : 0)); +} + +inline const CIEC_STRING BOOL_TO_STRING(const CIEC_BOOL &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_BYTE::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_BYTE::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING BOOL_TO_WSTRING(const CIEC_BOOL &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_BYTE::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_BYTE::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME BOOL_TO_TIME(const CIEC_BOOL &pa_roVal){ + return CIEC_TIME(static_cast(true == pa_roVal ? FORTE_TIME_BASE_UNITS_PER_SECOND : 0)); +} + +//******************************************************************************************** +// BYTE_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL BYTE_TO_BOOL(const CIEC_BYTE &pa_roVal){ + return CIEC_BOOL((TForteByte)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT BYTE_TO_DINT(const CIEC_BYTE &pa_roVal){ + return CIEC_DINT((TForteInt32) pa_roVal); +} + +inline const CIEC_DWORD BYTE_TO_DWORD(const CIEC_BYTE &pa_roVal){ + return CIEC_DWORD((TForteDWord) pa_roVal); +} + +inline const CIEC_INT BYTE_TO_INT(const CIEC_BYTE &pa_roVal){ + return CIEC_INT((TForteInt16) pa_roVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT BYTE_TO_LINT(const CIEC_BYTE &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL BYTE_TO_LREAL(const CIEC_BYTE &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD BYTE_TO_LWORD(const CIEC_BYTE &pa_roVal){ + return CIEC_LWORD((TForteLWord) pa_roVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL BYTE_TO_REAL(const CIEC_BYTE &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT BYTE_TO_SINT(const CIEC_BYTE &pa_roVal){ + return CIEC_SINT((TForteInt8) (CIEC_SINT::scm_nMaxVal >= pa_roVal) ? pa_roVal : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_UDINT BYTE_TO_UDINT(const CIEC_BYTE &pa_roVal){ + return CIEC_UDINT((TForteUInt32) pa_roVal); +} + +inline const CIEC_UINT BYTE_TO_UINT(const CIEC_BYTE &pa_roVal){ + return CIEC_UINT((TForteUInt16) pa_roVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT BYTE_TO_ULINT(const CIEC_BYTE &pa_roVal){ + return CIEC_ULINT((TForteUInt64) pa_roVal); +} +#endif + +inline const CIEC_USINT BYTE_TO_USINT(const CIEC_BYTE &pa_roVal){ + return CIEC_USINT((TForteUInt8) pa_roVal); +} + +inline const CIEC_WORD BYTE_TO_WORD(const CIEC_BYTE &pa_roVal){ + return CIEC_WORD((TForteWord) pa_roVal); +} + +inline const CIEC_STRING BYTE_TO_STRING(const CIEC_BYTE &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_BYTE::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_BYTE::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING BYTE_TO_WSTRING(const CIEC_BYTE &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_BYTE::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_BYTE::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME BYTE_TO_TIME(const CIEC_BYTE &pa_roVal){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +//******************************************************************************************** +// DINT_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL DINT_TO_BOOL(const CIEC_DINT &pa_roVal){ + return CIEC_BOOL((TForteInt32)0 != pa_roVal ? true : false); +} + +inline const CIEC_BYTE DINT_TO_BYTE(const CIEC_DINT &pa_roVal){ + TForteByte nBuf = static_cast(pa_roVal); + if(CIEC_BYTE::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_BYTE::scm_nMaxVal; + } + else{ + if(CIEC_BYTE::scm_nMinVal > pa_roVal){ + nBuf = CIEC_BYTE::scm_nMinVal; + } + } + return CIEC_BYTE(nBuf); +} + +inline const CIEC_DWORD DINT_TO_DWORD(const CIEC_DINT &pa_roVal){ + return CIEC_DWORD( ((0 < pa_roVal) ? (TForteDWord)pa_roVal : CIEC_DWORD::scm_nMinVal)); +} + +inline const CIEC_INT DINT_TO_INT(const CIEC_DINT &pa_roVal){ + TForteInt16 nBuf = static_cast(pa_roVal); + if(CIEC_INT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_INT::scm_nMaxVal; + } + else{ + if(CIEC_INT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_INT::scm_nMinVal; + } + } + return CIEC_INT(nBuf); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT DINT_TO_LINT(const CIEC_DINT &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL DINT_TO_LREAL(const CIEC_DINT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD DINT_TO_LWORD(const CIEC_DINT &pa_roVal){ + return CIEC_LWORD( (0 < pa_roVal) ? (TForteLWord)pa_roVal : CIEC_LWORD::scm_nMinVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL DINT_TO_REAL(const CIEC_DINT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT DINT_TO_SINT(const CIEC_DINT &pa_roVal){ + TForteInt8 nBuf = static_cast(pa_roVal); + if(CIEC_SINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_SINT::scm_nMaxVal; + } + else{ + if(CIEC_SINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_SINT::scm_nMinVal; + } + } + return CIEC_SINT(nBuf); +} + +inline const CIEC_UDINT DINT_TO_UDINT(const CIEC_DINT &pa_roVal){ + return CIEC_UDINT( (((CIEC_DINT::TValueType)CIEC_UDINT::scm_nMinVal) < pa_roVal) ? (CIEC_UDINT::TValueType)pa_roVal : CIEC_UDINT::scm_nMinVal); +} + +inline const CIEC_UINT DINT_TO_UINT(const CIEC_DINT &pa_roVal){ + TForteUInt16 nBuf = static_cast(pa_roVal); + if(CIEC_UINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_UINT::scm_nMaxVal; + } + else{ + if(CIEC_UINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_UINT::scm_nMinVal; + } + } + return CIEC_UINT(nBuf); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT DINT_TO_ULINT(const CIEC_DINT &pa_roVal){ + return CIEC_ULINT( (0 < pa_roVal) ? (TForteUInt64)pa_roVal : CIEC_ULINT::scm_nMinVal); +} +#endif + +inline const CIEC_USINT DINT_TO_USINT(const CIEC_DINT &pa_roVal){ + TForteUInt8 nBuf = static_cast(pa_roVal); + if(CIEC_USINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_USINT::scm_nMaxVal; + } + else{ + if(CIEC_USINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_USINT::scm_nMinVal; + } + } + return CIEC_USINT(nBuf); +} + +inline const CIEC_WORD DINT_TO_WORD(const CIEC_DINT &pa_roVal){ + TForteWord nBuf = static_cast(pa_roVal); + if(CIEC_WORD::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_WORD::scm_nMaxVal; + } + else{ + if(CIEC_WORD::scm_nMinVal > pa_roVal){ + nBuf = CIEC_WORD::scm_nMinVal; + } + } + return CIEC_WORD(nBuf); +} + +inline const CIEC_STRING DINT_TO_STRING(const CIEC_DINT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_DINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_DINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING DINT_TO_WSTRING(const CIEC_DINT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_DINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_DINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME DINT_TO_TIME(const CIEC_DINT &pa_roVal){ + if(pa_roVal > 0){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); + }else{ + return CIEC_TIME(static_cast(0)); + } +} + +//******************************************************************************************** +// DWORD_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL DWORD_TO_BOOL(const CIEC_DWORD &pa_roVal){ + return CIEC_BOOL((TForteDWord)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT DWORD_TO_DINT(const CIEC_DWORD &pa_roVal){ + return CIEC_DINT((TForteInt32) (static_cast(CIEC_DINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_DINT::scm_nMaxVal); +} + +inline const CIEC_BYTE DWORD_TO_BYTE(const CIEC_DWORD &pa_roVal){ + return CIEC_BYTE((TForteByte) (static_cast(CIEC_BYTE::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_BYTE::scm_nMaxVal); +} + +inline const CIEC_INT DWORD_TO_INT(const CIEC_DWORD &pa_roVal){ + return CIEC_INT((TForteInt16) (static_cast(CIEC_INT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_INT::scm_nMaxVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT DWORD_TO_LINT(const CIEC_DWORD &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL DWORD_TO_LREAL(const CIEC_DWORD &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD DWORD_TO_LWORD(const CIEC_DWORD &pa_roVal){ + return CIEC_LWORD((TForteLWord) pa_roVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL DWORD_TO_REAL(const CIEC_DWORD &pa_roVal){ + //fprintf(stderr,"DWORD_TO_REAL: %ld, %f\n", pa_roVal.operator TForteDWord(), (TForteFloat) pa_roVal); + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT DWORD_TO_SINT(const CIEC_DWORD &pa_roVal){ + return CIEC_SINT((TForteInt8) (static_cast(CIEC_SINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_UDINT DWORD_TO_UDINT(const CIEC_DWORD &pa_roVal){ + return CIEC_UDINT((TForteUInt32) pa_roVal); +} + +inline const CIEC_UINT DWORD_TO_UINT(const CIEC_DWORD &pa_roVal){ + return CIEC_UINT((TForteUInt16) (static_cast(CIEC_UINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_UINT::scm_nMaxVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT DWORD_TO_ULINT(const CIEC_DWORD &pa_roVal){ + return CIEC_ULINT((TForteUInt64) pa_roVal); +} +#endif + +inline const CIEC_USINT DWORD_TO_USINT(const CIEC_DWORD &pa_roVal){ + return CIEC_USINT((TForteUInt8) (static_cast(CIEC_USINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_USINT::scm_nMaxVal); +} + +inline const CIEC_WORD DWORD_TO_WORD(const CIEC_DWORD &pa_roVal){ + return CIEC_WORD((TForteWord) (static_cast(CIEC_WORD::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_WORD::scm_nMaxVal); +} + +inline const CIEC_TIME DWORD_TO_TIME(const CIEC_DWORD &pa_roVal){ + return CIEC_TIME(static_cast(pa_roVal)* FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +inline const CIEC_STRING DWORD_TO_STRING(const CIEC_DWORD &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_DWORD::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_DWORD::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING DWORD_TO_WSTRING(const CIEC_DWORD &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_DWORD::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_DINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +//******************************************************************************************** +// LWORD_TO_* functions +//******************************************************************************************** +#ifdef FORTE_USE_64BIT_DATATYPES + +inline const CIEC_BOOL LWORD_TO_BOOL(const CIEC_LWORD &pa_roVal){ + return CIEC_BOOL((TForteLWord)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT LWORD_TO_DINT(const CIEC_LWORD &pa_roVal){ + return CIEC_DINT((TForteInt32) (static_cast(CIEC_DINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_DINT::scm_nMaxVal); +} + +inline const CIEC_BYTE LWORD_TO_BYTE(const CIEC_LWORD &pa_roVal){ + return CIEC_BYTE((TForteByte) (static_cast(CIEC_BYTE::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_BYTE::scm_nMaxVal); +} + +inline const CIEC_INT LWORD_TO_INT(const CIEC_LWORD &pa_roVal){ + return CIEC_INT((TForteInt16) (static_cast(CIEC_INT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_INT::scm_nMaxVal); +} + +inline const CIEC_LINT LWORD_TO_LINT(const CIEC_LWORD &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} + + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL LWORD_TO_LREAL(const CIEC_LWORD &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +inline const CIEC_DWORD LWORD_TO_DWORD(const CIEC_LWORD &pa_roVal){ + return CIEC_DWORD((TForteDWord) (static_cast(CIEC_DWORD::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_DWORD::scm_nMaxVal); +} + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL LWORD_TO_REAL(const CIEC_LWORD &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT LWORD_TO_SINT(const CIEC_LWORD &pa_roVal){ + return CIEC_SINT((TForteInt8) (static_cast(CIEC_SINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_UDINT LWORD_TO_UDINT(const CIEC_LWORD &pa_roVal){ + return CIEC_UDINT((TForteUInt32) (static_cast(CIEC_UDINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_UDINT::scm_nMaxVal); +} + +inline const CIEC_UINT LWORD_TO_UINT(const CIEC_LWORD &pa_roVal){ + return CIEC_UINT((TForteUInt16) (static_cast(CIEC_UINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_UINT::scm_nMaxVal); +} + +inline const CIEC_ULINT LWORD_TO_ULINT(const CIEC_LWORD &pa_roVal){ + return CIEC_ULINT((TForteUInt64) pa_roVal); +} + +inline const CIEC_USINT LWORD_TO_USINT(const CIEC_LWORD &pa_roVal){ + return CIEC_USINT((TForteUInt8) (static_cast(CIEC_USINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_USINT::scm_nMaxVal); +} + +inline const CIEC_WORD LWORD_TO_WORD(const CIEC_LWORD &pa_roVal){ + return CIEC_WORD((TForteWord) (static_cast(CIEC_WORD::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_WORD::scm_nMaxVal); +} + +inline const CIEC_STRING LWORD_TO_STRING(const CIEC_LWORD &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_LWORD::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_LWORD::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING LWORD_TO_WSTRING(const CIEC_LWORD &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_LWORD::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_LWORD::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME LWORD_TO_TIME(const CIEC_LWORD &pa_roVal){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); +} +#endif + +//******************************************************************************************** +// UDINT_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL UDINT_TO_BOOL(const CIEC_UDINT &pa_roVal){ + return CIEC_BOOL((TForteUInt32)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT UDINT_TO_DINT(const CIEC_UDINT &pa_roVal){ + return CIEC_DINT((TForteInt32) (static_cast(CIEC_DINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_DINT::scm_nMaxVal); +} + +inline const CIEC_BYTE UDINT_TO_BYTE(const CIEC_UDINT &pa_roVal){ + return CIEC_BYTE((TForteByte) (static_cast(CIEC_BYTE::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_BYTE::scm_nMaxVal); +} + +inline const CIEC_INT UDINT_TO_INT(const CIEC_UDINT &pa_roVal){ + return CIEC_INT((TForteInt16) (static_cast(CIEC_INT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_INT::scm_nMaxVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT UDINT_TO_LINT(const CIEC_UDINT &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL UDINT_TO_LREAL(const CIEC_UDINT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD UDINT_TO_LWORD(const CIEC_UDINT &pa_roVal){ + return CIEC_LWORD((TForteLWord) pa_roVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL UDINT_TO_REAL(const CIEC_UDINT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT UDINT_TO_SINT(const CIEC_UDINT &pa_roVal){ + return CIEC_SINT((TForteInt8) (static_cast(CIEC_SINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_UDINT UDINT_TO_DWORD(const CIEC_UDINT &pa_roVal){ + return CIEC_UDINT((TForteDWord) pa_roVal); +} + +inline const CIEC_UINT UDINT_TO_UINT(const CIEC_UDINT &pa_roVal){ + return CIEC_UINT((TForteUInt16) (static_cast(CIEC_UINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_UINT::scm_nMaxVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT UDINT_TO_ULINT(const CIEC_UDINT &pa_roVal){ + return CIEC_ULINT((TForteUInt64) pa_roVal); +} +#endif + +inline const CIEC_USINT UDINT_TO_USINT(const CIEC_UDINT &pa_roVal){ + return CIEC_USINT((TForteUInt8) (static_cast(CIEC_USINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_USINT::scm_nMaxVal); +} + +inline const CIEC_WORD UDINT_TO_WORD(const CIEC_UDINT &pa_roVal){ + return CIEC_WORD((TForteWord) (static_cast(CIEC_WORD::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_WORD::scm_nMaxVal); +} + +inline const CIEC_STRING UDINT_TO_STRING(const CIEC_UDINT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_UDINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_UDINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING UDINT_TO_WSTRING(const CIEC_UDINT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_UDINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + TForteInt32 nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_UDINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME UDINT_TO_TIME(const CIEC_UDINT &pa_roVal){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +//******************************************************************************************** +// UINT_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL UINT_TO_BOOL(const CIEC_UINT &pa_roVal){ + return CIEC_BOOL((TForteUInt16)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT UINT_TO_DINT(const CIEC_UINT &pa_roVal){ + return CIEC_DINT((TForteInt32) pa_roVal); +} + +inline const CIEC_INT UINT_TO_INT(const CIEC_UINT &pa_roVal){ + return CIEC_INT((TForteInt16) (CIEC_INT::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_INT::scm_nMaxVal); +} + +inline const CIEC_BYTE UINT_TO_BYTE(const CIEC_UINT &pa_roVal){ + return CIEC_BYTE((TForteByte) (CIEC_BYTE::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_BYTE::scm_nMaxVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT UINT_TO_LINT(const CIEC_UINT &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL UINT_TO_LREAL(const CIEC_UINT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD UINT_TO_LWORD(const CIEC_UINT &pa_roVal){ + return CIEC_LWORD((TForteLWord) pa_roVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL UINT_TO_REAL(const CIEC_UINT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT UINT_TO_SINT(const CIEC_UINT &pa_roVal){ + return CIEC_SINT((TForteInt8) (CIEC_SINT::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_DWORD UINT_TO_DWORD(const CIEC_UINT &pa_roVal){ + return CIEC_DWORD((TForteDWord) pa_roVal); +} + +inline const CIEC_UINT UINT_TO_UDINT(const CIEC_UINT &pa_roVal){ + return CIEC_UINT((TForteUInt32) pa_roVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT UINT_TO_ULINT(const CIEC_UINT &pa_roVal){ + return CIEC_ULINT((TForteUInt64) pa_roVal); +} +#endif + +inline const CIEC_USINT UINT_TO_USINT(const CIEC_UINT &pa_roVal){ + return CIEC_USINT((TForteUInt8) (CIEC_USINT::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_USINT::scm_nMaxVal); +} + +inline const CIEC_WORD UINT_TO_WORD(const CIEC_UINT &pa_roVal){ + return CIEC_WORD((TForteWord) pa_roVal); +} + +inline const CIEC_STRING UINT_TO_STRING(const CIEC_UINT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_UINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_UINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING UINT_TO_WSTRING(const CIEC_UINT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_UINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_UINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME UINT_TO_TIME(const CIEC_UINT &pa_roVal){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +//******************************************************************************************** +// ULINT_TO_* functions +//******************************************************************************************** +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_BOOL ULINT_TO_BOOL(const CIEC_ULINT &pa_roVal){ + return CIEC_BOOL((TForteUInt64)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT ULINT_TO_DINT(const CIEC_ULINT &pa_roVal){ + return CIEC_DINT((TForteInt32) (static_cast(CIEC_DINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_DINT::scm_nMaxVal); +} + +inline const CIEC_BYTE ULINT_TO_BYTE(const CIEC_ULINT &pa_roVal){ + return CIEC_BYTE((TForteByte) (static_cast(CIEC_BYTE::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_BYTE::scm_nMaxVal); +} + +inline const CIEC_INT ULINT_TO_INT(const CIEC_ULINT &pa_roVal){ + return CIEC_INT((TForteInt16) (static_cast(CIEC_INT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_INT::scm_nMaxVal); +} + +inline const CIEC_LINT ULINT_TO_LINT(const CIEC_ULINT &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL ULINT_TO_LREAL(const CIEC_ULINT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +inline const CIEC_DWORD ULINT_TO_DWORD(const CIEC_ULINT &pa_roVal){ + return CIEC_DWORD((TForteDWord) (static_cast(CIEC_DWORD::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_DWORD::scm_nMaxVal); +} + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL ULINT_TO_REAL(const CIEC_ULINT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT ULINT_TO_SINT(const CIEC_ULINT &pa_roVal){ + return CIEC_SINT((TForteInt8) (static_cast(CIEC_SINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_UDINT ULINT_TO_UDINT(const CIEC_ULINT &pa_roVal){ + return CIEC_UDINT((TForteUInt32) (static_cast(CIEC_UDINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_UDINT::scm_nMaxVal); +} + +inline const CIEC_UINT ULINT_TO_UINT(const CIEC_ULINT &pa_roVal){ + return CIEC_UINT((TForteUInt16) (static_cast(CIEC_UINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_UINT::scm_nMaxVal); +} + +inline const CIEC_LWORD ULINT_TO_LWORD(const CIEC_ULINT &pa_roVal){ + return CIEC_LWORD((TForteUInt64) pa_roVal); +} + +inline const CIEC_USINT ULINT_TO_USINT(const CIEC_ULINT &pa_roVal){ + return CIEC_USINT((TForteUInt8) (static_cast(CIEC_USINT::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_USINT::scm_nMaxVal); +} + +inline const CIEC_WORD ULINT_TO_WORD(const CIEC_ULINT &pa_roVal){ + return CIEC_WORD((TForteWord) (static_cast(CIEC_WORD::scm_nMaxVal) >= pa_roVal) ? static_cast(pa_roVal) : CIEC_WORD::scm_nMaxVal); +} + +inline const CIEC_STRING ULINT_TO_STRING(const CIEC_ULINT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_ULINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_ULINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING ULINT_TO_WSTRING(const CIEC_ULINT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_ULINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_ULINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME ULINT_TO_TIME(const CIEC_ULINT &pa_roVal){ + if(pa_roVal > 0){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); + }else{ + return CIEC_TIME(static_cast(0)); + } +} +#endif + +//******************************************************************************************** +// USINT_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL USINT_TO_BOOL(const CIEC_USINT &pa_roVal){ + return CIEC_BOOL((TForteUInt8)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT USINT_TO_DINT(const CIEC_USINT &pa_roVal){ + return CIEC_DINT((TForteInt32) pa_roVal); +} + +inline const CIEC_BYTE USINT_TO_BYTE(const CIEC_USINT &pa_roVal){ + return CIEC_BYTE((TForteByte) pa_roVal); +} + +inline const CIEC_INT USINT_TO_INT(const CIEC_USINT &pa_roVal){ + return CIEC_INT((TForteInt16) pa_roVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT USINT_TO_LINT(const CIEC_USINT &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL USINT_TO_LREAL(const CIEC_USINT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD USINT_TO_LWORD(const CIEC_USINT &pa_roVal){ + return CIEC_LWORD((TForteLWord) pa_roVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL USINT_TO_REAL(const CIEC_USINT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT USINT_TO_SINT(const CIEC_USINT &pa_roVal){ + return CIEC_SINT((TForteInt8) (CIEC_SINT::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_DWORD USINT_TO_DWORD(const CIEC_USINT &pa_roVal){ + return CIEC_DWORD((TForteDWord) pa_roVal); +} + +inline const CIEC_USINT USINT_TO_UDINT(const CIEC_USINT &pa_roVal){ + return CIEC_USINT((TForteUInt32) pa_roVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT USINT_TO_ULINT(const CIEC_USINT &pa_roVal){ + return CIEC_ULINT((TForteUInt64) pa_roVal); +} +#endif + +inline const CIEC_UINT USINT_TO_UINT(const CIEC_USINT &pa_roVal){ + return CIEC_UINT((TForteUInt16) pa_roVal); +} + +inline const CIEC_WORD USINT_TO_WORD(const CIEC_USINT &pa_roVal){ + return CIEC_WORD((TForteWord) pa_roVal); +} + +inline const CIEC_STRING USINT_TO_STRING(const CIEC_USINT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_USINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_USINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING USINT_TO_WSTRING(const CIEC_USINT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_USINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_USINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME USINT_TO_TIME(const CIEC_USINT &pa_roVal){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +//******************************************************************************************** +// WORD_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL WORD_TO_BOOL(const CIEC_WORD &pa_roVal){ + return CIEC_BOOL((TForteWord)0 != pa_roVal ? true : false); +} + +inline const CIEC_DINT WORD_TO_DINT(const CIEC_WORD &pa_roVal){ + return CIEC_DINT((TForteInt32) pa_roVal); +} + +inline const CIEC_BYTE WORD_TO_BYTE(const CIEC_WORD &pa_roVal){ + return CIEC_BYTE((TForteByte) (CIEC_BYTE::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_BYTE::scm_nMaxVal); +} + +inline const CIEC_INT WORD_TO_INT(const CIEC_WORD &pa_roVal){ + return CIEC_INT((TForteInt16) (CIEC_INT::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_INT::scm_nMaxVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT WORD_TO_LINT(const CIEC_WORD &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL WORD_TO_LREAL(const CIEC_WORD &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD WORD_TO_LWORD(const CIEC_WORD &pa_roVal){ + return CIEC_LWORD((TForteLWord) pa_roVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL WORD_TO_REAL(const CIEC_WORD &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT WORD_TO_SINT(const CIEC_WORD &pa_roVal){ + return CIEC_SINT((TForteInt8) (CIEC_SINT::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_SINT::scm_nMaxVal); +} + +inline const CIEC_DWORD WORD_TO_DWORD(const CIEC_WORD &pa_roVal){ + return CIEC_DWORD((TForteDWord) pa_roVal); +} + +inline const CIEC_WORD WORD_TO_UDINT(const CIEC_WORD &pa_roVal){ + return CIEC_WORD((TForteUInt32) pa_roVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT WORD_TO_ULINT(const CIEC_WORD &pa_roVal){ + return CIEC_ULINT((TForteUInt64) pa_roVal); +} +#endif + +inline const CIEC_USINT WORD_TO_USINT(const CIEC_WORD &pa_roVal){ + return CIEC_USINT((TForteUInt8) (CIEC_USINT::scm_nMaxVal >= pa_roVal) ? static_cast(pa_roVal) : CIEC_USINT::scm_nMaxVal); +} + +inline const CIEC_UINT WORD_TO_UINT(const CIEC_WORD &pa_roVal){ + return CIEC_UINT((TForteUInt16) pa_roVal); +} + +inline const CIEC_STRING WORD_TO_STRING(const CIEC_WORD &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_WORD::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_WORD::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING WORD_TO_WSTRING(const CIEC_WORD &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_WORD::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_WORD::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME WORD_TO_TIME(const CIEC_WORD &pa_roVal){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); +} + +//******************************************************************************************** +// INT_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL INT_TO_BOOL(const CIEC_INT &pa_roVal){ + return CIEC_BOOL((TForteInt16)0 != pa_roVal ? true : false); +} + +inline const CIEC_BYTE INT_TO_BYTE(const CIEC_INT &pa_roVal){ + TForteByte nBuf = static_cast(pa_roVal); + if(CIEC_BYTE::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_BYTE::scm_nMaxVal; + } + else{ + if(CIEC_BYTE::scm_nMinVal > pa_roVal){ + nBuf = CIEC_BYTE::scm_nMinVal; + } + } + return CIEC_BYTE(nBuf); +} + +inline const CIEC_DWORD INT_TO_DWORD(const CIEC_INT &pa_roVal){ + return CIEC_DWORD((TForteDWord) ((0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_DWORD::scm_nMinVal)); +} + +inline const CIEC_DINT INT_TO_DINT(const CIEC_INT &pa_roVal){ + return CIEC_DINT((TForteInt32) pa_roVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT INT_TO_LINT(const CIEC_INT &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL INT_TO_LREAL(const CIEC_INT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD INT_TO_LWORD(const CIEC_INT &pa_roVal){ + return CIEC_LWORD((TForteLWord) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_LWORD::scm_nMinVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL INT_TO_REAL(const CIEC_INT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT INT_TO_SINT(const CIEC_INT &pa_roVal){ + TForteInt8 nBuf = static_cast(pa_roVal); + if(CIEC_SINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_SINT::scm_nMaxVal; + } + else{ + if(CIEC_SINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_SINT::scm_nMinVal; + } + } + return CIEC_SINT(nBuf); +} + +inline const CIEC_UDINT INT_TO_UDINT(const CIEC_INT &pa_roVal){ + return CIEC_UDINT((TForteUInt32) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_UDINT::scm_nMinVal); +} + +inline const CIEC_UINT INT_TO_UINT(const CIEC_INT &pa_roVal){ + return CIEC_UINT((TForteUInt16) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_UINT::scm_nMinVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT INT_TO_ULINT(const CIEC_INT &pa_roVal){ + return CIEC_ULINT((TForteUInt64) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_ULINT::scm_nMinVal); +} +#endif + +inline const CIEC_USINT INT_TO_USINT(const CIEC_INT &pa_roVal){ + TForteUInt8 nBuf = static_cast(pa_roVal); + if(CIEC_USINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_USINT::scm_nMaxVal; + } + else{ + if(CIEC_USINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_USINT::scm_nMinVal; + } + } + return CIEC_USINT(nBuf); +} + +inline const CIEC_WORD INT_TO_WORD(const CIEC_INT &pa_roVal){ + return CIEC_WORD((TForteWord) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_WORD::scm_nMinVal); +} + +inline const CIEC_STRING INT_TO_STRING(const CIEC_INT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_INT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_INT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +inline const CIEC_TIME INT_TO_TIME(const CIEC_INT &pa_roVal){ + if(pa_roVal > 0 ){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); + }else{ + return CIEC_TIME(static_cast(0)); + } +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING INT_TO_WSTRING(const CIEC_INT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_INT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_INT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +//******************************************************************************************** +// LINT_TO_* functions +//******************************************************************************************** +#ifdef FORTE_USE_64BIT_DATATYPES + +inline const CIEC_BOOL LINT_TO_BOOL(const CIEC_LINT &pa_roVal){ + return CIEC_BOOL((TForteInt64)0 != pa_roVal ? true : false); +} + +inline const CIEC_BYTE LINT_TO_BYTE(const CIEC_LINT &pa_roVal){ + TForteByte nBuf = static_cast(pa_roVal); + if(CIEC_BYTE::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_BYTE::scm_nMaxVal; + } + else{ + if(CIEC_BYTE::scm_nMinVal > pa_roVal){ + nBuf = CIEC_BYTE::scm_nMinVal; + } + } + return CIEC_BYTE(nBuf); +} + +inline const CIEC_DWORD LINT_TO_DWORD(const CIEC_LINT &pa_roVal){ + return CIEC_DWORD((TForteDWord) ((0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_DWORD::scm_nMinVal)); +} + +inline const CIEC_DINT LINT_TO_DINT(const CIEC_LINT &pa_roVal){ + return CIEC_DINT((TForteInt32) pa_roVal); +} + +inline const CIEC_INT LINT_TO_INT(const CIEC_LINT &pa_roVal){ + TForteInt16 nBuf = static_cast(pa_roVal); + if(CIEC_INT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_INT::scm_nMaxVal; + } + else{ + if(CIEC_INT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_INT::scm_nMinVal; + } + } + return CIEC_INT(nBuf); +} + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL LINT_TO_LREAL(const CIEC_LINT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +inline const CIEC_LWORD LINT_TO_LWORD(const CIEC_LINT &pa_roVal){ + return CIEC_LWORD((TForteLWord) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_LWORD::scm_nMinVal); +} + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL LINT_TO_REAL(const CIEC_LINT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_SINT LINT_TO_SINT(const CIEC_LINT &pa_roVal){ + TForteInt8 nBuf = static_cast(pa_roVal); + if(CIEC_SINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_SINT::scm_nMaxVal; + } + else{ + if(CIEC_SINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_SINT::scm_nMinVal; + } + } + return CIEC_SINT(nBuf); +} + +inline const CIEC_UDINT LINT_TO_UDINT(const CIEC_LINT &pa_roVal){ + TForteUInt32 nBuf = static_cast(pa_roVal); + if(static_cast(CIEC_UDINT::scm_nMaxVal) < pa_roVal){ + nBuf = CIEC_UDINT::scm_nMaxVal; + } + else{ + if(0 > pa_roVal){ + nBuf = CIEC_UDINT::scm_nMinVal; + } + } + return CIEC_UDINT(nBuf); +} + +inline const CIEC_UINT LINT_TO_UINT(const CIEC_LINT &pa_roVal){ + TForteUInt16 nBuf = static_cast(pa_roVal); + if(CIEC_UINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_UINT::scm_nMaxVal; + } + else{ + if(CIEC_UINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_UINT::scm_nMinVal; + } + } + return CIEC_UINT(nBuf); +} + +inline const CIEC_ULINT LINT_TO_ULINT(const CIEC_LINT &pa_roVal){ + return CIEC_ULINT((TForteUInt64) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_ULINT::scm_nMinVal); +} + +inline const CIEC_USINT LINT_TO_USINT(const CIEC_LINT &pa_roVal){ + TForteUInt8 nBuf = static_cast(pa_roVal); + if(CIEC_USINT::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_USINT::scm_nMaxVal; + } + else{ + if(CIEC_USINT::scm_nMinVal > pa_roVal){ + nBuf = CIEC_USINT::scm_nMinVal; + } + } + return CIEC_USINT(nBuf); +} + +inline const CIEC_WORD LINT_TO_WORD(const CIEC_LINT &pa_roVal){ + TForteWord nBuf = static_cast(pa_roVal); + if(CIEC_WORD::scm_nMaxVal < pa_roVal){ + nBuf = CIEC_WORD::scm_nMaxVal; + } + else{ + if(CIEC_WORD::scm_nMinVal > pa_roVal){ + nBuf = CIEC_WORD::scm_nMinVal; + } + } + return CIEC_WORD(nBuf); +} + +inline const CIEC_STRING LINT_TO_STRING(const CIEC_LINT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_LINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_LINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING LINT_TO_WSTRING(const CIEC_LINT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_LINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_LINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +inline const CIEC_TIME LINT_TO_TIME(const CIEC_LINT &pa_roVal){ + if(pa_roVal > 0){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); + }else{ + return CIEC_TIME(static_cast(0)); + } +} +#endif + +//******************************************************************************************** +// SINT_TO_* functions +//******************************************************************************************** +inline const CIEC_BOOL SINT_TO_BOOL(const CIEC_SINT &pa_roVal){ + return CIEC_BOOL((TForteInt8)0 != pa_roVal ? true : false); +} + +inline const CIEC_BYTE SINT_TO_BYTE(const CIEC_SINT &pa_roVal){ + return CIEC_BYTE((TForteByte) ((0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_BYTE::scm_nMinVal)); +} + +inline const CIEC_DWORD SINT_TO_DWORD(const CIEC_SINT &pa_roVal){ + return CIEC_DWORD((TForteDWord) ((0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_DWORD::scm_nMinVal)); +} + +inline const CIEC_DINT SINT_TO_DINT(const CIEC_SINT &pa_roVal){ + return CIEC_DINT((TForteInt32) pa_roVal); +} + +inline const CIEC_TIME SINT_TO_TIME(const CIEC_SINT &pa_roVal){ + if(pa_roVal > 0){ + return CIEC_TIME(static_cast(pa_roVal) * FORTE_TIME_BASE_UNITS_PER_SECOND); + }else{ + return CIEC_TIME(static_cast(0)); + } +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LINT SINT_TO_LINT(const CIEC_SINT &pa_roVal){ + return CIEC_LINT((TForteInt64) pa_roVal); +} +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE +inline const CIEC_LREAL SINT_TO_LREAL(const CIEC_SINT &pa_roVal){ + return CIEC_LREAL((TForteDFloat) pa_roVal); +} +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD SINT_TO_LWORD(const CIEC_SINT &pa_roVal){ + return CIEC_LWORD((TForteLWord) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_LWORD::scm_nMinVal); +} +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +inline const CIEC_REAL SINT_TO_REAL(const CIEC_SINT &pa_roVal){ + return CIEC_REAL((TForteFloat) pa_roVal); +} +#endif + +inline const CIEC_INT SINT_TO_INT(const CIEC_SINT &pa_roVal){ + return CIEC_INT((TForteInt16) pa_roVal); +} + +inline const CIEC_UDINT SINT_TO_UDINT(const CIEC_SINT &pa_roVal){ + return CIEC_UDINT((TForteUInt32) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_UDINT::scm_nMinVal); +} + +inline const CIEC_UINT SINT_TO_UINT(const CIEC_SINT &pa_roVal){ + return CIEC_UINT((TForteUInt16) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_UINT::scm_nMinVal); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT SINT_TO_ULINT(const CIEC_SINT &pa_roVal){ + return CIEC_ULINT((TForteUInt64) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_ULINT::scm_nMinVal); +} +#endif + +inline const CIEC_USINT SINT_TO_USINT(const CIEC_SINT &pa_roVal){ + return CIEC_USINT((TForteUInt8) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_USINT::scm_nMinVal); +} + +inline const CIEC_WORD SINT_TO_WORD(const CIEC_SINT &pa_roVal){ + return CIEC_WORD((TForteWord) (0 < pa_roVal) ? static_cast(pa_roVal) : CIEC_WORD::scm_nMinVal); +} + +inline const CIEC_STRING SINT_TO_STRING(const CIEC_SINT &pa_roVal){ + CIEC_STRING string; + string.reserve(CIEC_SINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_SINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +inline const CIEC_WSTRING SINT_TO_WSTRING(const CIEC_SINT &pa_roVal){ + CIEC_WSTRING string; + string.reserve(CIEC_SINT::scm_unMaxStringBufSize); + char *pacBuffer = string.getValue(); + int nWrittenBytes = pa_roVal.toString(pacBuffer, CIEC_SINT::scm_unMaxStringBufSize); + nWrittenBytes = nWrittenBytes > -1 ? nWrittenBytes : 0; + string.assign(pacBuffer, static_cast(nWrittenBytes)); + return string; +} +#endif + +//******************************************************************************************** +// *_BCD_TO_** functions +//******************************************************************************************** +inline const CIEC_USINT BYTE_BCD_TO_USINT(const CIEC_BYTE &pa_roVal){ + return CIEC_USINT(static_cast((pa_roVal / 16 * 10) + (pa_roVal % 16))); +} + +inline const CIEC_UINT WORD_BCD_TO_UINT(const CIEC_WORD &pa_roVal){ + return CIEC_UINT(static_cast(BYTE_BCD_TO_USINT(CIEC_BYTE(static_cast(pa_roVal >> 8))) * 100 + BYTE_BCD_TO_USINT(CIEC_BYTE(static_cast(pa_roVal & 0xff))))); +} + +inline const CIEC_UDINT DWORD_BCD_TO_UDINT(const CIEC_DWORD &pa_roVal){ + return CIEC_UDINT(static_cast(WORD_BCD_TO_UINT(CIEC_WORD(static_cast(pa_roVal >> 16))) * 10000 + WORD_BCD_TO_UINT(CIEC_WORD(static_cast(pa_roVal & 0xffff))))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_ULINT LWORD_BCD_TO_ULINT(const CIEC_LWORD &pa_roVal){ + return CIEC_ULINT(static_cast(DWORD_BCD_TO_UDINT(CIEC_DWORD(static_cast(pa_roVal >> 32))) * 100000000 + DWORD_BCD_TO_UDINT(CIEC_DWORD(static_cast(pa_roVal & 0xffffffff))))); +} +#endif + +//******************************************************************************************** +// **_TO_BCD_* functions +//******************************************************************************************** +inline const CIEC_BYTE USINT_TO_BCD_BYTE(const CIEC_USINT &pa_roVal){ + return CIEC_BYTE(static_cast(pa_roVal / 10 * 16 + pa_roVal % 10)); +} + +inline const CIEC_WORD UINT_TO_BCD_WORD(const CIEC_UINT &pa_roVal){ + return CIEC_WORD(static_cast((static_cast(USINT_TO_BCD_BYTE(static_cast(pa_roVal / 100))) << 8) + static_cast(USINT_TO_BCD_BYTE(static_cast(pa_roVal % 100))))); +} + +inline const CIEC_DWORD UDINT_TO_BCD_DWORD(const CIEC_UDINT &pa_roVal){ + return CIEC_DWORD(static_cast((static_cast(UINT_TO_BCD_WORD(static_cast(pa_roVal / 10000))) << 16) + static_cast(UINT_TO_BCD_WORD(static_cast(pa_roVal % 10000))))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +inline const CIEC_LWORD ULINT_TO_BCD_LWORD(const CIEC_ULINT &pa_roVal){ + return CIEC_LWORD(static_cast((static_cast(UDINT_TO_BCD_DWORD(static_cast(pa_roVal / 100000000))) << 32) + static_cast(UDINT_TO_BCD_DWORD(static_cast(pa_roVal % 100000000))))); +} +#endif +#endif /* CONVERT_FUNCTIONS_H_ */ diff --git a/src/core/dataconn.cpp b/src/core/dataconn.cpp new file mode 100644 index 000000000..8b67eaa25 --- /dev/null +++ b/src/core/dataconn.cpp @@ -0,0 +1,153 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Rene Smodic, Gunnar Grabmaier, Ingo Hegny, + * Matthias Plasch + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "dataconn.h" +#include "funcbloc.h" + +CDataConnection::CDataConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId, + const CIEC_ANY *paSrcDO) : + CConnection(paSrcFB, paSrcPortId), + m_poValue(0), + mSpecialCastConnection(false){ + + if((0 != paSrcDO) && (CIEC_ANY::e_ANY != paSrcDO->getDataTypeID())){ + m_poValue = paSrcDO->clone(m_acDataBuf); + } +} + +CDataConnection::~CDataConnection(){ + if(0 != m_poValue){ + m_poValue->~CIEC_ANY(); + ; + } +} + +EMGMResponse CDataConnection::connect(CFunctionBlock *paDstFB, + CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + + TPortId dstPortId = paDstFB->getDIID(paDstPortNameId); + if(cg_unInvalidPortId != dstPortId){ + CIEC_ANY *dstDataPoint = paDstFB->getDIFromPortId(dstPortId); + retVal = establishDataConnection(paDstFB, dstPortId, dstDataPoint); + } + return retVal; +} + +EMGMResponse CDataConnection::connectToCFBInterface(CFunctionBlock *paDstFB, + CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + TPortId nDOID = paDstFB->getDOID(paDstPortNameId); + + if(cg_nInvalidEventID != nDOID){ + CIEC_ANY *dstDataPoint = paDstFB->getDataOutput(paDstPortNameId); + nDOID |= cgInternal2InterfaceMarker; + retVal = establishDataConnection(paDstFB, nDOID, dstDataPoint); + } + + return retVal; +} + +void CDataConnection::handleAnySrcPortConnection(const CIEC_ANY &paDstDataPoint){ + if(CIEC_ANY::e_ANY != paDstDataPoint.getDataTypeID()){ + m_poValue = paDstDataPoint.clone(m_acDataBuf); + getSourceId().mFB->configureGenericDO(getSourceId().mPortId, paDstDataPoint); + if(isConnected()){ + //We already have some connection also set their correct type + for(TDestinationIdList::Iterator it = mDestinationIds.begin(); + it != mDestinationIds.end(); ++it){ + it->mFB->connectDI(it->mPortId, this); + } + } + } +} + +#ifndef FORTE_CLASS_0 +EMGMResponse +CDataConnection::disconnect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retval = e_NO_SUCH_OBJECT; + TPortId dstPortId = paDstFB->getDIID(paDstPortNameId); + + if(cg_unInvalidPortId != dstPortId){ + retval = CConnection::removeDestination(SConnectionPoint(paDstFB, dstPortId)); + if(e_RDY == retval){ + // the CConnection class didn't respond an error + paDstFB->connectDI(dstPortId, 0); + } + } + return retval; +} +#endif + +void CDataConnection::readData(CIEC_ANY *pa_poValue) const{ + if(m_poValue){ + if(!mSpecialCastConnection){ + pa_poValue->setValue(*m_poValue); + } + else{ + CIEC_ANY::specialCast(*m_poValue, *pa_poValue); + } + } +} + +bool CDataConnection::canBeConnected(const CIEC_ANY *pa_poSrcDataPoint, + const CIEC_ANY *pa_poDstDataPoint, bool &pa_rbSpecialCast){ + CIEC_ANY::EDataTypeID eSrcId = pa_poSrcDataPoint->getDataTypeID(); + CIEC_ANY::EDataTypeID eDstId = pa_poDstDataPoint->getDataTypeID(); + bool bCanConnect = false; + + if(eSrcId == eDstId){ + bCanConnect = true; + } + else{ + if(((eSrcId == CIEC_ANY::e_ANY) && (eDstId != CIEC_ANY::e_ANY)) + || ((eSrcId != CIEC_ANY::e_ANY) && (eDstId == CIEC_ANY::e_ANY))){ + bCanConnect = true; + } + else{ + bCanConnect = CIEC_ANY::isCastable(eSrcId, eDstId); + pa_rbSpecialCast = ((bCanConnect) && needsSpecialCast(eSrcId)); + } + } + return bCanConnect; +} + +bool CDataConnection::needsSpecialCast(CIEC_ANY::EDataTypeID pa_eSrcDTId){ + //we want to cast from floating point data to an integer data type + return ((CIEC_ANY::e_LREAL == pa_eSrcDTId) || (CIEC_ANY::e_REAL == pa_eSrcDTId)); +} + +EMGMResponse CDataConnection::establishDataConnection(CFunctionBlock *paDstFB, TPortId paDstPortId, + CIEC_ANY *paDstDataPoint){ + EMGMResponse retVal = e_INVALID_OPERATION; + + if(0 == m_poValue){ + handleAnySrcPortConnection(*paDstDataPoint); + retVal = e_RDY; + } + else{ + if(canBeConnected(m_poValue, paDstDataPoint, mSpecialCastConnection)){ + retVal = e_RDY; + } + } + + if(e_RDY == retVal){ + retVal = CConnection::addDestination(SConnectionPoint(paDstFB, paDstPortId)); + if(e_RDY == retVal){ + if(!paDstFB->connectDI(paDstPortId, this)){ + retVal = e_INVALID_STATE; + mDestinationIds.pop_front(); //empty the list so that the have created connection is not here anymore + } + } + } + return retVal; +} diff --git a/src/core/dataconn.h b/src/core/dataconn.h new file mode 100644 index 000000000..1e10657ed --- /dev/null +++ b/src/core/dataconn.h @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Rene Smodic, Gunnar Grabmaier, Ingo Hegny, + * Martin Melik Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _DATACONN_H_ +#define _DATACONN_H_ + +#include "./datatypes/forte_any.h" +#include "conn.h" + +/*! \ingroup CORE\brief Class for handling a data connection. + */ +class CDataConnection : public CConnection { + + public: + CDataConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId, const CIEC_ANY *paSrcDO); + + virtual ~CDataConnection(); + + virtual EMGMResponse connect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); + + virtual EMGMResponse connectToCFBInterface(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); + + #ifndef FORTE_CLASS_0 + virtual EMGMResponse disconnect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); + #endif + +/*! \brief Write connection data value. + * + * Write data value from FB data output to connection data variable. + * \param pa_poValue pointer to FB data output + * \return Can be the following response: + * - TRUE ... write successful + * - FALSE ... no such data connection exists + */ + void writeData(const CIEC_ANY *pa_poValue){ + if(m_poValue){ + m_poValue->setValue(*pa_poValue); + } + }; + +/*! \brief Read connection data value. + * + * Read data value from connection data variable to FB data input. + * \param pa_poValue pointer to FB data input + */ + void readData(CIEC_ANY *pa_poValue) const; + +/*! \brief Set class member variable m_poValue. + * + * Set class member variable m_poValue. + * \param pa_poValue ... pointer to data variable + */ + void setValue(CIEC_ANY *pa_poValue) { + m_poValue = pa_poValue; + } +/*! \brief Get class member variable m_poValue. + * + * Get class member variable m_poValue. + * \return pointer to class member variable m_poValue + */ + CIEC_ANY* getValue() { + return m_poValue; + } + + protected: + + /*! \brief check if the the given data points are compatible so that a connection can be established + * + * @param pa_poSrcDataPoint data point of the connection's source (if 0 than it is a any data type) + * @param pa_poDstDataPoint data point of the connection's destination (if 0 than it is a any data type) + * @param pa_rbSpecialCast connection requires special cast (e.g., float datatype to int datatype conversion) + * @return true if a connection between the given end points is valid + */ + static bool canBeConnected(const CIEC_ANY *pa_poSrcDataPoint, const CIEC_ANY *pa_poDstDataPoint, + bool &pa_rbSpecialCast); + + /*! \brief check if the the given data type needs special treatment in conversions + * + * @param pa_eSrcDTId data type + * @return true if special treatment is necessary + */ + static bool needsSpecialCast(CIEC_ANY::EDataTypeID pa_eSrcDTId); + + /*! \brief Value for storing the current data of the connection + */ + CIEC_ANY *m_poValue; + + TForteByte m_acDataBuf[sizeof(CIEC_ANY)]; + + /*! \brief Flag for indicating that this connections needs special measures for casting. + * + * Currently this is only necessary for (L)REAL to ANY_INT data connections + */ + bool mSpecialCastConnection; + private: + + void handleAnySrcPortConnection(const CIEC_ANY &paDstDataPoint); + + EMGMResponse establishDataConnection(CFunctionBlock *paDstFB, TPortId paDstPortId, CIEC_ANY *paDstDataPoint); + +}; + +typedef CDataConnection *TDataConnectionPtr; + +#endif /*_DATACONN_H_*/ diff --git a/src/core/datatypes/CMakeLists.txt b/src/core/datatypes/CMakeLists.txt new file mode 100644 index 000000000..dc7eccaa9 --- /dev/null +++ b/src/core/datatypes/CMakeLists.txt @@ -0,0 +1,87 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2014 Profactor GmbH, ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Michael Hofmann, Alois Zoitl, Monika Wenger, Gerhard Ebenhofer +# * - initial implementation and rework communication infrastructure +# *******************************************************************************/ + + +############################################################################# +# Core Datatypes +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +forte_add_sourcefile_hcpp(forte_any_elementary forte_int forte_sint) +forte_add_sourcefile_hcpp(forte_dint forte_udint forte_uint) +forte_add_sourcefile_hcpp(forte_usint forte_dword forte_word) +forte_add_sourcefile_hcpp(forte_byte forte_bool forte_string) +forte_add_sourcefile_hcpp(forte_time forte_any) +forte_add_sourcefile_hcpp(forte_any_string) +forte_add_sourcefile_hcpp(forte_any_num) +forte_add_sourcefile_hcpp(forte_any_magnitude) +forte_add_sourcefile_hcpp(forte_any_bit) +forte_add_sourcefile_hcpp(forte_any_int) +forte_add_sourcefile_hcpp(forte_any_real) + +# include STRUCT Datatype-Support +forte_add_sourcefile_hcpp(forte_struct) + +set(FORTE_USE_64BIT_DATATYPES ON CACHE BOOL "Enable Forte 64-Bit Datatypes") +mark_as_advanced(FORTE_USE_64BIT_DATATYPES) +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(forte_lint forte_ulint) + forte_add_sourcefile_hcpp(forte_time_of_day forte_date_and_time) + forte_add_sourcefile_hcpp(forte_any_date forte_date forte_lword) + forte_add_definition("-DFORTE_USE_64BIT_DATATYPES") +endif(FORTE_USE_64BIT_DATATYPES) + +set(FORTE_USE_REAL_DATATYPE ON CACHE BOOL "Enable Forte Real Datatypes") +mark_as_advanced(FORTE_USE_REAL_DATATYPE) +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(forte_real) + forte_add_definition("-DFORTE_USE_REAL_DATATYPE") +endif(FORTE_USE_REAL_DATATYPE) + +set(FORTE_USE_LREAL_DATATYPE ON CACHE BOOL "Enable Forte LReal Datatypes") +mark_as_advanced(FORTE_USE_LREAL_DATATYPE) +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(forte_lreal) + forte_add_definition("-DFORTE_USE_LREAL_DATATYPE") +endif(FORTE_USE_LREAL_DATATYPE) + +set(FORTE_SUPPORT_ARRAYS ON CACHE BOOL "Enable Forte Array Datatypes") +mark_as_advanced(FORTE_SUPPORT_ARRAYS) +if(FORTE_SUPPORT_ARRAYS) + forte_add_sourcefile_hcpp(forte_array) + forte_add_definition("-DFORTE_SUPPORT_ARRAYS") +endif(FORTE_SUPPORT_ARRAYS) + + +set(FORTE_USE_WSTRING_DATATYPE ON CACHE BOOL "Enable Forte WSTRING Datatypes") +mark_as_advanced(FORTE_USE_WSTRING_DATATYPE) +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(forte_wstring) + forte_add_definition("-DFORTE_USE_WSTRING_DATATYPE") +endif(FORTE_USE_WSTRING_DATATYPE) + + +set(FORTE_UNICODE_SUPPORT ON CACHE BOOL "Enable unicode support for STRING and WSTRING, WSTRING needs unicode support enabled!") +mark_as_advanced(FORTE_UNICODE_SUPPORT) +if(FORTE_UNICODE_SUPPORT) + forte_add_sourcefile_hcpp(unicode_utils) + forte_add_definition("-DFORTE_UNICODE_SUPPORT") +elseif(FORTE_USE_WSTRING_DATATYPE) + message(FATAL_ERROR "In order to use WSTRING you need unicode support enabled") +endif(FORTE_UNICODE_SUPPORT) + +set(FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES ON CACHE BOOL "Enable Forte Custom Serializeable Datatypes") +mark_as_advanced(FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES) +if(FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES) + forte_add_definition("-DFORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES") +endif(FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES) + diff --git a/src/core/datatypes/forte_any.cpp b/src/core/datatypes/forte_any.cpp new file mode 100644 index 000000000..d8716e2c8 --- /dev/null +++ b/src/core/datatypes/forte_any.cpp @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2013 ACIN, nxtcontrol GmbH, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Martin Melik Merkumians, Stanislav Meduna, + * Monika Wenger, Matthias Plasch + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_any.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "forte_any_gen.cpp" +#endif +#include "forte_real.h" +#include "forte_lreal.h" +#include + +const CTypeLib::CDataTypeEntry CIEC_ANY::csm_oFirmwareDataTypeEntry_CIEC_ANY(g_nStringIdANY, CIEC_ANY::createDataType); + +const char * const CIEC_ANY::scm_acAnyToStringResponse = "ND (ANY)"; + +#ifdef FORTE_STATIC_LIB +int CIEC_ANY::dummyInit(){ + return 0; +} +#endif + +// A way to write binary literals (inspiration: http://www.thescripts.com/forum/thread219656.html) + +#define HEX__(n) 0x##n##LU + +#define B8__(x) \ + ((x&0x0000000FLU)?1:0) \ +|((x&0x000000F0LU)?2:0) \ +|((x&0x00000F00LU)?4:0) \ +|((x&0x0000F000LU)?8:0) \ +|((x&0x000F0000LU)?16:0) \ +|((x&0x00F00000LU)?32:0) \ +|((x&0x0F000000LU)?64:0) \ +|((x&0xF0000000LU)?128:0) + +#define B8(d) ((unsigned char)B8__(HEX__(d))) + +void CIEC_ANY::saveAssign(const CIEC_ANY &pa_roValue){ + CIEC_ANY::EDataTypeID srcDTID = pa_roValue.getDataTypeID(); + CIEC_ANY::EDataTypeID dstDTID = getDataTypeID(); + if(dstDTID == srcDTID){ + setValue(pa_roValue); + } + else{ + if(e_ANY == dstDTID){ + pa_roValue.clone((TForteByte*) this); + } + else if(isCastable(srcDTID, dstDTID)){ + if((CIEC_ANY::e_LREAL == srcDTID) || (CIEC_ANY::e_REAL == srcDTID)){ + specialCast(pa_roValue, *this); + } + else{ + setValue(pa_roValue); + } + } + //TODO for the else case check for any and maybe clone it + } + +} + +int CIEC_ANY::fromString(const char *pa_pacValue){ + int nRetVal = -1; + + if(e_ANY == getDataTypeID()){ + //we should only be here if it is really an unparameterized generic data type + const char *acHashPos = strchr(pa_pacValue, '#'); + if(0 != acHashPos){ + CStringDictionary::TStringId nTypeNameId = parseTypeName(pa_pacValue, acHashPos); + if(CStringDictionary::scm_nInvalidStringId != nTypeNameId){ + if(0 != CTypeLib::createDataTypeInstance(nTypeNameId, (TForteByte *) this)){ + nRetVal = fromString(pa_pacValue); //some of the datatypes require the type upfront for correct parsing e.g., time + if(0 > nRetVal){ + //if it didn't work change us back to an any + CIEC_ANY::createDataType((TForteByte *)this); + } + } + } + } + } + return nRetVal; +} + +CStringDictionary::TStringId CIEC_ANY::parseTypeName(const char *pa_pacValue, const char *pa_pacHashPos){ + CStringDictionary::TStringId nRetVal = CStringDictionary::scm_nInvalidStringId; + + int nLen = static_cast(pa_pacHashPos - pa_pacValue); + + if(nLen < scm_nMaxTypeNameLength){ + char acTypeNameBuf[scm_nMaxTypeNameLength]; + strncpy(acTypeNameBuf, pa_pacValue, nLen); + acTypeNameBuf[nLen] = '\0'; + nRetVal = CStringDictionary::getInstance().getId(acTypeNameBuf); + } + return nRetVal; +} + +int CIEC_ANY::toString(char* pa_pacValue, unsigned int pa_nBufferSize) const{ + int nRetVal = -1; + if((strlen(scm_acAnyToStringResponse) +1) < pa_nBufferSize){ + nRetVal = strlen(scm_acAnyToStringResponse); + memcpy(pa_pacValue, scm_acAnyToStringResponse, nRetVal); + pa_pacValue[nRetVal] = '\0'; + } + return nRetVal; +} + +bool CIEC_ANY::isCastable(EDataTypeID pa_eSource, EDataTypeID pa_eDestination, bool &pa_rbUpCast, bool &pa_rbDownCast){ + + pa_rbUpCast = pa_rbDownCast = false; + + // EDataTypeID -> EDataType matrix, e_BOOL to e_WSTRING + // Watch for ordering - it has to match EDataTypeID + + // Upcast: always possible without any loss of data or precision + static const TForteByte UpCast[e_WSTRING - e_BOOL + 1][(e_WSTRING - e_BOOL + 8) / 8] = { { B8(11111111), B8(11111000), B8(01100000) }, // e_BOOL to x + { B8(01111000), B8(01111000), B8(01100000) }, // e_SINT + { B8(00111000), B8(00111000), B8(01100000) }, // e_INT + { B8(00011000), B8(00011000), B8(00100000) }, // e_DINT + + { B8(00001000), B8(00001000), B8(10000000) }, // e_LINT + { B8(00111111), B8(11111000), B8(01100000) }, // e_USINT + { B8(00011011), B8(10111000), B8(01100000) }, // e_UINT + { B8(00001001), B8(10011000), B8(00100000) }, // e_UDINT + + { B8(00000000), B8(10001000), B8(00000000) }, // e_ULINT + { B8(01111111), B8(11111000), B8(00000000) }, // e_BYTE + { B8(00111011), B8(10111000), B8(00000000) }, // e_WORD + { B8(00011001), B8(10011000), B8(01000000) }, // e_DWORD + + { B8(00001000), B8(10001000), B8(01100000) }, // e_LWORD + { B8(00000000), B8(00000100), B8(00000000) }, // e_DATE + { B8(00000000), B8(00000010), B8(00000000) }, // e_TIME_OF_DAY + { B8(00000000), B8(00000001), B8(00000000) }, // e_DATE_AND_TIME + + { B8(00001000), B8(00001000), B8(10000000) }, // e_TIME + { B8(00000000), B8(00011000), B8(01100000) }, // e_REAL + { B8(00000000), B8(00001000), B8(00100000) }, // e_LREAL + { B8(00000000), B8(00000000), B8(00010000) }, // e_STRING + + { B8(00000000), B8(00000000), B8(00001000) } // e_WSTRING + }; + + // Downcast: information may get lost (eventually catastrophically) + static const TForteByte DownCast[e_WSTRING - e_BOOL + 1][(e_WSTRING - e_BOOL + 8) / 8] = { { B8(00000000), B8(00000000), B8(00000000) }, // e_BOOL to x + { B8(10000111), B8(10000000), B8(00000000) }, // e_SINT + { B8(11000111), B8(11000000), B8(00000000) }, // e_INT + { B8(11100111), B8(11100000), B8(01000000) }, // e_DINT + + { B8(11110111), B8(11110000), B8(01100000) }, // e_LINT + { B8(11000000), B8(00000000), B8(00000000) }, // e_USINT + { B8(11100100), B8(01000000), B8(00000000) }, // e_UINT + { B8(11110110), B8(01100000), B8(01000000) }, // e_UDINT + + { B8(11111111), B8(01110000), B8(01100000) }, // e_ULINT + { B8(10000000), B8(00000000), B8(01100000) }, // e_BYTE + { B8(11000100), B8(01000000), B8(01100000) }, // e_WORD + { B8(11100110), B8(01100000), B8(00100000) }, // e_DWORD + + { B8(11110111), B8(01110000), B8(00000000) }, // e_LWORD + { B8(00000000), B8(00000000), B8(00000000) }, // e_DATE + { B8(00000000), B8(00000000), B8(00000000) }, // e_TIME_OF_DAY + { B8(00000000), B8(00000000), B8(00000000) }, // e_DATE_AND_TIME + + { B8(11110111), B8(11110000), B8(01100000) }, // e_TIME + { B8(11111111), B8(11100000), B8(00000000) }, // e_REAL + { B8(11111111), B8(11110000), B8(01000000) }, // e_LREAL + { B8(00000000), B8(00000000), B8(00000000) }, // e_STRING + + { B8(00000000), B8(00000000), B8(00000000) } // e_WSTRING + }; + + if((pa_eSource < e_BOOL) || (pa_eSource > e_WSTRING) || (pa_eDestination < e_BOOL) || (pa_eDestination > e_WSTRING)){ + return false; + } + + pa_rbUpCast = (UpCast[pa_eSource - e_BOOL][(pa_eDestination - e_BOOL) >> 3] & (0x80 >> ((pa_eDestination - e_BOOL) & 0x07))) != 0; + pa_rbDownCast = (DownCast[pa_eSource - e_BOOL][(pa_eDestination - e_BOOL) >> 3] & (0x80 >> ((pa_eDestination - e_BOOL) & 0x07))) != 0; + + return (pa_rbUpCast | pa_rbDownCast); +} + +void CIEC_ANY::specialCast(const CIEC_ANY &pa_roSrcValue, CIEC_ANY &pa_roDstValue){ + switch (pa_roSrcValue.getDataTypeID()){ +#ifdef FORTE_USE_REAL_DATATYPE + case CIEC_ANY::e_REAL: + CIEC_REAL::castRealData(static_cast(pa_roSrcValue), pa_roDstValue); + break; +#ifdef FORTE_USE_64BIT_DATATYPES + case CIEC_ANY::e_LREAL: + CIEC_LREAL::castLRealData(static_cast(pa_roSrcValue), pa_roDstValue); + break; +#endif +#endif + default: + //we should not be here log error + DEVLOG_ERROR("CIEC_ANY::specialCast: special cast for unsupported source data type requested!\n"); + break; + } +} diff --git a/src/core/datatypes/forte_any.h b/src/core/datatypes/forte_any.h new file mode 100644 index 000000000..725bdd156 --- /dev/null +++ b/src/core/datatypes/forte_any.h @@ -0,0 +1,447 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, nxtcontrol GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Martin Melik Merkumians, Stanislav Meduna, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_H_ +#define _ANY_H_ + +#include +#include "../typelib.h" + +#if (!defined FORTE_LITTLE_ENDIAN) && (!defined FORTE_BIG_ENDIAN) +# error "Endianess is not defined!" +#endif + +/*!\ingroup COREDTS CIEC_ANY represents the IEC_ANY data type according to IEC 61131. + */ + +/*!\ingroup CORE \defgroup COREDTS Core Data Types + * \brief Implementation of the core IEC 61131-3 data types. + * + */ + +class CIEC_ANY{ + public: + + /*! \ingroup COREDTS\brief Data type ID's are chosen according to IEC 61499-1 : Function Block + * -- Part 1 Architecture - Annex F (informative) Information exchange/F.3 + * Transfer syntaxes (page 89). + */ + enum EDataTypeID{ + e_ANY, e_BOOL, e_SINT, e_INT, e_DINT, e_LINT, e_USINT, e_UINT, e_UDINT, e_ULINT, e_BYTE, e_WORD, e_DWORD, e_LWORD, e_DATE, e_TIME_OF_DAY, e_DATE_AND_TIME, e_TIME, //until here simple Datatypes + e_REAL, + e_LREAL, + e_STRING, + e_WSTRING, + e_DerivedData, + e_DirectlyDerivedData, + e_EnumeratedData, + e_SubrangeData, + e_ARRAY, //according to the compliance profile + e_STRUCT, + e_External = 256, // Base for CIEC_ANY based types outside of the forte base + e_Max = 65535 // Guarantees at least 16 bits - otherwise gcc will optimizes on some platforms + }; + +#ifdef FORTE_USE_64BIT_DATATYPES + typedef TForteUInt64 TLargestUIntValueType; + typedef TForteInt64 TLargestIntValueType; +#else + typedef TForteUInt32 TLargestUIntValueType; + typedef TForteInt32 TLargestIntValueType; +#endif + + /* the following functions have to be added by hand as they the default DECLARE_FIRMWARE_DATATYPE and DEFINE_FIRMWARE_DATATYPE + * does not work here. + */ + static CIEC_ANY *createDataType(TForteByte *pa_acDataBuf){ + return (0 != pa_acDataBuf) ? new (pa_acDataBuf) CIEC_ANY : new CIEC_ANY; + } + const static CTypeLib::CDataTypeEntry csm_oFirmwareDataTypeEntry_CIEC_ANY; + +#ifdef FORTE_STATIC_LIB + static int dummyInit(); +#endif + + + virtual ~CIEC_ANY(){ + } + + void saveAssign(const CIEC_ANY &pa_roValue); + + /*! \brief Set method for data type member value + * + * The data type value is set through the copy assignment + * + */ + virtual void setValue(const CIEC_ANY &pa_roValue){ + setValueSimple(pa_roValue); + } + + /*! \brief Makes a clone of the data type object + * + * With this command a clone object of the actual data type object is created. + * This clone object is necessary for establishing data-connections. + * Pure virtual function implementation. + */ + virtual CIEC_ANY* clone(TForteByte *pa_acDataBuf) const { + return createDataType(pa_acDataBuf); //there is nothing to clone in any impl + } + + /*! \brief Get data type id method + * + * With this command the data type of the actual object can be identified. + * The data type identifier is unique for each data type within FORTE. + */ + virtual EDataTypeID getDataTypeID() const { + return CIEC_ANY::e_ANY; + } + + /*! \brief Get the pointer to the union char array + * + * This command returns the pointer to the union char array + * \return Returns TForteByte* + */ + + TForteByte* getDataPtr(){ + return m_uAnyData.m_AData; + } + + /*! \brief Get a const pointer to the union char array + * + * \return Returns const TForteByte* + */ + + const TForteByte* getConstDataPtr() const{ + return m_uAnyData.m_AData; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * Pure virtual function implementation. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * Pure virtual function implementation. + * \param pa_pacValue buffer for storing the string representation + * \param pa_nBufferSize size in bytes available in the buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; + + /*! \brief determine whether we can cast the source to the destination and what kind of cast it is + */ + static bool isCastable(EDataTypeID pa_eSource, EDataTypeID pa_eDestination, bool &pa_rbUpCast, bool &pa_rbDownCast); + static bool isCastable(EDataTypeID pa_eSource, EDataTypeID pa_eDestination){ + bool bUpCast, bDownCast; + return isCastable(pa_eSource, pa_eDestination, bUpCast, bDownCast); + } + + /*! \brief perform special cast operation that can not be directly handled by the data types + */ + static void specialCast(const CIEC_ANY &pa_roSrcValue, CIEC_ANY &pa_roDstValue); + +#ifdef FORTE_SUPPORT_CUSTOM_SERIALIZABLE_DATATYPES + /*! \brief the following methods have to be implemented if a custom datatype is added to the forte which is not supported by the default seralize mechanism. */ + /*! \brief returns the required size for serialization */ + virtual unsigned int getRequiredSerializationSize() const{ + return 0; + } + ; + /*! \brief returns the tag of the datatype for serialization */ + virtual TForteByte getTag() const{ + return 0xFF; + } + ; + /*! \brief serialize the custom type */ + virtual int serializeCustomType(TForteByte*, int) const{ + return -1; + } + ; + /*! \brief deserialize the tag */ + virtual bool deserializeTag(const TForteByte){ + return false; + } + ; + /*! \brief deserialize the custom type*/ + virtual int deserializeCustomType(const TForteByte*, int){ + return -1; + } + ; +#endif + + bool isForced(){ + return m_bForced; + } + + void setForced(bool pa_bForced){ + m_bForced = pa_bForced; + } + +// friend class CDataConnection; +// friend class CInternal2InterfaceDataConnection; +// friend class CIEC_ARRAY; + + protected: + CIEC_ANY() : + m_bForced(false){ + setLargestUInt(0); + } + + /*! \brief copy the union data + * + * To be used for efficiently implementing assignment operators where it is + * known that this can be done safely. + */ + inline + void setValueSimple(const CIEC_ANY &pa_roValue){ + m_uAnyData = pa_roValue.m_uAnyData; + } + + /*! \brief Get Method for complex datatypes + * A virtual function for datatypes who can't be copied by the union assignment + */ + + void setTBOOL8(bool src){ + m_uAnyData.m_nLargestUInt = TLargestUIntValueType(src); + } + + void setTUINT32(TForteUInt32 src){ //also used for TForteDWord + m_uAnyData.m_nLargestUInt = TLargestUIntValueType(src); + } + + void setTUINT16(TForteUInt16 src){ //also used for TForteWord + m_uAnyData.m_nLargestUInt = TLargestUIntValueType(src); + } + + void setTUINT8(TForteUInt8 src){ //also used for TForteByte + m_uAnyData.m_nLargestUInt = TLargestUIntValueType(src); + } + + void setTINT32(TForteInt32 src){ + m_uAnyData.m_nLargestInt = TLargestIntValueType(src); + } + + void setTINT16(TForteInt16 src){ + m_uAnyData.m_nLargestInt = TLargestIntValueType(src); + } + + void setTINT8(TForteInt8 src){ + m_uAnyData.m_nLargestInt = TLargestIntValueType(src); + } + +#ifdef FORTE_USE_REAL_DATATYPE + void setTFLOAT(TForteFloat src){ + m_uAnyData.m_fFloat = TForteFloat(src); + } +#ifdef FORTE_USE_64BIT_DATATYPES + void setTDFLOAT(TForteDFloat src){ + m_uAnyData.m_fDFloat = TForteDFloat(src); + } +#endif //#ifdef FORTE_USE_64BIT_DATATYPES +#endif //#ifdef FORTE_USE_REAL_DATATYPE +#ifdef FORTE_USE_64BIT_DATATYPES + + void setTUINT64(TForteUInt64 src){ //also used for LWORD + m_uAnyData.m_nLargestUInt = TLargestUIntValueType(src); + } + + void setTINT64(TForteInt64 src){ + m_uAnyData.m_nLargestInt = TLargestIntValueType(src); + } +#endif //#ifdef FORTE_USE_64BIT_DATATYPES +#ifdef FORTE_BIG_ENDIAN + bool getTBOOL8() const{ + return (m_uAnyData.m_nLargestUInt != 0); + } + TForteUInt32 getTUINT32() const{ //also used for TForteDWord + return (TForteUInt32)m_uAnyData.m_nLargestUInt; + } + + TForteUInt16 getTUINT16() const{ //also used for TForteWord + return (TForteUInt16)m_uAnyData.m_nLargestUInt; + } + + TForteUInt8 getTUINT8() const{ //also used for TForteByte + return (TForteUInt8)m_uAnyData.m_nLargestUInt; + } + + TForteInt32 getTINT32() const{ + return (TForteInt32)m_uAnyData.m_nLargestInt; + } + + TForteInt16 getTINT16() const{ + return (TForteInt16)m_uAnyData.m_nLargestInt; + } + + TForteInt8 getTINT8() const{ + return (TForteInt8)m_uAnyData.m_nLargestInt; + } + +#ifdef FORTE_USE_64BIT_DATATYPES + TForteUInt64 getTUINT64() const{ //also used for LWORD + return (TForteUInt64)m_uAnyData.m_nLargestUInt; + } + TForteInt64 getTINT64() const{ + return (TForteInt64)m_uAnyData.m_nLargestInt; + } +#endif //#ifdef FORTE_USE_64BIT_DATATYPES +#else +#ifdef FORTE_LITTLE_ENDIAN + bool getTBOOL8() const{ + return m_uAnyData.m_bBool; + } + TForteUInt32 getTUINT32() const{ //also used for TForteDWord + return m_uAnyData.m_nUInt32; + } + TForteUInt16 getTUINT16() const{ //also used for TForteWord + return m_uAnyData.m_nUInt16; + } + TForteUInt8 getTUINT8() const{ //also used for TForteByte + return m_uAnyData.m_nUInt8; + } + TForteInt32 getTINT32() const{ + return m_uAnyData.m_nInt32; + } + TForteInt16 getTINT16() const{ + return m_uAnyData.m_nInt16; + } + TForteInt8 getTINT8() const{ + return m_uAnyData.m_nInt8; + } + +#ifdef FORTE_USE_64BIT_DATATYPES + TForteUInt64 getTUINT64() const{ //also used for LWORD + return m_uAnyData.m_nUInt64; + } + TForteInt64 getTINT64() const{ + return m_uAnyData.m_nInt64; + } +#endif //#ifdef FORTE_USE_64BIT_DATATYPES +#else +#error Endianess not defined! +#endif //#ifdef FORTE_BIG_ENDIAN +#endif //#ifdef FORTE_LITTLE_ENDIAN +#ifdef FORTE_USE_REAL_DATATYPE //!< get-Methods are Big/Little Endian independent + TForteFloat getTFLOAT() const{ + return (TForteFloat) m_uAnyData.m_fFloat; + } +#ifdef FORTE_USE_64BIT_DATATYPES + TForteDFloat getTDFLOAT() const{ + return TForteDFloat(m_uAnyData.m_fDFloat); + } +#endif //#ifdef FORTE_USE_64BIT_DATATYPES +#endif //#ifdef FORTE_USE_REAL_DATATYPE + TLargestUIntValueType getLargestUInt() const{ + return m_uAnyData.m_nLargestUInt; + } + + void setLargestUInt(TLargestUIntValueType m_nVal){ + m_uAnyData.m_nLargestUInt = m_nVal; + } + + TLargestIntValueType getLargestInt() const{ + return m_uAnyData.m_nLargestInt; + } + + void setLargestInt(TLargestIntValueType m_nVal){ + m_uAnyData.m_nLargestInt = m_nVal; + } + + TForteByte *getGenData(){ + return m_uAnyData.m_pGenData; + } + + const TForteByte *getGenData() const{ + return m_uAnyData.m_pGenData; + } + + void setGenData(TForteByte *pa_pGenData){ + m_uAnyData.m_pGenData = pa_pGenData; + } + + CStringDictionary::TStringId parseTypeName(const char *pa_pacValue, const char *pa_pacHashPos); + + private: + const static int scm_nMaxTypeNameLength = 14; + static const char * const scm_acAnyToStringResponse; + + //!declared but undefined copy constructor as we don't want ANYs to be directly copied. + CIEC_ANY(const CIEC_ANY&); + + //!declared but undefined copy constructor as we don't want ANYs to be directly assigned. Can result in problems for more complicated data types (e.g., string) + CIEC_ANY& operator =(const CIEC_ANY& pa_roValue); + + bool m_bForced; + + //Anonymous union holding the data value of our IEC data type + union UAnyData{ + bool m_bBool; + + TForteByte m_cByte; + TForteWord m_cWord; + TForteDWord m_cDWord; + + TForteInt8 m_nInt8; + TForteInt16 m_nInt16; + TForteInt32 m_nInt32; + + TForteUInt8 m_nUInt8; + TForteUInt16 m_nUInt16; + TForteUInt32 m_nUInt32; + +#ifdef FORTE_USE_REAL_DATATYPE + TForteFloat m_fFloat; +#ifdef FORTE_USE_64BIT_DATATYPES + TForteDFloat m_fDFloat; +#endif //#ifdef FORTE_USE_64BIT_DATATYPES +#endif //#ifdef FORTE_USE_REAL_DATATYPE +#ifdef FORTE_USE_64BIT_DATATYPES + TForteInt64 m_nInt64; + TForteUInt64 m_nUInt64; + TForteByte m_AData[sizeof(TForteUInt64)]; //!< For data extraction in big endian machines +#else + TForteByte m_AData[sizeof(TForteUInt32)]; //!< For data extraction in big endian machines +#endif //#ifdef FORTE_USE_64BIT_DATATYPES + TLargestUIntValueType m_nLargestUInt; + TLargestIntValueType m_nLargestInt; + /*! \brief A pointer to general data that can be used for data types needing other data than that contained in the union + * + * This is needed as the current design does not allow that the size of data types when created is different from + * the size of the CIEC_ANY class. This data value will be used for example by string or array. + */ + TForteByte *m_pGenData; + }; + + UAnyData m_uAnyData; + +}; + +/*!\brief Type for handling CIEC_ANY pointers + */ +typedef CIEC_ANY* TIEC_ANYPtr; +typedef const CIEC_ANY* TConstIEC_ANYPtr; + +typedef CIEC_ANY IIEC_ANY; //TODO: for legacy support, will be deleted with next major release + +#endif /*_MANY_H_*/ diff --git a/src/core/datatypes/forte_any_bit.cpp b/src/core/datatypes/forte_any_bit.cpp new file mode 100644 index 000000000..1d48a26ae --- /dev/null +++ b/src/core/datatypes/forte_any_bit.cpp @@ -0,0 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2013, 2015 TU Wien ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Matthias Plasch - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_any_bit.h" + +DEFINE_FIRMWARE_DATATYPE(ANY_BIT, g_nStringIdANY_BIT) diff --git a/src/core/datatypes/forte_any_bit.h b/src/core/datatypes/forte_any_bit.h new file mode 100644 index 000000000..585d5f3c0 --- /dev/null +++ b/src/core/datatypes/forte_any_bit.h @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Monika Wenger, + * Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_BIT_H_ +#define _ANY_BIT_H_ + +#include "forte_any_elementary.h" + +/*!\ingroup COREDTS IIEC_ANY_BIT represents any bit data types according to IEC 61131. + */ +class CIEC_ANY_BIT : public CIEC_ANY_ELEMENTARY{ + DECLARE_FIRMWARE_DATATYPE(ANY_BIT) + + public: + virtual ~CIEC_ANY_BIT(){ + } + + protected: + CIEC_ANY_BIT() : + CIEC_ANY_ELEMENTARY(){ + } +}; + +#endif /*_MANY_BIT_H_*/ diff --git a/src/core/datatypes/forte_any_date.cpp b/src/core/datatypes/forte_any_date.cpp new file mode 100644 index 000000000..f6cc1e511 --- /dev/null +++ b/src/core/datatypes/forte_any_date.cpp @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH, nxtControl GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wener, Alois Zoitl, Stansilav Meduna + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include "forte_any_date.h" + +#if defined(WINCE) +#include +#endif + +TForteInt32 CIEC_ANY_DATE::sm_nTimeZoneOffset = -1; + +TForteInt32 CIEC_ANY_DATE::getTimeZoneOffset(){ + if(sm_nTimeZoneOffset == -1){ + time_t t = 24 * 60 * 60; // 2. 1. 1970 00:00:00 for UTC + +#if ! defined(WINCE) + struct tm *ptm = localtime(&t); +#else + struct tm *ptm = wceex_localtime(&t); +#endif + + if(ptm->tm_mday < 2) + sm_nTimeZoneOffset = 60 * ptm->tm_hour + ptm->tm_min - 24 * 60; + else + sm_nTimeZoneOffset = 60 * ptm->tm_hour + ptm->tm_min; + } + + return sm_nTimeZoneOffset; +} + +bool CIEC_ANY_DATE::setDateAndTime(struct tm &pa_rstTM, unsigned int pa_unMilliSec){ + + pa_rstTM.tm_isdst = -1; + + time_t nTime; +#if ! defined(WINCE) + nTime = mktime(&pa_rstTM); +#else + nTime = wceex_mktime(&pa_rstTM); +#endif + + if(nTime == (time_t) -1) + return false; + + setTUINT64(nTime * 1000ULL + pa_unMilliSec); + return true; +} + +struct tm *CIEC_ANY_DATE::getTimeStruct() const { + TForteUInt64 nToStringBuffer = getTUINT64(); + time_t nTime = static_cast(nToStringBuffer / 1000ULL); + + struct tm *pstRetVal; + +#if ! defined(WINCE) + pstRetVal = localtime(&nTime); +#else + pstRetVal = wceex_localtime(&nTime); +#endif + return pstRetVal; +} + +unsigned int CIEC_ANY_DATE::getMilliSeconds() const{ + return getTUINT64() % 1000ULL; +} diff --git a/src/core/datatypes/forte_any_date.h b/src/core/datatypes/forte_any_date.h new file mode 100644 index 000000000..375d95319 --- /dev/null +++ b/src/core/datatypes/forte_any_date.h @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Martin Melik Merkumians, Alois Zoitl, + * Monika Wenger, Stansilav Meduna + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_DAT_H_ +#define _ANY_DAT_H_ + +#include "forte_any_elementary.h" + +/*!\ingroup COREDTS IIEC_ANY_DATE represents any date data types according to IEC 61131. + */ +class CIEC_ANY_DATE : public CIEC_ANY_ELEMENTARY{ + public: + virtual ~CIEC_ANY_DATE(){ + } + + /*! Retrieve the current timezone + * + * Can be sed to adjust mktime()-related values + * + * @return Number of minutes west (negative) or east (positive), not taking DST into consideration + */ + static TForteInt32 getTimeZoneOffset(); + + /*! set the value of the data according to the given values + * + */ + bool setDateAndTime(struct tm &pa_rstTM, unsigned int pa_unMilliSec); + + /*! retrieve the time struct for the current value stored in this Data variable + */ + struct tm *getTimeStruct() const; + + /*! Get the milliseconds part of the data value + */ + unsigned int getMilliSeconds() const; + + protected: + CIEC_ANY_DATE() { + } + + private: + static TForteInt32 sm_nTimeZoneOffset; +}; + +#endif /*_MANY_DAT_H_*/ diff --git a/src/core/datatypes/forte_any_derived.h b/src/core/datatypes/forte_any_derived.h new file mode 100644 index 000000000..e4472842d --- /dev/null +++ b/src/core/datatypes/forte_any_derived.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Martin Melik Merkumians, Alois Zoitl, + * Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_DER_H_ +#define _ANY_DER_H_ + +#include "forte_any.h" + +/*!\ingroup COREDTS CIEC_ANY_DERIVED represents the user defined data types according to + * IEC 61131. + */ +class CIEC_ANY_DERIVED : public CIEC_ANY{ + public: + virtual ~CIEC_ANY_DERIVED(){ + } + + protected: + CIEC_ANY_DERIVED() { + } +}; + +#endif /*_MANY_DER_H_*/ diff --git a/src/core/datatypes/forte_any_elementary.cpp b/src/core/datatypes/forte_any_elementary.cpp new file mode 100644 index 000000000..d72b02f03 --- /dev/null +++ b/src/core/datatypes/forte_any_elementary.cpp @@ -0,0 +1,327 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH, fortiss GmbH, nxtControl GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Monika Wenger, Matthias Plasch, Martin Melik Markumians, + * Ingo Hegny, Stanislav Meduna + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_any_elementary.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "forte_any_elementary_gen.cpp" +#endif +#include +#include +#include "forte_sint.h" +#include "forte_int.h" +#include "forte_dint.h" +#include "forte_usint.h" +#include "forte_uint.h" +#include "forte_udint.h" +#include "forte_lint.h" +#include "forte_ulint.h" + +DEFINE_FIRMWARE_DATATYPE(ANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY) + +const CStringDictionary::TStringId CIEC_ANY_ELEMENTARY::scm_anTypeNameStringIds[] = { g_nStringIdANY, g_nStringIdBOOL, g_nStringIdSINT, g_nStringIdINT, g_nStringIdDINT, g_nStringIdLINT, g_nStringIdUSINT, g_nStringIdUINT, g_nStringIdUDINT, g_nStringIdULINT, g_nStringIdBYTE, g_nStringIdWORD, g_nStringIdDWORD, g_nStringIdLWORD, g_nStringIdDATE, g_nStringIdTIME_OF_DAY, g_nStringIdDATE_AND_TIME, g_nStringIdTIME, //until here simple Datatypes + g_nStringIdREAL, g_nStringIdLREAL, g_nStringIdSTRING, //e_STRING, + g_nStringIdWSTRING, //e_WSTRING, + CStringDictionary::scm_nInvalidStringId, //e_DerivedData, + CStringDictionary::scm_nInvalidStringId, //e_DirectlyDerivedData, + CStringDictionary::scm_nInvalidStringId, //e_EnumeratedData, + CStringDictionary::scm_nInvalidStringId, //e_SubrangeData, + CStringDictionary::scm_nInvalidStringId, //e_ARRAY, + CStringDictionary::scm_nInvalidStringId, //e_STRUCT, + CStringDictionary::scm_nInvalidStringId, //e_External, + CStringDictionary::scm_nInvalidStringId, //e_Max + }; + +int CIEC_ANY_ELEMENTARY::toString(char* pa_acValue, unsigned int pa_nBufferSize) const{ + int nRetVal = 0; + + TLargestUIntValueType nDivisor = 0; + TLargestUIntValueType nUBuffer = 0; + TLargestIntValueType nSBuffer = 0; + + bool bSigned = true; + + switch (getDataTypeID()){ + case e_SINT: { + nSBuffer = getTINT8(); + nDivisor = 100; + break; + } + case e_USINT: + case e_BYTE: { + nUBuffer = getTUINT8(); + nDivisor = 100; + bSigned = false; + break; + } + case e_INT: { + nSBuffer = getTINT16(); + nDivisor = 10000; + break; + } + case e_UINT: + case e_WORD: { + nUBuffer = getTUINT16(); + nDivisor = 10000; + bSigned = false; + break; + } + case e_DINT: { + nSBuffer = getTINT32(); + nDivisor = 1000000000L; + break; + } + case e_UDINT: + case e_DWORD: { + nUBuffer = getTUINT32(); + nDivisor = 1000000000L; + bSigned = false; + break; + } +#ifdef FORTE_USE_64BIT_DATATYPES + case e_LINT: { + nSBuffer = getTINT64(); + nDivisor = 1000000000000000000LL; + break; + } + case e_ULINT: + case e_LWORD: { + nUBuffer = getTUINT64(); + nDivisor = 10000000000000000000ULL; + bSigned = false; + break; + } +#endif + default: { + return -1; + } + } + + if(true == bSigned){ + if(nSBuffer < 0){ + if(nRetVal >= (int) pa_nBufferSize){ + return -1; + } + pa_acValue[nRetVal] = '-'; + nRetVal++; + nSBuffer *= -1; + } + nUBuffer = static_cast(nSBuffer); + } + + bool bLeadingZeros = true; + do{ + if((0 == nUBuffer / nDivisor) && (true == bLeadingZeros)){ + nDivisor /= 10; + continue; + } + else{ + bLeadingZeros = false; + } + if(nRetVal >= (int) pa_nBufferSize){ + return -1; + } + + pa_acValue[nRetVal] = static_cast(static_cast(nUBuffer / nDivisor) + '0'); + nUBuffer = nUBuffer - (pa_acValue[nRetVal] - '0') * nDivisor; + nDivisor /= 10; + nRetVal++; + } while(nDivisor > 1); + + if(nRetVal >= (int) pa_nBufferSize){ + return -1; + } + pa_acValue[nRetVal] = static_cast(static_cast(nUBuffer / nDivisor) + '0'); + nRetVal++; + + if(nRetVal >= (int) pa_nBufferSize){ + return -1; + } + pa_acValue[nRetVal] = '\0'; + + return nRetVal; +} + +int CIEC_ANY_ELEMENTARY::fromString(const char *pa_pacValue){ + int nRetVal = -1; + const char *pacRunner = pa_pacValue; + int nMultiplier = 10; + bool bSigned = true; + + if((0 == pa_pacValue) || ('\0' == *pa_pacValue)){ + return -1; + } + + if(e_ANY == getDataTypeID()){ + nRetVal = CIEC_ANY::fromString(pa_pacValue); + //TODO think of a check if it is really an any elementary that has been created + } + else{ + const char *acHashPos = strchr(pa_pacValue, '#'); + if((0 != acHashPos) && (!forte::core::util::isDigit(*pa_pacValue))){ + //if we have a hash and the first character is not a digit it has to be a type identifier + nRetVal = checkTypeSpec(pa_pacValue, acHashPos); + if(nRetVal < 0){ + return -1; + } + pacRunner += (nRetVal + 1); //put the runner one after the hash + nRetVal = -1; + } + + TLargestUIntValueType nUUpperBound = 0; + TLargestIntValueType nSUpperBound = 0; + TLargestIntValueType nSLowerBound = 0; + + if('#' == pacRunner[1]){ + switch (pacRunner[0]){ + case '2': + nMultiplier = 2; + break; + case '8': + nMultiplier = 8; + break; + default: + return -1; + break; + } + pacRunner = pacRunner + 2; + } + else if('\0' != pacRunner[1] && '#' == pacRunner[2]){ + if('1' == pacRunner[0]){ + if('6' == pacRunner[1]){ + nMultiplier = 16; + } + else{ + if('0' != pacRunner[1]){ + return -1; + } + } + } + else + return -1; + pacRunner = pacRunner + 3; + } + + EDataTypeID eID = getDataTypeID(); + switch (eID){ + case e_SINT: { + nSUpperBound = CIEC_SINT::scm_nMaxVal; + nSLowerBound = CIEC_SINT::scm_nMinVal; + break; + } + case e_INT: { + nSUpperBound = CIEC_INT::scm_nMaxVal; + nSLowerBound = CIEC_INT::scm_nMinVal; + break; + } + case e_DINT: { + nSUpperBound = CIEC_DINT::scm_nMaxVal; + nSLowerBound = CIEC_DINT::scm_nMinVal; + break; + } + +#ifdef FORTE_USE_64BIT_DATATYPES + case e_LINT: { + nSUpperBound = CIEC_LINT::scm_nMaxVal; + nSLowerBound = CIEC_LINT::scm_nMinVal; + break; + } +#endif + case e_USINT: + case e_BYTE: { + nUUpperBound = CIEC_USINT::scm_nMaxVal; + bSigned = false; + break; + } + + case e_UINT: + case e_WORD: { + nUUpperBound = CIEC_UINT::scm_nMaxVal; + bSigned = false; + break; + } + + case e_UDINT: + case e_DWORD: { + nUUpperBound = CIEC_UDINT::scm_nMaxVal; + bSigned = false; + break; + } + +#ifdef FORTE_USE_64BIT_DATATYPES + case e_ULINT: + case e_LWORD: { + nUUpperBound = CIEC_ULINT::scm_nMaxVal; + bSigned = false; + break; + } +#endif + + default: { + return false; + } + } + + if((bSigned) && (10 != nMultiplier)){ + //only decimal numbers have a sign + bSigned = false; + nUUpperBound = 2 * nSUpperBound + 1; + } + + char *pacEndPtr; + errno = 0; //erno is not cleared by the strto* functions + + if(true == bSigned){ +#ifdef FORTE_USE_64BIT_DATATYPES + TForteInt64 nValue = forte::core::util::strtoll(pacRunner, &pacEndPtr, nMultiplier); +#else + TForteInt32 nValue = forte::core::util::strtol(pacRunner, &pacEndPtr, nMultiplier); +#endif + + if((ERANGE != errno)&& (nValue <= nSUpperBound) && (nValue + >= nSLowerBound)){ + setLargestInt(nValue); + nRetVal = static_cast(pacEndPtr - pa_pacValue); + } + } + else{ + if ('-' != *pacRunner){ + //The strtou* functions will correctly parse also negative numbers and provide their two complement as value +#ifdef FORTE_USE_64BIT_DATATYPES + TForteUInt64 nValue = forte::core::util::strtoull(pacRunner, &pacEndPtr, nMultiplier); +#else + TForteUInt32 nValue = forte::core::util::strtoul(pacRunner, &pacEndPtr, nMultiplier); +#endif //FORTE_USE_64BIT_DATATYPES + if ((ERANGE != errno) && (nValue <= nUUpperBound)){ + setLargestUInt(nValue); + nRetVal = static_cast(pacEndPtr - pa_pacValue); + } + } + } + if(0 == nRetVal){ + // at this point a length of zero means broken string so return -1 + nRetVal = -1; + } + } + return nRetVal; +} + +int CIEC_ANY_ELEMENTARY::checkTypeSpec(const char *pa_pacValue, const char *pa_pacHashPos){ + int nRetVal = -1; + + CStringDictionary::TStringId nTypeNameId = parseTypeName(pa_pacValue, pa_pacHashPos); + + if((CStringDictionary::scm_nInvalidStringId != nTypeNameId) && (scm_anTypeNameStringIds[getDataTypeID()] == nTypeNameId)){ + nRetVal = static_cast(pa_pacHashPos - pa_pacValue); + } + return nRetVal; +} + diff --git a/src/core/datatypes/forte_any_elementary.h b/src/core/datatypes/forte_any_elementary.h new file mode 100644 index 000000000..51431f94f --- /dev/null +++ b/src/core/datatypes/forte_any_elementary.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Martin Melik Merkumians, Alois Zoitl, + * Monika Wenger, Stansilav Meduna + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_ELE_H_ +#define _ANY_ELE_H_ + +#include "forte_any.h" +#include +#include + +/*!\ingroup COREDTS IIEC_ANY_ELEMENTARY represents the elementary data types according to + * IEC 61131. + */ +class CIEC_ANY_ELEMENTARY : public CIEC_ANY{ + DECLARE_FIRMWARE_DATATYPE(ANY_ELEMENTARY) + + public: + + CIEC_ANY_ELEMENTARY(const CIEC_ANY_ELEMENTARY &pa_roVal) : + CIEC_ANY(){ + setLargestUInt(pa_roVal.getLargestUInt()); + } + + virtual ~CIEC_ANY_ELEMENTARY(){ + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_ANY; + } + + virtual int toString(char* pa_acValue, unsigned int pa_nBufferSize) const; + virtual int fromString(const char *pa_rsValue); + + protected: + CIEC_ANY_ELEMENTARY() { + } + + private: + + int checkTypeSpec(const char *pa_pacValue, const char *pa_pacHashPos); + + const static CStringDictionary::TStringId scm_anTypeNameStringIds[]; + const static int scm_nMaxTypeNameLength = 13; + +}; + +#endif /*_MANY_ELE_H_*/ diff --git a/src/core/datatypes/forte_any_int.cpp b/src/core/datatypes/forte_any_int.cpp new file mode 100644 index 000000000..817611f85 --- /dev/null +++ b/src/core/datatypes/forte_any_int.cpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_any_int.h" + +DEFINE_FIRMWARE_DATATYPE(ANY_INT, g_nStringIdANY_INT) + +CIEC_ANY_INT::CIEC_ANY_INT(TLargestIntValueType paVal){ + setSignedValue(paVal); +} diff --git a/src/core/datatypes/forte_any_int.h b/src/core/datatypes/forte_any_int.h new file mode 100644 index 000000000..d4dc90fb4 --- /dev/null +++ b/src/core/datatypes/forte_any_int.h @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Monika Wenger, + * Martin Melik Markumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_INT_H_ +#define _ANY_INT_H_ + +#include "forte_any_num.h" + +/*!\ingroup COREDTS CIEC_ANY_INT represents all integer data types according to IEC 61131. + + */ +class CIEC_ANY_INT : public CIEC_ANY_NUM{ + DECLARE_FIRMWARE_DATATYPE(ANY_INT) + + public: + CIEC_ANY_INT(TLargestIntValueType paVal); + + virtual ~CIEC_ANY_INT(){ + } + + bool isSigned() const{ + bool bRetVal = false; + if(e_LINT <= getDataTypeID()){ + bRetVal = true; + } + return bRetVal; + } + + TLargestUIntValueType getUnsignedValue() const{ + return getLargestUInt(); + } + + TLargestIntValueType getSignedValue() const{ + return getLargestInt(); + } + + void setSignedValue(TLargestIntValueType m_nVal){ + setLargestInt(m_nVal); + } + + void setUnsignedValue(TLargestIntValueType m_nVal){ + setLargestInt(m_nVal); + } + + CIEC_ANY_INT() { + } +}; + +#endif /*_MANY_INT_H_*/ diff --git a/src/core/datatypes/forte_any_magnitude.cpp b/src/core/datatypes/forte_any_magnitude.cpp new file mode 100644 index 000000000..931d74fee --- /dev/null +++ b/src/core/datatypes/forte_any_magnitude.cpp @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_any_magnitude.h" + +DEFINE_FIRMWARE_DATATYPE(ANY_MAGNITUDE, g_nStringIdANY_MAGNITUDE) + diff --git a/src/core/datatypes/forte_any_magnitude.h b/src/core/datatypes/forte_any_magnitude.h new file mode 100644 index 000000000..f644b4d25 --- /dev/null +++ b/src/core/datatypes/forte_any_magnitude.h @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Monika Wenger, + * Martin Melik Markumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_MAG_H_ +#define _ANY_MAG_H_ + +#include "forte_any_elementary.h" + +/*!\ingroup COREDTS CIEC_ANY_MAGNITUDE represents the magnitude data types according to + * IEC 61131. + + */ +class CIEC_ANY_MAGNITUDE : public CIEC_ANY_ELEMENTARY{ + DECLARE_FIRMWARE_DATATYPE(ANY_MAGNITUDE) + + public: + virtual ~CIEC_ANY_MAGNITUDE(){ + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_ANY; + } + + protected: + CIEC_ANY_MAGNITUDE(){ + } +}; + +#endif /*_MANY_MAG_H_*/ diff --git a/src/core/datatypes/forte_any_num.cpp b/src/core/datatypes/forte_any_num.cpp new file mode 100644 index 000000000..c9186b5de --- /dev/null +++ b/src/core/datatypes/forte_any_num.cpp @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_any_num.h" + +DEFINE_FIRMWARE_DATATYPE(ANY_NUM, g_nStringIdANY_NUM) diff --git a/src/core/datatypes/forte_any_num.h b/src/core/datatypes/forte_any_num.h new file mode 100644 index 000000000..4cafa2b93 --- /dev/null +++ b/src/core/datatypes/forte_any_num.h @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Monika Wenger, + * Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_NUM_H_ +#define _ANY_NUM_H_ + +#include "forte_any_magnitude.h" + +/*!\ingroup COREDTS CIEC_ANY_NUM represents any number data types according to IEC 61131. + + */ +class CIEC_ANY_NUM : public CIEC_ANY_MAGNITUDE{ + DECLARE_FIRMWARE_DATATYPE(ANY_NUM) + + public: + virtual ~CIEC_ANY_NUM(){ + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_ANY; + } + protected: + CIEC_ANY_NUM() { + + } + +}; + +#endif /*_MANY_NUM_H_*/ diff --git a/src/core/datatypes/forte_any_real.cpp b/src/core/datatypes/forte_any_real.cpp new file mode 100644 index 000000000..14e680aab --- /dev/null +++ b/src/core/datatypes/forte_any_real.cpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_any_real.h" + +DEFINE_FIRMWARE_DATATYPE(ANY_REAL, g_nStringIdANY_REAL) + + + + diff --git a/src/core/datatypes/forte_any_real.h b/src/core/datatypes/forte_any_real.h new file mode 100644 index 000000000..2dabb179a --- /dev/null +++ b/src/core/datatypes/forte_any_real.h @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Monika Wenger, + * Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_REA_H_ +#define _ANY_REA_H_ + +#include "forte_any_num.h" + +/*!\ingroup COREDTS CIEC_ANY_REAL represents any real data types according to IEC 61131. + + */ +class CIEC_ANY_REAL : public CIEC_ANY_NUM{ + DECLARE_FIRMWARE_DATATYPE(ANY_REAL) + + public: + virtual ~CIEC_ANY_REAL(){ + } + + protected: + CIEC_ANY_REAL() { + } +}; + +#endif /*_MANY_REA_H_*/ diff --git a/src/core/datatypes/forte_any_string.cpp b/src/core/datatypes/forte_any_string.cpp new file mode 100644 index 000000000..e83d9f3d9 --- /dev/null +++ b/src/core/datatypes/forte_any_string.cpp @@ -0,0 +1,287 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2015 nxtControl GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stansilav Meduna, Alois Zoitl, Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "forte_any_string.h" +#include "unicode_utils.h" +#include +#include +#include + +DEFINE_FIRMWARE_DATATYPE(ANY_STRING, g_nStringIdANY_STRING) + +char CIEC_ANY_STRING::sm_acNullString[1] = {'\0'}; + +CIEC_ANY_STRING::~CIEC_ANY_STRING(){ + if(getGenData()){ + forte_free(getGenData()); + } +} + +CIEC_ANY_STRING& CIEC_ANY_STRING::operator =(const char* const pa_pacValue){ + if(0 != pa_pacValue){ + size_t nLen = strlen(pa_pacValue); + if (nLen > scm_unMaxStringLen) { + //If we get a to large string we will truncate it + nLen = scm_unMaxStringLen; + DEVLOG_WARNING("Too large string given in assignment, destination will be truncated!\n"); + } + assign(pa_pacValue, static_cast(nLen)); + } + return *this; +} + +void CIEC_ANY_STRING::assign(const char *pa_poData, TForteUInt16 pa_nLen) { + if(0 != pa_nLen){ + if (pa_poData != getValue()) { + reserve(pa_nLen); + memcpy(getValue(), pa_poData, pa_nLen); + } + } + if(0 != getValue()){ + setLength(pa_nLen); + getValue()[pa_nLen] = '\0'; //not really necessary, but is a stop if someone forgets that this is not a textual string + } +} + +void CIEC_ANY_STRING::append(const char *pa_poData) { + append(pa_poData, static_cast(strlen(pa_poData))); +} + +void CIEC_ANY_STRING::append(const char *pa_poData, TForteUInt16 pa_nLen) { + TForteUInt16 nLen = length(); + if(0 != pa_nLen){ + if ((getCapacity() - nLen) < pa_nLen) { + reserve(static_cast(nLen + pa_nLen)); + } + if(0 != getValue()){ + memcpy(getValue() + nLen, pa_poData, pa_nLen); + setLength(static_cast(nLen + pa_nLen)); + getValue()[nLen + pa_nLen] = '\0'; //not really necessary, but is a stop if someone forgets that this is not a textual string + } + } + +} + +void CIEC_ANY_STRING::reserve(TForteUInt16 pa_nRequestedSize){ + if(getCapacity() < pa_nRequestedSize + 1){ + bool firstAlloc = (getGenData() == 0); + TForteUInt16 nLength = length(); + TForteUInt16 nNewLength = static_cast((getCapacity() * 3) >> 1); + if(nNewLength < pa_nRequestedSize){ + nNewLength = pa_nRequestedSize; + } + setGenData((TForteByte *) forte_realloc(getGenData(), nNewLength + 5)); // the plus five are 2 bytes for length, 2 bytes for capacity and one for a backup \0 + setAllocatedLength(static_cast(nNewLength)); //only newLength is useable for strings and should be considered in the size checks + if (firstAlloc) { + setLength(nLength); //necessary to initialize the length if this is the first reserve call + getValue()[nLength] = '\0'; + } + } +} + +int CIEC_ANY_STRING::determineEscapedStringLength(const char *pa_pacValue, char pa_cDelimiter){ + if (*pa_pacValue != pa_cDelimiter){ + return static_cast(strlen(pa_pacValue)); + } + + const char *pacRunner; + for (pacRunner = pa_pacValue+1; *pacRunner != pa_cDelimiter && *pacRunner; ++pacRunner) { + if('$' == *pacRunner){ + TForteUInt16 nDummy; + ++pacRunner; + if (*pacRunner == '\0') + break; + if(!handleDollarEscapedChar(&pacRunner, (pa_cDelimiter == '"'), nDummy)){ + continue; // It is invalid but we need the real end + } + } + } + + return (pa_cDelimiter == *pacRunner) ? static_cast(pacRunner + 1 - pa_pacValue) : -1; +} + +bool CIEC_ANY_STRING::handleDollarEscapedChar(const char **pa_pacValue, bool pa_bWide, TForteUInt16 &pa_rnValue){ + bool bRetVal = true; + switch((*pa_pacValue)[0]){ + case '\'': + case '\"': + pa_rnValue = (*pa_pacValue)[0]; + break; + case 'L': + case 'l': + pa_rnValue = 0x10; //ASCI 0x10 is the line feed character + break; + case 'N': + case 'n': + pa_rnValue ='\n'; + break; + case 'P': + case 'p': + pa_rnValue = '\f'; + break; + case 'R': + case 'r': + pa_rnValue = '\r'; + break; + case 'T': + case 't': + pa_rnValue = '\t'; + break; + case '$': + pa_rnValue = '$'; + break; + default: + bRetVal = parseEscapedHexNum(pa_pacValue, pa_bWide, pa_rnValue); + break; + } + return bRetVal; +} + +int CIEC_ANY_STRING::dollarEscapeChar(char *pa_pacValue, char pa_cValue, unsigned int pa_nBufferSize) { + unsigned int nUsedBytes = 1; + char cVal = pa_cValue; + switch(pa_cValue){ + case '$': + ++nUsedBytes; + cVal = '$'; + break; + case '\'': + ++nUsedBytes; + cVal = '\''; + break; + case 0x10: // line feed + ++nUsedBytes; + cVal = 'l'; + break; + case '\n': + ++nUsedBytes; + cVal = 'n'; + break; + case '\f': + ++nUsedBytes; + cVal = 'p'; + break; + case '\r': + ++nUsedBytes; + cVal = 'r'; + break; + case '\t': + ++nUsedBytes; + cVal = 't'; + break; + case '\"': + ++nUsedBytes; + cVal = '\"'; + break; + default: + break; + } + + if (pa_pacValue == 0) + return nUsedBytes; + + if (nUsedBytes > pa_nBufferSize) + return -1; + + if (nUsedBytes == 2) + *pa_pacValue++ = '$'; + + *pa_pacValue = cVal; + + return nUsedBytes; +} + +bool CIEC_ANY_STRING::parseEscapedHexNum(const char **pa_pacValue, bool pa_bWide, TForteUInt16 &pa_rnValue){ + bool bRetVal = false; + + pa_rnValue = 0; + if (forte::core::util::isHexDigit((*pa_pacValue)[0])){ + pa_rnValue = static_cast(forte::core::util::charHexDigitToInt((*pa_pacValue)[0]) << 4); + if (forte::core::util::isHexDigit((*pa_pacValue)[1])){ + pa_rnValue |= forte::core::util::charHexDigitToInt((*pa_pacValue)[1]); + + if (pa_bWide) { + pa_rnValue <<= 8; + + if (forte::core::util::isHexDigit((*pa_pacValue)[2])) + pa_rnValue |= forte::core::util::charHexDigitToInt((*pa_pacValue)[2]) << 4; + else + return false; + + if (forte::core::util::isHexDigit((*pa_pacValue)[3])) + pa_rnValue |= forte::core::util::charHexDigitToInt((*pa_pacValue)[3]); + else + return false; + } + + *pa_pacValue += pa_bWide ? 3 : 1; + bRetVal = true; + } + } + return bRetVal; +} + +int CIEC_ANY_STRING::unescapeFromString(const char *pa_pacValue, char pa_cDelimiter) { + TForteUInt16 nLen = 0; + int nRetVal = -1; + const char *pacRunner = pa_pacValue; + TForteUInt16 nValue; + bool bWide = (pa_cDelimiter == '"'); + + if(*pacRunner == pa_cDelimiter){ + //remove leading string delimiter char + ++pacRunner; + } + + char *acValue = getValue(); + while((*pacRunner != '\0') && (nLen != scm_unMaxStringLen)){ + if('$' == *pacRunner){ + ++pacRunner; + if (*pacRunner == '\0') + break; + if(!handleDollarEscapedChar(&pacRunner, bWide, nValue)){ + return -1; + } + +#ifdef FORTE_USE_WSTRING_DATATYPE + if (! bWide) +#endif + acValue[nLen] = (char) nValue; +#ifdef FORTE_USE_WSTRING_DATATYPE + else { + int nEncLen = CUnicodeUtilities::encodeUTF8Codepoint(reinterpret_cast(acValue + nLen), 3, nValue); + if (nEncLen < 0) + return -1; + nLen = static_cast(nLen + nEncLen - 1); + } +#endif + } + else{ + if(pa_cDelimiter == *pacRunner){ + //we are at the end of the string + ++pacRunner; + break; + } + else{ + acValue[nLen] = *pacRunner; + } + } + ++pacRunner; + ++nLen; + } + + getValue()[nLen] = '\0'; + setLength(static_cast(nLen)); + nRetVal = static_cast(pacRunner - pa_pacValue); + + return nRetVal; +} diff --git a/src/core/datatypes/forte_any_string.h b/src/core/datatypes/forte_any_string.h new file mode 100644 index 000000000..e863ecb2e --- /dev/null +++ b/src/core/datatypes/forte_any_string.h @@ -0,0 +1,177 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Stanislav Meduna, Monika Wenger, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ANY_STR_H_ +#define _ANY_STR_H_ + +#include "forte_any_elementary.h" + +/*!\ingroup COREDTS IIEC_ANY_STRING represents any bit data types according to IEC 61131. + */ +class CIEC_ANY_STRING : public CIEC_ANY_ELEMENTARY{ + DECLARE_FIRMWARE_DATATYPE(ANY_STRING) + + public: + static const unsigned int scm_unMaxStringLen = 65534; //save one for the \0 needed for allocated length + + virtual ~CIEC_ANY_STRING(); + + CIEC_ANY_STRING(const CIEC_ANY_STRING& pa_roValue) : + CIEC_ANY_ELEMENTARY(){ + this->assign(pa_roValue.getValue(), pa_roValue.length()); + } + + CIEC_ANY_STRING &operator=(const CIEC_ANY_STRING& pa_roValue){ + this->assign(pa_roValue.getValue(), pa_roValue.length()); + return *this; + } + + /*! \brief Operator: CIEC_STRING data type = string data type + * + * This command implements the assignment operator for the C++ datatype STRING + * The parameter value is represented by a C++ variable (call by value). + * \param pa_pacValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_ANY_STRING& operator =(const char* const pa_pacValue); + + /*! \brief Get-Method for CIEC_ANY_STRING + * + * With this command the value of the actual object can be read. + * \param - No parameters necessary. + * \return Can be the following response: + * - Actual value of the object. + */ + + char* getValue(void){ + return ((char *) ((0 != getGenData()) ? reinterpret_cast(getGenData() + 4) : sm_acNullString)); + } + + const char *getValue(void) const{ + return (const char *) ((0 != getGenData()) ? reinterpret_cast(getGenData() + 4) : sm_acNullString); + } + + TForteUInt16 length() const{ + return (0 != getGenData()) ? (*((TForteUInt16 *) (getGenData()))) : static_cast(0); + } + + void clear(){ + assign(0,0); + } + + bool empty() const{return length() == 0;} + + /*! Assign arbitrary data (can contain '0x00') + */ + void assign(const char *pa_poData, TForteUInt16 pa_nLen); + + /*! Append arbitrary data (can contain '0x00') + */ + void append(const char *pa_poData, TForteUInt16 pa_nLen); + + /*! Append arbitrary data (can contain '0x00') + */ + void append(const char *pa_poData); + + /*! Try to reserve enough space to hold a string with given length. + * After this function the string will be at least of the size given. + */ + void reserve(TForteUInt16 pa_nRequestedSize); + + /*! Retrieve the current allocated size + * + * @return number of bytes that this string has allocated for use + */ + TForteUInt16 getCapacity() const{ + return (0 != getGenData()) ? (*((TForteUInt16 *) (getGenData() + 2))) : static_cast(0); + } + +#ifdef FORTE_UNICODE_SUPPORT + /*! \brief Converts a UTF-8 encoded string to a variable + * + * This command implements a conversion function from a UTF-16 + * encoded string (found e.g. in XML to the internal + * ISO 10646 Row 00 encoding. + * \param pa_pacBuffer Reference to the given UTF-8 encoded byte array + * \param pa_nLen Length to read (-1 for null-terminated) + * \param pa_bUnescape Handle $-escapes and delimiter characters at the beginning and end + * \return Can be the following response: + * \return number of bytes used from srcString + * -1 on error + */ + virtual int fromUTF8(const char *, int, bool){return 0;} + + /*! \brief Converts the variable to a UTF-8 representation + * + * This command implements a conversion function from a WSTRING + * to a UTF-8 encoding, usable e.g. for the serialization. + * \param pa_pacBuffer Reference to the output buffer. If 0, only the needed size will be computed. + * \param pa_nBufferSize Size of the provided buffer. + * \param pa_bEscape Produce $-escapes and delimiter characters at the beginning and end + * \return number of bytes used in the buffer + * -1 on error + */ + virtual int toUTF8(char*, unsigned int, bool) const{return 0;} +#endif + + protected: + static char sm_acNullString[]; + + /*! \brief Determines the source length of a potentially escaped string + * + * If the given string starts with a delimiter, the method searches for the ending + * delimiter and return the length including the delimiters. + * If the string does not start with the delimiter, this method is equivalent to strlen. + * + * Note: the returned length can be > scm_unMaxStringLen, so even larger strings + * can be truncated and their end still be found + * + * \param pa_pacValue Source string + * @param pa_cDelimiter string delimiting character (i.e., ' for STRING, " for WSTRING) + * \return length of the string, -1 if it starts with a delimiter but does not end with one + */ + static int determineEscapedStringLength(const char *pa_pacValue, char pa_cDelimiter); + + static bool handleDollarEscapedChar(const char **pa_pacValue, bool pa_bWide, TForteUInt16 &pa_rnValue); + // Use null as destination for just determining the need of escaping + static int dollarEscapeChar(char *pa_pacValue, char pa_cValue, unsigned int pa_nBufferSize); + static bool parseEscapedHexNum(const char **pa_pacValue, bool pa_bWide, TForteUInt16 &pa_rnValue); + + /*! \brief Unescape the input string. + * + * As the unescaping never makes the string longer, it can be used in-place + * @param pa_pacValue the source trong to unescape from + * @param pa_cDelimiter string delimiting character (i.e., ' for STRING, " for WSTRING) + * @return on success number of bytes take from src string + * -1 on error + */ + int unescapeFromString(const char *pa_pacValue, char pa_cDelimiter); + + void setLength(TForteUInt16 pa_unVal){ + TForteByte *pBuf = getGenData(); + if(0 != pBuf){ + *((TForteUInt16 *) (pBuf)) = pa_unVal; + } + } + + void setAllocatedLength(TForteUInt16 pa_unVal){ + TForteByte *pBuf = getGenData(); + if(0 != pBuf){ + *((TForteUInt16 *) (pBuf + 2)) = pa_unVal; + } + } + + CIEC_ANY_STRING(){ + } +}; + +#endif /*_MANY_STR_H_*/ diff --git a/src/core/datatypes/forte_array.cpp b/src/core/datatypes/forte_array.cpp new file mode 100644 index 000000000..e817d1b86 --- /dev/null +++ b/src/core/datatypes/forte_array.cpp @@ -0,0 +1,187 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2015 ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Stansilav Meduna + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "forte_array.h" +#include + + +#ifdef FORTE_SUPPORT_ARRAYS +DEFINE_FIRMWARE_DATATYPE(ARRAY, g_nStringIdARRAY) + +CIEC_ARRAY::CIEC_ARRAY() { +} + +CIEC_ARRAY::CIEC_ARRAY(TForteUInt16 pa_nLength, CStringDictionary::TStringId pa_unArrayType) { + setup(pa_nLength, pa_unArrayType); +} + +CIEC_ARRAY::CIEC_ARRAY(const CIEC_ARRAY& pa_roValue) : + CIEC_ANY_DERIVED(){ + + TForteInt16 nSize = pa_roValue.size(); + + if(0 != nSize){ + setGenData((TForteByte *) forte_malloc(8 + (1 + pa_roValue.size()) * sizeof(CIEC_ANY))); + if(0 != getGenData()){ + setSize(pa_roValue.size()); + TForteByte *acDataBuf = (TForteByte *) (getArray() - 1); // The first element is a reference element + const CIEC_ANY *poBuf = pa_roValue.getArray() - 1; + + for(int i = 0; i <= nSize; ++i, ++poBuf){ + //as we acDataBuf is already the target place we don't need to store the resulting pointer + poBuf->clone(acDataBuf); //clone is faster than the CTypeLib call + acDataBuf += sizeof(CIEC_ANY); + } + } + } + +} + +CIEC_ARRAY::~CIEC_ARRAY(){ + clear(); +} + +void CIEC_ARRAY::setup(TForteUInt16 pa_nLength, CStringDictionary::TStringId pa_unArrayType){ + if(0 != pa_nLength){ + if(0 != getGenData()){ + clear(); + } + + // The first element is a reference element, that is used + // - to initialize the elements not set by fromString or deserialize + // - to get the element id, even if the array has a zero size (not enabled yet, open to discussion) + + setGenData((TForteByte *) forte_malloc(8 + (1 + pa_nLength) * sizeof(CIEC_ANY))); + setSize(pa_nLength); + TForteByte *acDataBuf = (TForteByte *) (getArray() - 1); // The first element is a reference element + CIEC_ANY *poBuf = CTypeLib::createDataTypeInstance(pa_unArrayType, acDataBuf); + + for(unsigned int i = 0; i < pa_nLength; ++i){ + acDataBuf += sizeof(CIEC_ANY); + //as we acDataBuf is already the target place we don't need to store the resulting pointer + poBuf->clone(acDataBuf); //clone is faster than the CTypeLib call + } + } +} + +void CIEC_ARRAY::setValue(const CIEC_ANY& pa_roValue){ + if(pa_roValue.getDataTypeID() == e_ARRAY){ + //TODO maybe check if array data is of same type or castable + const CIEC_ANY *poSrcArray = static_cast(pa_roValue).getArray(); + + TForteUInt16 unSize = (size() < static_cast(pa_roValue).size()) ? size() : static_cast(pa_roValue).size(); + + for(TForteUInt16 i = 0; i < unSize; ++i, ++poSrcArray){ + (*this)[i]->setValue(*poSrcArray); + } + } +} + +void CIEC_ARRAY::clear(){ + if(size()){ + CIEC_ANY *poArray = getArray(); + for(unsigned int i = 0; i < size(); ++i, ++poArray){ + poArray->~CIEC_ANY(); + } + + forte_free(getGenData()); + setGenData(0); + } +} + +//TODO: for full compliance support of multiple element-statements must be implemented +int CIEC_ARRAY::fromString(const char *pa_pacValue){ + int nRetVal = -1; + const char *pcRunner = pa_pacValue; + if('[' == pa_pacValue[0]){ + + CIEC_ANY *poBufVal = 0; + TForteUInt16 i = 0; + TForteUInt16 unArraySize = size(); + int nValueLen; + + while((*pcRunner != '\0') && (*pcRunner != ']')){ + pcRunner++; + if(i < unArraySize){ + nValueLen = (*this)[i]->fromString(pcRunner); + } + else{ + if(0 == poBufVal) + poBufVal = (getArray() - 1)->clone(0); + nValueLen = poBufVal->fromString(pcRunner); + } + if((0 < nValueLen) && ((',' == pcRunner[nValueLen]) || (']' == pcRunner[nValueLen]))){ + pcRunner += nValueLen; + } + else{ + //we have an error or the end bracket + break; + } + i++; + } + if(*pcRunner == ']'){ + //arrays have to and on a closing bracket + nRetVal = pcRunner - pa_pacValue + 1; //+1 from the closing bracket + // For the rest of the array size copy the default element + for(; i < unArraySize; ++i){ + (*this)[i]->setValue(*(&(getArray()[-1]))); + } + } + delete poBufVal; + } + return nRetVal; +} + +int CIEC_ARRAY::toString(char* pa_acValue, unsigned int pa_nBufferSize) const{ + int nBytesUsed = -1; + + if(pa_nBufferSize){ + *pa_acValue = '['; + pa_acValue++; + pa_nBufferSize--; + nBytesUsed = 1; + int nUsedBytesByElement; + TForteUInt16 unSize = size(); + const CIEC_ANY *poArray = getArray(); + for(unsigned int i = 0; i < unSize; ++i, ++poArray){ + nUsedBytesByElement = poArray->toString(pa_acValue, pa_nBufferSize); + if(-1 == nUsedBytesByElement){ + return -1; + } + pa_nBufferSize -= nUsedBytesByElement; + pa_acValue += nUsedBytesByElement; + if(!pa_nBufferSize){ + return -1; + } + + nBytesUsed += nUsedBytesByElement; + + if(i != static_cast(unSize - 1)){ + *pa_acValue = ','; + pa_acValue++; + + ++nBytesUsed; + pa_nBufferSize--; + } + } + if(pa_nBufferSize < 2){ + return -1; + } + *pa_acValue = ']'; + pa_acValue[1] = '\0'; + nBytesUsed++; + } + + return nBytesUsed; +} + +#endif /* FORTE_SUPPORT_ARRAYS */ diff --git a/src/core/datatypes/forte_array.h b/src/core/datatypes/forte_array.h new file mode 100644 index 000000000..ce728ac6d --- /dev/null +++ b/src/core/datatypes/forte_array.h @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2013 ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Stansilav Meduna, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_ARRAY_H_ +#define _FORTE_ARRAY_H_ + +#include "forte_any_derived.h" + +#ifdef FORTE_SUPPORT_ARRAYS + +/*!\ingroup COREDTS CIEC_ARRAY represents the array data type according to IEC 61131. + */ +class CIEC_ARRAY : public CIEC_ANY_DERIVED{ + DECLARE_FIRMWARE_DATATYPE(ARRAY) + public: + CIEC_ARRAY(TForteUInt16 pa_nLength, CStringDictionary::TStringId pa_unArrayType); + + explicit CIEC_ARRAY(const CIEC_ARRAY& pa_roValue); + + virtual ~CIEC_ARRAY(); + + //!Function to configure the array if it is created via the typelib + void setup(TForteUInt16 pa_nLength, CStringDictionary::TStringId pa_unArrayType); + + /*! \brief Get the array's size + * + * With this command the size of the array can be evaluated. + * + * \param - No parameters necessary. + * \return - the length of the array. + */ + TForteUInt16 size() const{ + return (0 != getGenData()) ? (*((TForteUInt16 *) (getGenData()))) : static_cast(0); + } + + /*! \brief Operator: CIEC_INT data type [unsigned int] data type + * + * This command implements the index operator for a C++ unsigned int index. + * \param pa_nIndex Index + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_ANY* operator [](TForteUInt16 pa_nIndex){ + if(pa_nIndex < size()){ + return &(getArray()[pa_nIndex]); + } + return 0; + } + ; + + const CIEC_ANY* operator [](TForteUInt16 pa_nIndex) const{ + if(pa_nIndex < size()){ + return &(getArray()[pa_nIndex]); + } + return 0; + } + + + CIEC_ARRAY& operator =(const CIEC_ARRAY &pa_roValue){ + setValue(pa_roValue); + return *this; + } + + /*! \brief Get the data type of elements inside the array + * + */ + CIEC_ANY::EDataTypeID getElementDataTypeID() const{ + return getArray() != 0 ? getArray()[-1].getDataTypeID() : CIEC_ANY::e_ANY; + } + ; + + virtual void setValue(const CIEC_ANY& pa_roValue); + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_ARRAY; + } + + /*! \brief Converts array value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (array format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_rsValue); + /*! \brief Converts data type value to array + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (array format). + * This function is necessary for communication with a proper engineering system. + * \param pa_rsValue Reference to the given String + * \return number of bytes used in the buffer + * -1 on error + */ + virtual int toString(char* pa_acValue, unsigned int pa_nBufferSize) const; + protected: + + private: + //This constructor is only to be used by the create instance method + CIEC_ARRAY(); + + /*! \brief CIEC_ARRAY data type member value is a array of CIEC_ANY. + * + * This list contains the elements in the array of the type given by + * the reference pointer. + * + * Note: the pointers have to be correctly aligned. To accommodate 64-bit + * pointers there is a 6-byte gap after the 2-byte array size. + */ + CIEC_ANY *getArray(){ + return static_cast((0 != getGenData()) ? ((CIEC_ANY *) (getGenData() + 8)) + 1 : 0); + } + + const CIEC_ANY *getArray() const{ + return static_cast((0 != getGenData()) ? ((const CIEC_ANY *) (getGenData() + 8)) + 1 : 0); + } + + void setSize(TForteUInt16 pa_unVal){ + TForteByte *pBuf = getGenData(); + if(0 != pBuf){ + *((TForteUInt16 *) (pBuf)) = pa_unVal; + } + } + + void clear(); + }; + +#endif /* FORTE_SUPPORT_ARRAYS */ + +#endif /*_FORTE_ARRAY_H_*/ diff --git a/src/core/datatypes/forte_bool.cpp b/src/core/datatypes/forte_bool.cpp new file mode 100644 index 000000000..415086eec --- /dev/null +++ b/src/core/datatypes/forte_bool.cpp @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Rene Smodic, + * Gerhard Ebenhofer, Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_bool.h" +#include + +DEFINE_FIRMWARE_DATATYPE(BOOL, g_nStringIdBOOL) + +const TForteUInt16 CIEC_BOOL::scm_unMaxStringBufSize = 5; + +int CIEC_BOOL::fromString(const char *pa_pacValue){ + int nRetVal = 0; + + if(0 == strncmp(pa_pacValue, "BOOL#", 5)){ + pa_pacValue += 5; + nRetVal += 5; + } + + if(pa_pacValue[0] == '1'){ + setTBOOL8(true); + nRetVal += 1; + } + else{ + if(pa_pacValue[0] == '0'){ + setTBOOL8(false); + nRetVal += 1; + } + else{ + if(((pa_pacValue[0] == 'T') || (pa_pacValue[0] == 't')) && + ((pa_pacValue[1] == 'R') || (pa_pacValue[1] == 'r')) && + ((pa_pacValue[2] == 'U') || (pa_pacValue[2] == 'u')) && + ((pa_pacValue[3] == 'E') || (pa_pacValue[3] == 'e'))){ + setTBOOL8(true); + nRetVal += 4; + } + else{ + if(((pa_pacValue[0] == 'F') || (pa_pacValue[0] == 'f')) && + ((pa_pacValue[1] == 'A') || (pa_pacValue[1] == 'a')) && + ((pa_pacValue[2] == 'L') || (pa_pacValue[2] == 'l')) && + ((pa_pacValue[3] == 'S') || (pa_pacValue[3] == 's')) && + ((pa_pacValue[4] == 'E') || (pa_pacValue[4] == 'e'))){ + setTBOOL8(false); + nRetVal += 5; + } + else{ + nRetVal = -1; + } + } + } + } + return nRetVal; +} + +int CIEC_BOOL::toString(char* pa_acValue, unsigned int pa_nBufferSize) const { + int nRetval = -1; + if(pa_nBufferSize >= 6){ + if(getTBOOL8()){ + strcpy(pa_acValue, "TRUE"); + nRetval = 4; + } + else{ + strcpy(pa_acValue, "FALSE"); + nRetval = 5; + } + } + return nRetval; +} diff --git a/src/core/datatypes/forte_bool.h b/src/core/datatypes/forte_bool.h new file mode 100644 index 000000000..baa37b1a1 --- /dev/null +++ b/src/core/datatypes/forte_bool.h @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Martin Melik-Merkiumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_BOOL_H_ +#define _FORTE_BOOL_H_ + +#include "forte_any_bit.h" + +/*!\ingroup COREDTS CIEC_BOOL represents the bool data type according to IEC 61131. + */ +class CIEC_BOOL : public CIEC_ANY_BIT{ + DECLARE_FIRMWARE_DATATYPE(BOOL) + + public: + typedef bool TValueType; + + CIEC_BOOL(){ + setTBOOL8(false); + } + + CIEC_BOOL(const CIEC_BOOL& pa_rbValue) : CIEC_ANY_BIT() { + *this = pa_rbValue; + } + + CIEC_BOOL(bool pa_bValue){ + *this = pa_bValue; + } + + virtual ~CIEC_BOOL(){ + } + + /*! \brief Operator: CIEC_BOOL data type = bool data type + * + * This command implements the assignment operator for the IEC61131 datatype BOOL. + * The parameter value is a reference onto a given C++ variable (call by reference). + * \param pa_bValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_BOOL& operator =(bool pa_bValue){ + setTBOOL8(pa_bValue); + return *this; + } + + CIEC_BOOL& operator =(const CIEC_BOOL &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_BOOL to elementary bool + * + * Conversion operator for converting CIEC_BOOL to elementary bool + */ + operator bool() const{ + return (0 != getLargestUInt()); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_BOOL; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering systems. + * \param pa_pacValue Pointer to the provided buffer + * \param pa_nBufferSize Size of the provided buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; + + static const TForteUInt16 scm_unMaxStringBufSize; + + private: +}; + +#endif /*_FORTE_BOOL_H_*/ diff --git a/src/core/datatypes/forte_byte.cpp b/src/core/datatypes/forte_byte.cpp new file mode 100644 index 000000000..3465c3915 --- /dev/null +++ b/src/core/datatypes/forte_byte.cpp @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_byte.h" + +DEFINE_FIRMWARE_DATATYPE(BYTE, g_nStringIdBYTE) + +const TForteUInt16 CIEC_BYTE::scm_unMaxStringBufSize = 100; + +const CIEC_BYTE::TValueType CIEC_BYTE::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_byte.h b/src/core/datatypes/forte_byte.h new file mode 100644 index 000000000..c8643e207 --- /dev/null +++ b/src/core/datatypes/forte_byte.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Martin Melik-Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_BYTE_H_ +#define _FORTE_BYTE_H_ + +#include "forte_any_bit.h" +#include + +/*!\ingroup COREDTS CIEC_BYTE represents the byte data type according to IEC 61131. + */ +class CIEC_BYTE: public CIEC_ANY_BIT { + DECLARE_FIRMWARE_DATATYPE(BYTE) + + public: + typedef TForteByte TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_BYTE() { + } + + CIEC_BYTE(const CIEC_BYTE& pa_roValue) : CIEC_ANY_BIT() { + setValueSimple(pa_roValue); + } + + explicit CIEC_BYTE(TForteByte pa_cValue) { + setTUINT8(pa_cValue); + } + + virtual ~CIEC_BYTE() { + } + + /*! \brief Operator: CIEC_BYTE data type = CIEC_BYTE data type + * + * This command implements the assignment operator for the IEC61131 datatype BYTE. + * The parameter value is a reference onto a given C++ variable (call by reference). + * \param pa_rcValue Reference for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_BYTE& operator =(TForteByte pa_rcValue) { + setTUINT8(pa_rcValue); + return *this; + } + + CIEC_BYTE& operator =(const CIEC_BYTE &pa_roValue) { + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_BYTE to elementary byte + * + * Conversion operator for converting CIEC_BYTE to elementary byte + */ + operator TForteByte() const { + return getTUINT8(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_BYTE; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_BYTE_H_*/ diff --git a/src/core/datatypes/forte_date.cpp b/src/core/datatypes/forte_date.cpp new file mode 100644 index 000000000..e6a7c83ed --- /dev/null +++ b/src/core/datatypes/forte_date.cpp @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 nxtControl GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include +#include +#include +#include +#include "forte_date.h" +#include "../../arch/timerha.h" +#if defined(WINCE) +#include +#endif + +DEFINE_FIRMWARE_DATATYPE(DATE, g_nStringIdDATE) + +int CIEC_DATE::fromString(const char *pa_pacValue){ + // 2007-12-21 + struct tm tm; + char *acBuffer = const_cast(pa_pacValue); + + memset(&tm, 0, sizeof(tm)); + + if('d' == tolower(*acBuffer)){ + acBuffer++; + if(('a' == tolower(acBuffer[0])) && ('t' == tolower(acBuffer[1])) && ('e' == tolower(acBuffer[2]))){ + acBuffer += 3; + } + if('#' != *acBuffer){ + return -1; + } + acBuffer++; + } + + if('\0' != *acBuffer){ + //TODO think of using any elementary fromString function instead of strtoul + tm.tm_year = static_cast(::strtoul(acBuffer, &acBuffer, 10) - 1900); + if('-' == *acBuffer){ + ++acBuffer; + tm.tm_mon = static_cast(::strtoul(acBuffer, &acBuffer, 10) - 1); + if('-' == *acBuffer){ + ++acBuffer; + tm.tm_mday = static_cast(::strtoul(acBuffer, &acBuffer, 10)); + } + else{ + return -1; + } + } + else{ + return -1; + } + } + else{ + return -1; + } + + // If we are east of the UTC, adjust the time now - otherwise + // we might fall before time representable by time_t. Otherwise adjust + // after converting - it's easier than to step back in struct tm + TForteInt32 tzOffset = CIEC_ANY_DATE::getTimeZoneOffset(); + if (tzOffset > 0) { + tm.tm_hour = tzOffset / 60; + tm.tm_min = tzOffset % 60; + } + + if(!setDateAndTime(tm, 0)){ + return -1; + } + + if (tzOffset < 0){ + setTUINT64( getTUINT64() + (60*tzOffset * 1000ULL)); + } + return static_cast(acBuffer - pa_pacValue); +} + +int CIEC_DATE::toString(char* pa_pacValue, unsigned int pa_nBufferSize) const{ + int nRetVal = -1; + + struct tm *ptm = getTimeStruct(); + + if (ptm == 0) + return -1; + +#ifdef WIN32 + nRetVal = _snprintf(pa_pacValue, pa_nBufferSize, "%04d-%02d-%02d", 1900+ptm->tm_year, ptm->tm_mon+1, ptm->tm_mday); +#else + nRetVal = snprintf(pa_pacValue, pa_nBufferSize, "%04d-%02d-%02d", 1900 + ptm->tm_year, ptm->tm_mon + 1, ptm->tm_mday); +#endif + if((nRetVal < -1) || (nRetVal >= (int) pa_nBufferSize)){ + nRetVal = -1; + } + return nRetVal; +} diff --git a/src/core/datatypes/forte_date.h b/src/core/datatypes/forte_date.h new file mode 100644 index 000000000..a0f3b503a --- /dev/null +++ b/src/core/datatypes/forte_date.h @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2013 nxtControl GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl, Martin Melik Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_DATE_H_ +#define _FORTE_DATE_H_ + +#include "forte_any_date.h" + +#ifdef FORTE_USE_64BIT_DATATYPES + +/*!\ingroup COREDTS CIEC_DATE represents the time data types according to IEC 61131. + */ + +class CIEC_DATE : public CIEC_ANY_DATE{ + DECLARE_FIRMWARE_DATATYPE(DATE) + public: + typedef TForteUInt64 TValueType; + + CIEC_DATE(){ + } + + CIEC_DATE(const CIEC_DATE& pa_roValue) : + CIEC_ANY_DATE(){ + setValueSimple(pa_roValue); + } + + CIEC_DATE(TForteUInt64 pa_nValue){ + setTUINT64(pa_nValue); + } + + virtual ~CIEC_DATE(){ + } + + /*! \brief Operator: CIEC_DATE data type = long data type + * + * This command implements the assignment operator for the C++ datatype long long. + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_DATE& operator =(TForteUInt64 pa_nValue){ + setTUINT64(pa_nValue); + return *this; + } + + CIEC_DATE& operator =(const CIEC_DATE &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Operator: CIEC_TIME data type operator++ + * + * This command implements the increment operator for the IEC61131 datatype TIME. + * The parameter value is represented by a C++ variable (call by value). + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_DATE& operator ++(void){ + setTUINT64(getTUINT64() + 1); + return *this; + } + /*! \brief Converts CIEC_SINT to elementary 32 bit integer + * + * Conversion operator for converting CIEC_SINT to elementary 32 bit integer + */ + operator TForteUInt64() const{ + return getTUINT64(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_DATE; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the given String + * \return Can be the following response: + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the provided buffer + * \param pa_nBufferSize Size of the provided buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; +}; + +#endif /* #ifdef FORTE_USE_64BIT_DATATYPES */ + +#endif /*_FORTE_DATE_H_*/ diff --git a/src/core/datatypes/forte_date_and_time.cpp b/src/core/datatypes/forte_date_and_time.cpp new file mode 100644 index 000000000..c947021a2 --- /dev/null +++ b/src/core/datatypes/forte_date_and_time.cpp @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 nxtControl GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl, Martin Melik Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include +#include +#include +#include "forte_date_and_time.h" +#include "forte_date.h" +#include "forte_time_of_day.h" +#include "../../arch/timerha.h" + +DEFINE_FIRMWARE_DATATYPE(DATE_AND_TIME, g_nStringIdDATE_AND_TIME) + +int CIEC_DATE_AND_TIME::fromString(const char *pa_pacValue){ + // 2007-12-21-15:00:00.000 + int nRetVal = -1; + char *acBuffer = const_cast(pa_pacValue); + + if('d' == tolower(*acBuffer)){ + if('t' == tolower(acBuffer[1])){ + acBuffer += 2; + } + else{ + //TODO maybe allow to turn this check of for small devices + if((0 == strncmp("date_and_time", acBuffer, 13)) + || (0 == strncmp("DATE_AND_TIME", acBuffer, 13))){ + acBuffer += 13; + } + } + + if('#' != *acBuffer){ + return -1; + } + acBuffer++; + } + + struct tm tm; + unsigned int msec = 0; + + memset(&tm, 0, sizeof(tm)); + + //Duplicate code the same as in forte date + if('\0' != *acBuffer){ + tm.tm_year = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10) - 1900); + if('-' == *acBuffer){ + ++acBuffer; + tm.tm_mon = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10) - 1); + if('-' == *acBuffer){ + ++acBuffer; + tm.tm_mday = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10)); + + if('-' == *acBuffer){ + ++acBuffer; + //duplicate code this one can be find in time of day + tm.tm_hour = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10)); + if(':' == *acBuffer){ + ++acBuffer; + tm.tm_min = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10)); + if(':' == *acBuffer){ + ++acBuffer; + tm.tm_sec = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10)); + if('.' == *acBuffer){ + unsigned int nNums = 0; + ++acBuffer; + while(isdigit(*acBuffer)){ + msec = 10 * msec + forte::core::util::charDigitToInt(*acBuffer); + ++acBuffer; + ++nNums; + } + + if(nNums < 3){ + for(unsigned int i = nNums; i < 3; ++i) + msec *= 10; + } + else{ + for(unsigned int i = 0; i < (nNums - 3); ++i) + msec /= 10; + } + } + nRetVal = static_cast(acBuffer - pa_pacValue); + } + } + } + } + } + } + + if(-1 != nRetVal){ + if(!setDateAndTime(tm, msec)){ + nRetVal = -1; + } + } + + return nRetVal; +} + +int CIEC_DATE_AND_TIME::toString(char* pa_pacValue, unsigned int pa_nBufferSize) const{ + int nRetVal = -1; + + struct tm *ptm = getTimeStruct(); + + if(0 != ptm){ + +#ifdef WIN32 + nRetVal = _snprintf(pa_pacValue, pa_nBufferSize, "%04d-%02d-%02d-%02d:%02d:%02d.%03d", 1900+ptm->tm_year, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, getMilliSeconds()); +#else + nRetVal = + snprintf(pa_pacValue, pa_nBufferSize, "%04d-%02d-%02d-%02d:%02d:%02d.%03d", 1900 + + ptm->tm_year, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, getMilliSeconds()); +#endif + + if((nRetVal < -1) || (nRetVal >= (int) pa_nBufferSize)){ + nRetVal = -1; + } + } + return nRetVal; +} + +int CIEC_DATE_AND_TIME::toGMTString(char* pa_pacValue, unsigned int pa_nBufferSize) const{ + int nRetVal = -1; + + TForteUInt64 nToStringBuffer = getTUINT64(); + time_t t = static_cast(nToStringBuffer / 1000); +#if ! defined(WINCE) + struct tm *ptm = gmtime(&t); +#else + struct tm *ptm = wceex_gmtime(&t); + + if (ptm == 0) + return -1; + +#endif +#ifdef WIN32 + nRetVal = _snprintf(pa_pacValue, pa_nBufferSize, "%04d-%02d-%02d-%02d:%02d:%02d.%03d", 1900+ptm->tm_year, ptm->tm_mon+1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int) (nToStringBuffer % 1000)); +#else + nRetVal = + snprintf(pa_pacValue, pa_nBufferSize, "%04d-%02d-%02d-%02d:%02d:%02d.%03d", 1900 + + ptm->tm_year, ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, ptm->tm_sec, (int) (nToStringBuffer + % 1000)); +#endif + + if((nRetVal < -1) || (nRetVal >= (int) pa_nBufferSize)){ + nRetVal = -1; + } + return nRetVal; +} + diff --git a/src/core/datatypes/forte_date_and_time.h b/src/core/datatypes/forte_date_and_time.h new file mode 100644 index 000000000..71eb83ff4 --- /dev/null +++ b/src/core/datatypes/forte_date_and_time.h @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2013 nxtControl GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl, Martin Melik Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_DATE_AND_TIME_H_ +#define _FORTE_DATE_AND_TIME_H_ + +#include "forte_any_date.h" +#include +#if defined(WINCE) +#include +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +/*!\ingroup COREDTS CIEC_DATE_AND_TIME represents the time data types according to IEC 61131. + */ + +class CIEC_DATE_AND_TIME : public CIEC_ANY_DATE { + DECLARE_FIRMWARE_DATATYPE(DATE_AND_TIME) + public: + typedef TForteUInt64 TValueType; + + CIEC_DATE_AND_TIME() { } + + CIEC_DATE_AND_TIME(const CIEC_DATE_AND_TIME& pa_roValue) : CIEC_ANY_DATE() { + setValueSimple(pa_roValue); + } + + CIEC_DATE_AND_TIME(TForteUInt64 pa_nValue) { + setTUINT64(pa_nValue); + } + + virtual ~CIEC_DATE_AND_TIME() {} + + /*! \brief Operator: CIEC_DATE_AND_TIME data type = long data type + * + * This command implements the assignment operator for the C++ datatype long long. + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_DATE_AND_TIME& operator = (TForteUInt64 pa_nValue) { + setTUINT64(pa_nValue); + return *this; + } + + CIEC_DATE_AND_TIME& operator = (const CIEC_DATE_AND_TIME &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Operator: CIEC_TIME data type operator++ + * + * This command implements the increment operator for the IEC61131 data type TIME. + * The parameter value is represented by a C++ variable (call by value). + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_DATE_AND_TIME& operator ++ (void) { + setTUINT64(getTUINT64()+1); + return *this; + } + /*! \brief Converts CIEC_SINT to elementary 32 bit integer + * + * Conversion operator for converting CIEC_SINT to elementary 32 bit integer + */ + operator TForteUInt64 () const { return getTUINT64(); } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_DATE_AND_TIME; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the given String + * \return Can be the following response: + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + /*! \brief Converts data type value to string - use local time + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the provided buffer + * \param pa_nBufferSize Size of the provided buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const ; + + /*! \brief Converts data type value to string - use GMT time + * \param pa_pacValue Pointer to the provided buffer + * \param pa_nBufferSize Size of the provided buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toGMTString(char* pa_pacValue, unsigned int pa_nBufferSize) const ; + + /*! \brief Set the variable to current time + */ + void setCurrentTime(){ + #if ! defined(WINCE) + setTUINT64(time(0) * 1000ULL); + #else + setTUINT64(wceex_time(0) * 1000ULL); + #endif + }; +}; + +#endif /* #ifdef FORTE_USE_64BIT_DATATYPES */ + +#endif /*_MTIME_H_*/ diff --git a/src/core/datatypes/forte_dint.cpp b/src/core/datatypes/forte_dint.cpp new file mode 100644 index 000000000..319f305ab --- /dev/null +++ b/src/core/datatypes/forte_dint.cpp @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Ingo Hegny, Monika Wenger, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_dint.h" + +DEFINE_FIRMWARE_DATATYPE(DINT, g_nStringIdDINT) + +const TForteUInt16 CIEC_DINT::scm_unMaxStringBufSize = 100; + +const CIEC_DINT::TValueType CIEC_DINT::scm_nMinVal = std::numeric_limits::min(); +const CIEC_DINT::TValueType CIEC_DINT::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_dint.h b/src/core/datatypes/forte_dint.h new file mode 100644 index 000000000..6224e1c85 --- /dev/null +++ b/src/core/datatypes/forte_dint.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_DINT_H_ +#define _FORTE_DINT_H_ + +#include "forte_any_int.h" +#include + +/*!\ingroup COREDTS CIEC_DINT represents the dint data type according to IEC 61131. + */ +class CIEC_DINT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(DINT) + + public: + typedef TForteInt32 TValueType; + + static const TValueType scm_nMinVal; + static const TValueType scm_nMaxVal; + + CIEC_DINT(){ + } + + CIEC_DINT(const CIEC_DINT& pa_roValue) : CIEC_ANY_INT() { + setValueSimple(pa_roValue); + } + + CIEC_DINT(TForteInt32 pa_nValue){ + setTINT32(pa_nValue); + } + + virtual ~CIEC_DINT(){ + } + + /*! \brief Operator: CIEC_DINT data type = long data type + * + * This command implements the assignment operator for the C++ datatype LONG. + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_DINT& operator =(TForteInt32 pa_nValue){ + setTINT32(pa_nValue); + return *this; + } + + CIEC_DINT& operator =(const CIEC_DINT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_DINT to elementary byte + * + * Conversion operator for converting CIEC_DINT to elementary 32 bit integer + */ + operator TForteInt32() const{ + return getTINT32(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_DINT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_DINT_H_*/ diff --git a/src/core/datatypes/forte_dword.cpp b/src/core/datatypes/forte_dword.cpp new file mode 100644 index 000000000..1d9c3ced5 --- /dev/null +++ b/src/core/datatypes/forte_dword.cpp @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_dword.h" + +DEFINE_FIRMWARE_DATATYPE(DWORD, g_nStringIdDWORD) + +const TForteUInt16 CIEC_DWORD::scm_unMaxStringBufSize = 100; + +const CIEC_DWORD::TValueType CIEC_DWORD::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_dword.h b/src/core/datatypes/forte_dword.h new file mode 100644 index 000000000..a82627644 --- /dev/null +++ b/src/core/datatypes/forte_dword.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_DWORD_H_ +#define _FORTE_DWORD_H_ + +#include "forte_any_bit.h" +#include + +/*!\ingroup COREDTS CIEC_DWORD represents the dword data type according to IEC 61131. + */ +class CIEC_DWORD : public CIEC_ANY_BIT{ + DECLARE_FIRMWARE_DATATYPE(DWORD) + + public: + typedef TForteDWord TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_DWORD(){ + } + + CIEC_DWORD(const CIEC_DWORD& pa_roValue) : CIEC_ANY_BIT(){ + setValueSimple(pa_roValue); + } + + CIEC_DWORD(TForteDWord pa_cValue){ + setTUINT32(pa_cValue); + } + + virtual ~CIEC_DWORD(){ + } + + /*! \brief Operator: CIEC_DWORD data type = long data type + * + * This command implements the assignment operator for the C++ datatype UNSIGNED LONG + * The parameter value is represented by a C++ variable (call by value). + * \param pa_cValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_DWORD& operator =(TForteDWord pa_cValue){ + setTUINT32(pa_cValue); + return *this; + } + + CIEC_DWORD& operator =(const CIEC_DWORD &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_DWORD to elementary word + * + * Conversion operator for converting CIEC_DWORD to elementary word + */ + operator TForteDWord() const{ + return getTUINT32(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_DWORD; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_DWORD_H_*/ diff --git a/src/core/datatypes/forte_int.cpp b/src/core/datatypes/forte_int.cpp new file mode 100644 index 000000000..e9c6e9e5c --- /dev/null +++ b/src/core/datatypes/forte_int.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_int.h" + +DEFINE_FIRMWARE_DATATYPE(INT, g_nStringIdINT) + +const TForteUInt16 CIEC_INT::scm_unMaxStringBufSize = 100; + +const CIEC_INT::TValueType CIEC_INT::scm_nMinVal = std::numeric_limits::min(); +const CIEC_INT::TValueType CIEC_INT::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_int.h b/src/core/datatypes/forte_int.h new file mode 100644 index 000000000..7430b0ce0 --- /dev/null +++ b/src/core/datatypes/forte_int.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_INT_H_ +#define _FORTE_INT_H_ + +#include "forte_any_int.h" +#include + +/*!\ingroup COREDTS CIEC_INT represents the int data type according to IEC 61131. + */ +class CIEC_INT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(INT) + + public: + typedef TForteInt16 TValueType; + + static const TValueType scm_nMinVal; + static const TValueType scm_nMaxVal; + + CIEC_INT(){ + } + + CIEC_INT(const CIEC_INT& pa_roValue) : + CIEC_ANY_INT(){ + setValueSimple(pa_roValue); + } + + CIEC_INT(TForteInt16 pa_nValue){ + setTINT16(pa_nValue); + } + + virtual ~CIEC_INT(){ + } + + /*! \brief Operator: CIEC_INT data type = short data type + * + * This command implements the assignment operator for the C++ datatype SHORT + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_INT& operator =(TForteInt16 pa_nValue){ + setTINT16(pa_nValue); + return *this; + } + + CIEC_INT& operator =(const CIEC_INT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_INT to elementary 16 bit integer + * + * Conversion operator for converting CIEC_INT to elementary 16 bit integer + */ + operator TForteInt16() const{ + return getTINT16(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_INT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_INT_H_*/ diff --git a/src/core/datatypes/forte_lint.cpp b/src/core/datatypes/forte_lint.cpp new file mode 100644 index 000000000..5f613913e --- /dev/null +++ b/src/core/datatypes/forte_lint.cpp @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_lint.h" + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_DATATYPE(LINT, g_nStringIdLINT); + +const TForteUInt16 CIEC_LINT::scm_unMaxStringBufSize = 100; + +const CIEC_LINT::TValueType CIEC_LINT::scm_nMinVal = std::numeric_limits::min(); +const CIEC_LINT::TValueType CIEC_LINT::scm_nMaxVal = std::numeric_limits::max(); + +#endif diff --git a/src/core/datatypes/forte_lint.h b/src/core/datatypes/forte_lint.h new file mode 100644 index 000000000..6110e754d --- /dev/null +++ b/src/core/datatypes/forte_lint.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_LINT_H_ +#define _FORTE_LINT_H_ + +#include "forte_any_int.h" +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +/*!\ingroup COREDTS CIEC_LINT represents the dint data type according to IEC 61131. + */ +class CIEC_LINT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(LINT) + + public: + typedef TForteInt64 TValueType; + + static const TValueType scm_nMinVal; + static const TValueType scm_nMaxVal; + + CIEC_LINT(){ + } + + CIEC_LINT(const CIEC_LINT& pa_roValue) : + CIEC_ANY_INT(){ + setValueSimple(pa_roValue); + } + + CIEC_LINT(TForteInt64 pa_nValue){ + setTINT64(pa_nValue); + } + + virtual ~CIEC_LINT(){ + } + + /*! \brief Operator: CIEC_LINT data type = long data type + * + * This command implements the assignment operator for the C++ datatype LONG. + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_LINT& operator =(TForteInt64 pa_nValue){ + setTINT64(pa_nValue); + return *this; + } + + CIEC_LINT& operator =(const CIEC_LINT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_LINT to elementary byte + * + * Conversion operator for converting CIEC_LINT to elementary 64 bit integer + */ + operator TForteInt64() const{ + return getTINT64(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_LINT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif +#endif /*_FORTE_LINT_H_*/ diff --git a/src/core/datatypes/forte_lreal.cpp b/src/core/datatypes/forte_lreal.cpp new file mode 100644 index 000000000..77febe357 --- /dev/null +++ b/src/core/datatypes/forte_lreal.cpp @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, + * Ingo Hegny, Martin Melik Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include +#include +#include +#include "forte_lreal.h" + +#include "forte_real.h" +#include "forte_string.h" +#include "forte_wstring.h" + +#ifdef FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_DATATYPE(LREAL, g_nStringIdLREAL) + +const TForteUInt16 CIEC_LREAL::scm_unMaxStringBufSize = 100; + +int CIEC_LREAL::fromString(const char *pa_pacValue){ + char *pcEnd; + const char *pacRunner = pa_pacValue; + double realval = 0.0; + + if(0 == strncmp(pacRunner, "LREAL#", 6)){ + pacRunner += 6; + } + + errno = 0; + realval = strtod(pacRunner, &pcEnd); + + if((errno != 0) || (pacRunner == pcEnd)){ + return -1; + } + setTDFLOAT((TForteDFloat) realval); + return static_cast(pcEnd - pa_pacValue); +} + +int CIEC_LREAL::toString(char* pa_pacValue, unsigned int pa_nBufferSize) const{ + int nRetVal = -1; +#ifdef WIN32 + nRetVal = _snprintf(pa_pacValue, pa_nBufferSize, "%.*g", 15, getTDFLOAT()); +#else + nRetVal = snprintf(pa_pacValue, pa_nBufferSize, "%.*g", 15, getTDFLOAT()); +#endif + + if((nRetVal < -1) || (nRetVal >= (int) pa_nBufferSize)){ + nRetVal = -1; + } + return nRetVal; +} + +void CIEC_LREAL::setValue(const CIEC_ANY& pa_roValue){ + EDataTypeID eID = pa_roValue.getDataTypeID(); + switch (eID){ + case e_LREAL: + setValueSimple(pa_roValue); + break; + case e_REAL: + (*this) = (((CIEC_REAL &) pa_roValue)).operator TForteFloat(); + break; + case e_STRING: + (*this).fromString(((CIEC_STRING&) pa_roValue).getValue()); + break; + case e_WSTRING: + (*this).fromString(((CIEC_WSTRING&) pa_roValue).getValue()); + break; + case e_SINT: + case e_INT: + case e_DINT: + case e_LINT: + (*this) = static_cast(*((CIEC_ANY::TLargestIntValueType *) pa_roValue.getConstDataPtr())); + break; + default: + (*this) = static_cast(*((CIEC_ANY::TLargestUIntValueType *) pa_roValue.getConstDataPtr())); + break; + } +} + +void CIEC_LREAL::castLRealData(const CIEC_LREAL &pa_roSrcValue, CIEC_ANY &pa_roDestValue){ + switch (pa_roDestValue.getDataTypeID()){ + case CIEC_ANY::e_REAL: + static_cast(pa_roDestValue) = static_cast(pa_roSrcValue); + break; + case CIEC_ANY::e_LREAL: + static_cast(pa_roDestValue) = pa_roSrcValue; + break; + case CIEC_ANY::e_BYTE: + case CIEC_ANY::e_WORD: + case CIEC_ANY::e_DWORD: + case CIEC_ANY::e_LWORD: + // bit string will cast to the binary representation of the real value + pa_roDestValue.setValue(pa_roSrcValue); + break; + case CIEC_ANY::e_BOOL: //bool works better when treated as signed so that negative numbers will be treated as true to + case CIEC_ANY::e_SINT: + case CIEC_ANY::e_INT: + case CIEC_ANY::e_DINT: + case CIEC_ANY::e_LINT: + *((CIEC_ANY::TLargestIntValueType *) pa_roDestValue.getDataPtr()) = static_cast(pa_roSrcValue); + break; + default: + //TODO maybe we should check for destination id to be in valid range (i.e., any_bit, any_unsigned_int, and time) + //should not be necessary because of connect function, but who knows. + *((CIEC_ANY::TLargestUIntValueType *) pa_roDestValue.getDataPtr()) = static_cast(pa_roSrcValue); + break; + } +} + +#endif //FORTE_USE_64BIT_DATATYPES +#endif //FORTE_USE_REAL_DATATYPE diff --git a/src/core/datatypes/forte_lreal.h b/src/core/datatypes/forte_lreal.h new file mode 100644 index 000000000..53cf1d29d --- /dev/null +++ b/src/core/datatypes/forte_lreal.h @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, + * Ingo Hegny, Monika Wenger, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_LREAL_H_ +#define _FORTE_LREAL_H_ + +#include "forte_any_real.h" + +#ifdef FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + +/*!\ingroup COREDTS CIEC_LREAL represents the lreal data type according to IEC 61131. + */ +class CIEC_LREAL : public CIEC_ANY_REAL{ + DECLARE_FIRMWARE_DATATYPE(LREAL) + + public: + typedef TForteDFloat TValueType; + + CIEC_LREAL(){ + } + + CIEC_LREAL(const CIEC_LREAL& pa_roValue) : + CIEC_ANY_REAL(){ + setValueSimple(pa_roValue); + } + + CIEC_LREAL(TForteDFloat pa_fValue){ + setTDFLOAT(pa_fValue); + } + + virtual ~CIEC_LREAL(){ + } + + /*! \brief Operator: CIEC_LREAL data type = CIEC_LREAL data type + * + * This command implements the assignment operator for the C++ datatype DFLOAT. + * The parameter value is represented by a C++ variable (call by value). + * \param pa_fValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_LREAL& operator =(TForteDFloat pa_fValue){ + setTDFLOAT(pa_fValue); + return *this; + } + + CIEC_LREAL& operator =(const CIEC_LREAL &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_LREAL to elementary 64 bit float + * + * Conversion operator for converting CIEC_LREAL to elementary 64 bit float + */ + + operator TForteDFloat() const{ + return getTDFLOAT(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_LREAL; + } + + virtual void setValue(const CIEC_ANY& pa_roValue); + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the buffer String + * \param pa_nBufferSize size of the buffer thats available for this function + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; + + /*! \brief Casts TForteDFloat values to CIEC data types + * \param pa_roSrcValue Source value for the cast + * \param pa_roDestValue Destination CIEC object of the cast + */ + static void castLRealData(const CIEC_LREAL &pa_roSrcValue, CIEC_ANY &pa_roDestValue); + + static const TForteUInt16 scm_unMaxStringBufSize; + + protected: + + private: + /*! \brief bit distortion extension for serialization function - 64 bit values. + * \param pa_pcBytes Pointer to first part of original object. + * \param pa_nValue Pointer to the modified object + * \return Can be the following response: + * - No return value. + */ + static void serializedouble(TForteByte* pa_pcBytes, TForteUInt64 pa_nValue){ + pa_pcBytes[0] = (TForteByte) ((pa_nValue >> 56) & 0x00FF); + pa_pcBytes[1] = (TForteByte) ((pa_nValue >> 48) & 0x00FF); + pa_pcBytes[2] = (TForteByte) ((pa_nValue >> 40) & 0x00FF); + pa_pcBytes[3] = (TForteByte) ((pa_nValue >> 32) & 0x00FF); + pa_pcBytes[4] = (TForteByte) ((pa_nValue >> 24) & 0x00FF); + pa_pcBytes[5] = (TForteByte) ((pa_nValue >> 16) & 0x00FF); + pa_pcBytes[6] = (TForteByte) ((pa_nValue >> 8) & 0x00FF); + pa_pcBytes[7] = (TForteByte) (pa_nValue & 0x00FF); + } + ; + /*! \brief bit distortion extension for deserialization function - 64 bit values. + * \param pa_pcBytes Pointer to first part of final object. + * \param pa_nValue Pointer to the modified object + * \return Can be the following response: + * - No return value. + */ + static void deserializedouble(const TForteByte* pa_pcBytes, TForteUInt64* pa_nValue){ + *pa_nValue = ((((TForteUInt64) pa_pcBytes[0]) << 56) & 0xFF00000000000000ULL) + ((((TForteUInt64) pa_pcBytes[1]) << 48) & 0x00FF000000000000ULL) + ((((TForteUInt64) pa_pcBytes[2]) << 40) & 0x0000FF0000000000ULL) + ((((TForteUInt64) pa_pcBytes[3]) << 32) & 0x000000FF00000000ULL) + ((((TForteUInt64) pa_pcBytes[4]) << 24) & 0x00000000FF000000ULL) + ((((TForteUInt64) pa_pcBytes[5]) << 16) & 0x0000000000FF0000ULL) + ((((TForteUInt64) pa_pcBytes[6]) << 8) & 0x000000000000FF00ULL) + ((TForteUInt64) pa_pcBytes[7] & 0x00000000000000FFULL); + } + ; + +}; + +#endif /* #ifdef FORTE_USE_64BIT_DATATYPES */ + +#endif /* #ifdef FORTE_USE_REAL_DATATYPE */ + +#endif /*_FORTE_LREAL_H_*/ diff --git a/src/core/datatypes/forte_lword.cpp b/src/core/datatypes/forte_lword.cpp new file mode 100644 index 000000000..6b87daf34 --- /dev/null +++ b/src/core/datatypes/forte_lword.cpp @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkiumians, Alois Zoitl, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_lword.h" + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_DATATYPE(LWORD, g_nStringIdLWORD) + +const TForteUInt16 CIEC_LWORD::scm_unMaxStringBufSize = 100; + +const CIEC_LWORD::TValueType CIEC_LWORD::scm_nMaxVal = std::numeric_limits::max(); + +#endif diff --git a/src/core/datatypes/forte_lword.h b/src/core/datatypes/forte_lword.h new file mode 100644 index 000000000..124cdaf34 --- /dev/null +++ b/src/core/datatypes/forte_lword.h @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkiumians, Alois Zoitl, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_LWORD_H_ +#define _FORTE_LWORD_H_ + +#include "forte_any_bit.h" +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +/*!\ingroup COREDTS CIEC_DWORD represents the dword data type according to IEC 61131. + */ + +class CIEC_LWORD : public CIEC_ANY_BIT{ + DECLARE_FIRMWARE_DATATYPE(LWORD) + + public: + typedef TForteLWord TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_LWORD(){ + } + + CIEC_LWORD(const CIEC_LWORD& pa_roValue) : + CIEC_ANY_BIT(){ + setValueSimple(pa_roValue); + } + + CIEC_LWORD(TForteLWord pa_cValue){ + setTUINT64(pa_cValue); + } + virtual ~CIEC_LWORD(){ + } + + /*! \brief Operator: CIEC_LWORD data type = long data type + * + * This command implements the assignment operator for the C++ datatype UNSIGNED LONG LONG + * The parameter value is represented by a C++ variable (call by value). + * \param pa_cValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_LWORD& operator =(TForteLWord pa_cValue){ + setTUINT64(pa_cValue); + return *this; + } + + CIEC_LWORD& operator =(const CIEC_LWORD &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_LWORD to elementary word + * + * Conversion operator for converting CIEC_LWORD to elementary word + */ + operator TForteLWord() const{ + return getTUINT64(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_LWORD; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif + +#endif /*_FORTE_LWORD_H_*/ diff --git a/src/core/datatypes/forte_real.cpp b/src/core/datatypes/forte_real.cpp new file mode 100644 index 000000000..a7a957861 --- /dev/null +++ b/src/core/datatypes/forte_real.cpp @@ -0,0 +1,131 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, + * Ingo Hegny, Martin Melik Merkumians, Monika Wenger, Stanislav Meduna, + * Matthias Plasch + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include +#include +#include "forte_real.h" +#include "forte_lreal.h" + +#ifdef FORTE_USE_REAL_DATATYPE + +DEFINE_FIRMWARE_DATATYPE(REAL, g_nStringIdREAL) + +const TForteUInt16 CIEC_REAL::scm_unMaxStringBufSize = 100; + +int CIEC_REAL::fromString(const char *pa_pacValue){ + char *pcEnd; + const char *pacRunner = pa_pacValue; + TForteFloat realval = 0.0; + const TForteFloat TFLOAT_min = 3.4e-38f; // lower precision boundary + const TForteFloat TFLOAT_max = 3.4e38f; // upper precision boundary + + if(0 == strncmp(pacRunner, "REAL#", 5)){ + pacRunner += 5; + } + + + #if defined(WIN32) || defined(__ECOS) || defined(VXWORKS) + realval = strtod(pacRunner, &pcEnd); + #else + realval = strtof(pacRunner, &pcEnd); + #endif + + if(((fabs(realval) < TFLOAT_min) && (realval != 0)) || ((fabs(realval) > TFLOAT_max) && (realval != 0)) || + (pacRunner == pcEnd)) + return -1; + + setTFLOAT((TForteFloat) realval); + return static_cast(pcEnd - pa_pacValue); +} + +int CIEC_REAL::toString(char* pa_acValue, unsigned int pa_nBufferSize) const{ + int nRetVal; + +#ifdef WIN32 + nRetVal = _snprintf(pa_acValue, pa_nBufferSize, "%g", getTFLOAT()); +#else + nRetVal = snprintf(pa_acValue, pa_nBufferSize, "%g", getTFLOAT()); +#endif + + if((nRetVal < -1) || (nRetVal >= (int) pa_nBufferSize)){ + nRetVal = -1; + } + return nRetVal; +} + +void CIEC_REAL::setValue(const CIEC_ANY& pa_roValue){ + EDataTypeID eID = pa_roValue.getDataTypeID(); + switch (eID) { + case e_REAL: + setValueSimple(pa_roValue); + break; +#ifdef FORTE_USE_64BIT_DATATYPES + case e_LREAL: + (*this)=static_cast((CIEC_LREAL&)(pa_roValue)); + break; +#endif + case e_STRING: + (*this).fromString(((CIEC_STRING&)pa_roValue).getValue()); + break; + case e_WSTRING: + (*this).fromString(((CIEC_WSTRING&)pa_roValue).getValue()); + break; + case e_SINT: + case e_INT: + case e_DINT: + case e_LINT: + (*this) = static_cast(*((CIEC_ANY::TLargestIntValueType *) pa_roValue.getConstDataPtr())); + break; + default: + (*this) = static_cast(*((CIEC_ANY::TLargestUIntValueType *) pa_roValue.getConstDataPtr())); + break; + } +} + +void CIEC_REAL::castRealData(const CIEC_REAL &pa_roSrcValue, CIEC_ANY &pa_roDestValue){ + switch(pa_roDestValue.getDataTypeID()){ + case CIEC_ANY::e_REAL: + static_cast(pa_roDestValue) = pa_roSrcValue; + break; + case CIEC_ANY::e_LREAL: +#ifdef FORTE_USE_64BIT_DATATYPES + static_cast(pa_roDestValue) = pa_roSrcValue; +#endif + break; + case CIEC_ANY::e_BYTE: + case CIEC_ANY::e_WORD: + case CIEC_ANY::e_DWORD: + case CIEC_ANY::e_LWORD: + // bit string will cast to the binary representation of the real value + pa_roDestValue.setValue(pa_roSrcValue); + break; + case CIEC_ANY::e_BOOL: //bool works better when treated as signed so that negative numbers will be treated as true to + case CIEC_ANY::e_SINT: + case CIEC_ANY::e_INT: + case CIEC_ANY::e_DINT: + case CIEC_ANY::e_LINT: + *((CIEC_ANY::TLargestIntValueType *) pa_roDestValue.getDataPtr()) = static_cast(pa_roSrcValue); + break; + default: + //TODO maybe we should check for destination id to be in valid range (i.e., any_bit, any_unsigned_int, and time) + //should not be necessary because of connect function, but who knows. + *((CIEC_ANY::TLargestUIntValueType *) pa_roDestValue.getDataPtr()) = static_cast(pa_roSrcValue); + break; + } +} + +#endif //FORTE_USE_REAL_DATATYPE + + diff --git a/src/core/datatypes/forte_real.h b/src/core/datatypes/forte_real.h new file mode 100644 index 000000000..d8f38eeb4 --- /dev/null +++ b/src/core/datatypes/forte_real.h @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Pr3factor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Martin Melik Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_REAL_H_ +#define _FORTE_REAL_H_ + +#include "forte_any_real.h" + +#ifdef FORTE_USE_REAL_DATATYPE + +#include "forte_string.h" +#include "forte_wstring.h" + +/*!\ingroup COREDTS CIEC_REAL represents the real data type according to IEC 61131. + */ +class CIEC_REAL : public CIEC_ANY_REAL{ + DECLARE_FIRMWARE_DATATYPE(REAL) + + public: + typedef TForteFloat TValueType; + + CIEC_REAL(){ + } + + CIEC_REAL(const CIEC_REAL& pa_roValue) : + CIEC_ANY_REAL(){ + setValueSimple(pa_roValue); + } + + CIEC_REAL(TForteFloat pa_fValue){ + setTFLOAT(pa_fValue); + } + + virtual ~CIEC_REAL(){ + } + + /*! \brief Operator: CIEC_REAL data type = float data type + * + * This command implements the assignment operator for the C++ datatype FLOAT. + * The parameter value is represented by a C++ variable (call by value). + * \param pa_fValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_REAL& operator =(TForteFloat pa_fValue){ + setTFLOAT(pa_fValue); + return *this; + } + ; + + CIEC_REAL& operator =(const CIEC_REAL &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_REAL to elementary 32 bit float + * + * Conversion operator for converting CIEC_REAL to elementary 32 bit float + */ + operator TForteFloat() const{ + return getTFLOAT(); + } + + virtual void setValue(const CIEC_ANY& pa_roValue); + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_REAL; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the buffer String + * \param pa_nBufferSize size of the buffer thats available for this function + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; + + /*! \brief Casts TForteFloat values to CIEC data types + * \param pa_roSrcValue Source value for the cast + * \param pa_roDestValue Destination CIEC object of the cast + */ + static void castRealData(const CIEC_REAL &pa_roSrcValue, CIEC_ANY &pa_roDestValue); + + static const TForteUInt16 scm_unMaxStringBufSize; + +}; + +#endif /* #ifdef FORTE_USE_REAL_DATATYPE */ + +#endif /*_FORTE_REAL_H_*/ diff --git a/src/core/datatypes/forte_sint.cpp b/src/core/datatypes/forte_sint.cpp new file mode 100644 index 000000000..8ac1e29e4 --- /dev/null +++ b/src/core/datatypes/forte_sint.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_sint.h" + +DEFINE_FIRMWARE_DATATYPE(SINT, g_nStringIdSINT) + +const TForteUInt16 CIEC_SINT::scm_unMaxStringBufSize = 100; + +const CIEC_SINT::TValueType CIEC_SINT::scm_nMinVal = std::numeric_limits::min(); +const CIEC_SINT::TValueType CIEC_SINT::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_sint.h b/src/core/datatypes/forte_sint.h new file mode 100644 index 000000000..7a9a2a4c3 --- /dev/null +++ b/src/core/datatypes/forte_sint.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_SINT_H_ +#define _FORTE_SINT_H_ + +#include "forte_any_int.h" +#include + +/*!\ingroup COREDTS CIEC_SINT represents the sint data type according to IEC 61131. + */ +class CIEC_SINT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(SINT) + + public: + typedef TForteInt8 TValueType; + + static const TValueType scm_nMinVal; + static const TValueType scm_nMaxVal; + + CIEC_SINT(){ + } + + CIEC_SINT(const CIEC_SINT& pa_roValue) : + CIEC_ANY_INT(){ + setValueSimple(pa_roValue); + } + + CIEC_SINT(TForteInt8 pa_nValue){ + setTINT8(pa_nValue); + } + + virtual ~CIEC_SINT(){ + } + + /*! \brief Operator: CIEC_SINT data type = char data type + * + * This command implements the assignment operator for the C++ datatype CHAR + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_SINT& operator =(TForteInt8 pa_nValue){ + setTINT8(pa_nValue); + return *this; + } + + CIEC_SINT& operator =(const CIEC_SINT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_SINT to elementary 8 bit integer + * + * Conversion operator for converting CIEC_SINT to elementary 8 bit integer + */ + operator TForteInt8() const{ + return getTINT8(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_SINT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_SINT_H_*/ diff --git a/src/core/datatypes/forte_string.cpp b/src/core/datatypes/forte_string.cpp new file mode 100644 index 000000000..aa1e28802 --- /dev/null +++ b/src/core/datatypes/forte_string.cpp @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Rene Smodic, Alois Zoitl, + * Ingo Hegny, Martin Meik Merkumians, Stanislav Meduna + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_string.h" +#include +#include "forte_uint.h" +#include "unicode_utils.h" + +DEFINE_FIRMWARE_DATATYPE(STRING, g_nStringIdSTRING); + +int CIEC_STRING::fromString(const char *pa_pacValue){ + int nSrcLen = determineEscapedStringLength(pa_pacValue, '\''); + int nSrcCappedLength = nSrcLen; + + if(0 < nSrcLen){ + if((nSrcLen >= 7) && (0 == strncmp(pa_pacValue, "STRING#", 7))){ + pa_pacValue += 7; + nSrcCappedLength -= 7; + } + + if (nSrcLen > scm_unMaxStringLen) + nSrcCappedLength = scm_unMaxStringLen; + + + if (*pa_pacValue == '\'') { + reserve(static_cast(nSrcCappedLength)); + if (unescapeFromString(pa_pacValue, '\'') < 0) + return -1; + } else { + assign(pa_pacValue, static_cast(nSrcCappedLength)); + } + } + + return nSrcLen; +} + +int CIEC_STRING::toString(char* pa_acValue, unsigned int pa_nBufferSize) const { + int nRetVal = -1; + if(static_cast(length() + 2) < pa_nBufferSize){ //add 2 for the leading and closing ' + *pa_acValue = '\''; + pa_acValue++; + TForteUInt16 nLen = length(); + int nUsedBytes = 0; + pa_nBufferSize -= 2; + if(0 < nLen){ + const char * acValue = getValue(); + for(unsigned int i = 0; i < nLen; ++i){ + if(static_cast(nUsedBytes) >= pa_nBufferSize){ + return -1; + } + nUsedBytes += dollarEscapeChar(pa_acValue+nUsedBytes, acValue[i], 2); + } + + } else{ + *pa_acValue = '\0'; + } + nRetVal = nUsedBytes; + pa_acValue[nRetVal] = '\''; + pa_acValue[nRetVal + 1] = '\0'; + } + return nRetVal + 2; +} + +#ifdef FORTE_UNICODE_SUPPORT +int CIEC_STRING::fromUTF8(const char *pa_pacValue, int pa_nLen, bool pa_bUnescape) { + unsigned int nMaxWidth; + + int nSrcLen = pa_nLen >= 0 ? pa_nLen : (pa_bUnescape ? determineEscapedStringLength(pa_pacValue, '\'') : strlen(pa_pacValue)); + int nSrcCappedLength = nSrcLen; + + if(0 <= nSrcLen){ + if (nSrcLen == 0) { + assign("", 0); + return 0; + } + + if (nSrcLen > static_cast(scm_unMaxStringLen)) { + // If we get a to large string we will truncate it + // This is a conservative guess + nSrcCappedLength = scm_unMaxStringLen; + DEVLOG_WARNING("Too large string, destination will be truncated!\n"); + } + + int nLength = CUnicodeUtilities::checkUTF8(pa_pacValue, nSrcCappedLength, nMaxWidth); + if (nLength < 0) { + DEVLOG_WARNING("Invalid UTF-8 string given to fromString!\n"); + *this = "***INVALID UTF-8***"; + return -1; + } else if (nMaxWidth > 8) { + DEVLOG_WARNING("UTF-8 string with non-representable characters given to fromString!\n"); + } + + reserve(static_cast(nLength)); + if (0 == getGenData()) + return -1; + + TForteUInt32 nCodepoint; + const char *pRunner = pa_pacValue; + TForteByte *pEncBuffer = (TForteByte *) getValue(); + TForteByte *pEncRunner = pEncBuffer; + + while (*pRunner && (pRunner-pa_pacValue) < nSrcCappedLength && (pEncRunner-pEncBuffer) < nLength) { + int nRes; + nRes = CUnicodeUtilities::parseUTF8Codepoint((const TForteByte *) pRunner, nCodepoint); + pRunner += nRes; + if (nCodepoint == CUnicodeUtilities::scm_unBOMMarker) + continue; + if (nCodepoint >= 0x100) + nCodepoint = '?'; + *pEncRunner++ = (TForteByte) nCodepoint; + } + + *pEncRunner = '\0'; + setLength(static_cast(pEncRunner - pEncBuffer)); + + if (pa_bUnescape) { + nLength = unescapeFromString(getValue(), '\''); + if (nLength < 0) + return -1; + } + } + return nSrcLen; +} + +int CIEC_STRING::toUTF8(char* pa_pacBuffer, unsigned int pa_nBufferSize, bool pa_bEscape) const { + // Count the needed space + unsigned int nNeededLength = pa_bEscape ? 2 : 0; // Leading and trailing delimiter + int nRes; + + const unsigned char *pRunner = (const unsigned char *) getValue(); + while (*pRunner) { + nRes = CUnicodeUtilities::encodeUTF8Codepoint(0, 0, (TForteUInt32) *pRunner); + if (nRes < 0) + return -1; + nNeededLength += nRes; + if (nRes == 1 && pa_bEscape && dollarEscapeChar(0, *pRunner, 0) == 2) + nNeededLength++; + ++pRunner; + } + + if (pa_pacBuffer == 0) + return nNeededLength; + + if (nNeededLength+1 > pa_nBufferSize) + return -1; + + char *pEncRunner = pa_pacBuffer; + char *pDataEnd = pa_pacBuffer + nNeededLength; + + if (pa_bEscape) + *pEncRunner++ = '\''; + + pRunner = (const unsigned char *) getValue(); + while (*pRunner) { + nRes = CUnicodeUtilities::encodeUTF8Codepoint((TForteByte *) pEncRunner, static_cast(pDataEnd - pEncRunner), (TForteUInt32) *pRunner); + if (nRes == 1 && pa_bEscape) + nRes = dollarEscapeChar(pEncRunner, *pRunner, static_cast(pDataEnd - pEncRunner)); + + if (nRes < 0) + return -1; + + pEncRunner += nRes; + ++pRunner; + } + + if (pa_bEscape) + *pEncRunner++ = '\''; + *pEncRunner = '\0'; + + return static_cast(pEncRunner - pa_pacBuffer); +} + +#endif diff --git a/src/core/datatypes/forte_string.h b/src/core/datatypes/forte_string.h new file mode 100644 index 000000000..fd2275eed --- /dev/null +++ b/src/core/datatypes/forte_string.h @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, nxtControl GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Rene Smodic, Alois Zoitl, Gerhard Ebenhofer + * Ingo Hegny, Martin Melik Merkumians, Monika Wenger, Stanislav Meduna, + * Matthias Plasch + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_STRING_H_ +#define _FORTE_STRING_H_ + +#include "forte_any_string.h" +#include +#include + +namespace forte { + namespace com_infra { + class CFBDKASN1ComLayer; + } +} + +/*!\ingroup COREDTS CIEC_STRING represents the string data type according to IEC 61131. + */ +class CIEC_STRING : public CIEC_ANY_STRING{ + DECLARE_FIRMWARE_DATATYPE(STRING) + ; + public: + CIEC_STRING() { + } + + CIEC_STRING(const char* pa_pacValue) { + (*this) = pa_pacValue; + } + + virtual ~CIEC_STRING(){ + } + + CIEC_STRING &operator =(const char* const pa_pacValue) { + CIEC_ANY_STRING::operator =(pa_pacValue); + return *this; + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_STRING; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_acValue Pointer to char-array for the result + * \param pa_nBufferSize Size of the buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_acValue, unsigned int pa_nBufferSize) const ; + + /*! \brief Converts a UTF-8 encoded string to a STRING (ISO 10646 Row 00 internally) + * + * This command implements a conversion function from a UTF-8 + * encoded string (found e.g. in XML to the internal + * ISO 10646 Row 00 encoding. + * \param pa_pacValue Reference to the given UTF-8 encoded byte array + * \param pa_nLen Length to read (-1 for null-terminated) + * \param pa_bUnescape Handle $-escapes and delimiter characters at the beginning and end + * \return number of bytes used from srcString + * -1 on error + */ +#ifdef FORTE_UNICODE_SUPPORT + virtual int fromUTF8(const char *pa_pacValue, int pa_nLen, bool pa_bUnescape); +#endif + /*! \brief Converts the STRING to a UTF-8 representation + * + * This command implements a conversion function from a STRING + * to a UTF-8 encoding, usable e.g. for the serialization. + * \param pa_pacBuffer Reference to the output buffer. If 0, only the needed size will be computed. + * \param pa_nBufferSize Size of the provided buffer. + * \param pa_bEscape Produce $-escapes and delimiter characters at the beginning and end + * \return number of bytes used in the buffer + * -1 on error + */ +#ifdef FORTE_UNICODE_SUPPORT + virtual int toUTF8(char* pa_pacBuffer, unsigned int pa_nBufferSize, bool pa_bEscape) const; +#endif + protected: + + + virtual void setValue(const CIEC_ANY &pa_roValue){ + if (pa_roValue.getDataTypeID() == CIEC_ANY::e_STRING) { + const CIEC_STRING &roSrc(static_cast (pa_roValue)); + this->assign(roSrc.getValue(), roSrc.length()); + } + } + + private: +}; + +inline +bool operator ==(const CIEC_STRING &pa_roLeft, const CIEC_STRING &pa_roRight) { + return (0 == strcmp(pa_roLeft.getValue(), pa_roRight.getValue())); +} + +inline +bool operator !=(const CIEC_STRING &pa_roLeft, const CIEC_STRING &pa_roRight) { + return !(pa_roLeft ==pa_roRight); +} + +#endif /*_FORTE_STRING_H_*/ diff --git a/src/core/datatypes/forte_struct.cpp b/src/core/datatypes/forte_struct.cpp new file mode 100644 index 000000000..e480fe317 --- /dev/null +++ b/src/core/datatypes/forte_struct.cpp @@ -0,0 +1,281 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "forte_struct.h" +#include +//#include + +CIEC_STRUCT::CIEC_STRUCT(CStringDictionary::TStringId pa_unTypeName, TForteUInt16 pa_nLength, const CStringDictionary::TStringId pa_unElementTypes[], const CStringDictionary::TStringId pa_unElementNames[], TForteUInt8 TypeID){ + setup(pa_unTypeName, pa_nLength, pa_unElementTypes, pa_unElementNames, TypeID); +// printf("STRUCT() Type: %s\n",CStringDictionary::getInstance().get(getStructTypeNameID())); +} + +CIEC_STRUCT::CIEC_STRUCT(const CIEC_STRUCT& pa_roValue) : + CIEC_ANY_DERIVED(){ + //TODO: check if same datatype; + if(0 != pa_roValue.getStructSize()){ + setGenData((TForteByte *) forte_malloc( + scm_unMembersOffset + + pa_roValue.getStructSize() * sizeof(CIEC_ANY))); //Data + setStructSize(pa_roValue.getStructSize()); + setASN1StructType(pa_roValue.getASN1StructType()); + setElementNames((pa_roValue.elementNames())); + setStructTypeNameID(pa_roValue.getStructTypeNameID()); + } + + TForteByte *acDataBuf = (TForteByte *) getMembers(); + if(0 != acDataBuf){ + const CIEC_ANY* poSrcBuf = pa_roValue.getMembers(); + + for(unsigned int i = 0; i < getStructSize(); ++i, ++poSrcBuf){ + poSrcBuf->clone(acDataBuf); //clone is faster than the CTypeLib call + acDataBuf += sizeof(CIEC_ANY); + } + } + else{ +// printf("target of copy constructor is null-pointer!\n"); + } +} + +CIEC_STRUCT::~CIEC_STRUCT(){ + clear(); +} + +void CIEC_STRUCT::setup(CStringDictionary::TStringId pa_unTypeName, TForteUInt16 pa_nLength, const CStringDictionary::TStringId pa_aunElementTypes[], const CStringDictionary::TStringId pa_aunElementNames[], TForteUInt8 pa_TypeID){ + if(0 != pa_nLength){ + if(0 != getGenData()){ + clear(); + } + setGenData((TForteByte *) forte_malloc( + scm_unMembersOffset + + pa_nLength * sizeof(CIEC_ANY))); //Data (system-dependent) + setASN1StructType(pa_TypeID); + setStructSize(pa_nLength); + setElementNames(pa_aunElementNames); + setStructTypeNameID(pa_unTypeName); + TForteByte *acDataBuf = (TForteByte *) getMembers(); + + for(unsigned int i = 0; i < pa_nLength; ++i){ + CTypeLib::createDataTypeInstance(pa_aunElementTypes[i], acDataBuf); + acDataBuf += sizeof(CIEC_ANY); + } + } +} + +void CIEC_STRUCT::setValue(const CIEC_ANY& pa_roValue){ + if(pa_roValue.getDataTypeID() == e_STRUCT){ + if(getStructTypeNameID() == static_cast(pa_roValue).getStructTypeNameID()){ + CIEC_ANY *poDstBuf = getMembers(); + const CIEC_ANY* poSrcBuf = static_cast(pa_roValue).getMembers(); + for(unsigned int i = 0; i < getStructSize(); ++i, ++poSrcBuf, ++poDstBuf){ + poDstBuf->setValue( *poSrcBuf); + } + } + } +} + +void CIEC_STRUCT::clear(){ + if(getASN1StructType()){ + CIEC_ANY *poBuf = getMembers(); + + for(TForteUInt8 i = 0; i < getStructSize(); ++i, ++poBuf){ + poBuf->~CIEC_ANY(); + } + + forte_free(getGenData()); + setGenData(0); + } +} + +int CIEC_STRUCT::fromString(const char *pa_pacValue){ + int nRetVal = -1; + int nLength; + unsigned int nElementCount = 0; // count how much elements we could retrieve + const char *pcRunner = pa_pacValue; + CStringDictionary::TStringId unElementNameId; + CIEC_ANY *poMember; + + if('(' == pa_pacValue[0]){ + + while((*pcRunner != '\0') && (*pcRunner != ')') && (nElementCount < getStructSize())){ + pcRunner++; + + //first extract the element name + nLength = 0; + unElementNameId = parseNextElementId(pcRunner, nLength); + + if(CStringDictionary::scm_nInvalidStringId == unElementNameId){ + return -1; + } + + pcRunner += nLength; + + poMember = getMemberNamed(unElementNameId); + if(0 == poMember){ + return -1; + } + + nLength = poMember->fromString(pcRunner); + + if(0 < nLength){ + nElementCount++; + pcRunner += nLength; + + //remove trailing whitespaces + while(' ' == *pcRunner){ + pcRunner++; + } + + if(',' != *pcRunner){ + break; + } + } + else{ + //we have an error or the end bracket + break; + } + } + + if((*pcRunner == ')')&& (nElementCount == getStructSize())) { + //structs have to and on a closing bracket + nRetVal = static_cast(pcRunner - pa_pacValue + 1); //+1 from the closing bracket + } + } + return nRetVal; +} + +CStringDictionary::TStringId CIEC_STRUCT::parseNextElementId(const char *pa_pcRunner, int &pa_nCounter){ + CStringDictionary::TStringId unElementNameId = CStringDictionary::scm_nInvalidStringId; + TIdentifier acIdentifier; + + //remove any leading whitespaces before the identifier + while(' ' == *pa_pcRunner){ + pa_pcRunner++; + pa_nCounter++; + } + + for(unsigned int i = 0; ((*pa_pcRunner != '\0') && (*pa_pcRunner != ')')); ++i, ++pa_nCounter, ++pa_pcRunner){ + if(i >= cg_nIdentifierLength){ + //currently we only allow identifiers smaller that size + return CStringDictionary::scm_nInvalidStringId; + } + + if((':' == *pa_pcRunner) || (' ' == *pa_pcRunner)){ + acIdentifier[i] = '\0'; //close identifier string + break; + } + acIdentifier[i] = *pa_pcRunner; + } + //remove any whitespaces between identifier and assignment operator + while(' ' == *pa_pcRunner){ + pa_pcRunner++; + pa_nCounter++; + } + + if(':' == *pa_pcRunner){ + //only if we have a : we have a correct identifier + pa_pcRunner++; + pa_nCounter++; + if('=' == *pa_pcRunner){ + unElementNameId = CStringDictionary::getInstance().getId(acIdentifier); + pa_pcRunner++; + pa_nCounter++; + //remove any whitespaces between assignment operator and value + while(' ' == *pa_pcRunner){ + pa_pcRunner++; + pa_nCounter++; + } + if(('\0' == *pa_pcRunner) || (')' == *pa_pcRunner)){ + return CStringDictionary::scm_nInvalidStringId; + } + } + } + + return unElementNameId; +} + +int CIEC_STRUCT::toString(char* pa_acValue, unsigned int pa_nBufferSize) const{ + int nBytesUsed = -1; + + if(pa_nBufferSize){ + *pa_acValue = '('; + pa_acValue++; + pa_nBufferSize--; + nBytesUsed = 1; + int nUsedBytesByElement; + TForteUInt16 unSize = getStructSize(); + const CStringDictionary::TStringId *punMemberNameIds = elementNames(); + const CIEC_ANY *poMembers = getMembers(); + + for(unsigned int i = 0; i < unSize; ++i, ++poMembers, ++punMemberNameIds){ + const char *acMemberName = CStringDictionary::getInstance().get(*punMemberNameIds); + + if(strlen(acMemberName) + 2 > pa_nBufferSize){ + return -1; + } + + strcpy(pa_acValue, acMemberName); + pa_acValue += strlen(acMemberName); + *pa_acValue = ':'; + pa_acValue++; + *pa_acValue = '='; + pa_acValue++; + pa_nBufferSize -= (strlen(acMemberName) + 2); + nBytesUsed += (strlen(acMemberName) + 2); + + nUsedBytesByElement = poMembers->toString(pa_acValue, pa_nBufferSize); + if(-1 == nUsedBytesByElement){ + return -1; + } + pa_nBufferSize -= nUsedBytesByElement; + pa_acValue += nUsedBytesByElement; + if(!pa_nBufferSize){ + return -1; + } + nBytesUsed += nUsedBytesByElement; + + if(i != static_cast(unSize - 1)){ + *pa_acValue = ','; + pa_acValue++; + + ++nBytesUsed; + pa_nBufferSize--; + } + } + if(pa_nBufferSize < 2){ + return -1; + } + *pa_acValue = ')'; + pa_acValue[1] = '\0'; + nBytesUsed++; + } + + return nBytesUsed; +} + +CIEC_ANY *CIEC_STRUCT::getMemberNamed(CStringDictionary::TStringId pa_unMemberNameId){ + CIEC_ANY *poRetVal = 0; + + CIEC_ANY *poMembers = getMembers(); + const CStringDictionary::TStringId *punMemberNameIds = elementNames(); + + for(unsigned int i = 0; i < getStructSize(); ++i, ++poMembers, ++punMemberNameIds){ + if(*punMemberNameIds == pa_unMemberNameId){ + poRetVal = poMembers; + break; + } + + } + + return poRetVal; +} + diff --git a/src/core/datatypes/forte_struct.h b/src/core/datatypes/forte_struct.h new file mode 100644 index 000000000..157b6166f --- /dev/null +++ b/src/core/datatypes/forte_struct.h @@ -0,0 +1,182 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_STRUCT_H_ +#define _FORTE_STRUCT_H_ + +#include "forte_any_derived.h" + +class CIEC_STRUCT : public CIEC_ANY_DERIVED{ + public: + CIEC_STRUCT(CStringDictionary::TStringId pa_unTypeName, TForteUInt16 pa_nLength, const CStringDictionary::TStringId pa_unElementTypes[], const CStringDictionary::TStringId pa_unElementNames[], TForteUInt8 TypeID); + + CIEC_STRUCT(const CIEC_STRUCT& pa_roValue); + + virtual ~CIEC_STRUCT(); + + CIEC_STRUCT& operator =(const CIEC_STRUCT &pa_roValue){ + setValue(pa_roValue); + return *this; + } + +//new alignment: +// ASN1-StructType (8bit) +// padding (8bit) +// StructSize (16bit) +// StructTypeNameID (32bit) +// *elementNames (system dependent - but aligned) +// Data (system dependent - but aligned) + + /*! \brief Get the Struct's type + * + * With this command the type-ID of the struct can be evaluated. + * + * \param - No parameters necessary. + * \return - the type-ID of the struct. + */ + + TForteUInt8 getASN1StructType() const{ + return (0 != getGenData()) ? (*((TForteUInt8 *) (getGenData()))) : static_cast(0); + } + + /*! \brief Get the Struct's size + * + * With this command the size of the struct can be evaluated. + * + * \param - No parameters necessary. + * \return - the size of the struct. + */ + TForteUInt16 getStructSize() const{ + return (0 != getGenData()) ? (*((TForteUInt16 *) (getGenData() + 2 * sizeof(TForteUInt8)))) : static_cast(0); + } + + /*! \brief Get the Struct's elementNames + * + * retrieve array of StringIDs of element names. + * + * \param - No parameters necessary. + * \return - pointer to array of StringIds. + */ + const CStringDictionary::TStringId* elementNames() const{ + if(0 != getGenData()){ + CStringDictionary::TStringId** pBuf = reinterpret_cast(const_cast(getGenData() + 2 * sizeof(TForteUInt8) + sizeof(TForteUInt16) + sizeof(CStringDictionary::TStringId))); + return *pBuf; + } + return 0; + } + + /*! \brief Get the Struct's type name + * + * With this command the type name of the struct can be evaluated. + * + * \param - No parameters necessary. + * \return - StringId of Struct's type name. + */ + CStringDictionary::TStringId getStructTypeNameID() const{ + return (0 != getGenData()) ? (*((CStringDictionary::TStringId *) (getGenData() + 2 * sizeof(TForteUInt8) + sizeof(TForteUInt16)))) : 0; + } + + void setValue(const CIEC_ANY& pa_roValue); + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_STRUCT; + } + + /*! \brief Converts array value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (array format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_rsValue); + /*! \brief Converts data type value to string + * + * This command implements a conversion function to C++ data type. + * \param pa_acValue Pointer to char-array + * \param pa_nBufferSize Size of the provided buffer + * \return number of bytes used in the buffer + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; + + CIEC_ANY *getMembers(){ + return (CIEC_ANY *) ((0 != getGenData()) ? (getGenData() + scm_unMembersOffset) : 0); + } + + const CIEC_ANY *getMembers() const{ + return (CIEC_ANY *) ((0 != getGenData()) ? (getGenData() + scm_unMembersOffset) : 0); + } + + /*! \brief Get the struct's member var with the given name id + * + * \param pa_unMemberNameId the string id of the member name + * \return on a valid member name id a pointer to the member var otherwise 0 + */ + CIEC_ANY *getMemberNamed(CStringDictionary::TStringId pa_unMemberNameId); + + protected: + + //!Function to configure the array if it is created via the typelib + void setup(CStringDictionary::TStringId pa_unTypeName, TForteUInt16 pa_nLength, const CStringDictionary::TStringId pa_unElementTypes[], const CStringDictionary::TStringId pa_unElementNames[], TForteUInt8 pa_TypeID); + +//TODO: remove? already defined in de-/serializer + enum EASN1Tags{ + e_UNIVERSAL = 0, e_APPLICATION = 64, e_CONTEXT = 128, e_PRIVATE = 192 + }; + enum EASN1Encoding{ + e_PRIMITIVE = 0, e_CONSTRUCTED = 32 + }; + + private: + static const unsigned int scm_unMembersOffset = + 2 * sizeof(TForteUInt8) + //ASN1Type + padding (2*8bit) + sizeof(TForteUInt16) + //number of elements (1x16bit) + sizeof(CStringDictionary::TStringId) + //Datatype name ID (1x32bit) + sizeof(CStringDictionary::TStringId*); //Pointer to const static member of specialized class, containing element names (system-dependent) + + void setASN1StructType(TForteUInt16 pa_unVal){ + TForteByte *pBuf = getGenData(); + if(0 != pBuf){ + *((TForteUInt16 *) (pBuf)) = pa_unVal; + } + } + + void setStructTypeNameID(const CStringDictionary::TStringId pa_unVal){ + TForteByte * pBuf = (getGenData() + 2 * sizeof(TForteUInt8) + sizeof(TForteUInt16)); + if(0 != pBuf){ + *((CStringDictionary::TStringId*) (pBuf)) = pa_unVal; + } + } + + void setStructSize(TForteUInt16 pa_unVal){ + TForteByte *pBuf = getGenData() + 2 * sizeof(TForteUInt8); + if(0 != pBuf){ + *((TForteUInt16 *) (pBuf)) = pa_unVal; + } + } + + void setElementNames(const CStringDictionary::TStringId* pa_unElementNames){ + CStringDictionary::TStringId** pBuf = (reinterpret_cast((getGenData() + 2 * sizeof(TForteUInt8) + sizeof(TForteUInt16) + sizeof(CStringDictionary::TStringId)))); + if(0 != getGenData()){ + *(pBuf) = (const_cast((pa_unElementNames))); + } + } + + void clear(); + + static CStringDictionary::TStringId parseNextElementId(const char *pa_pcRunner, int &pa_nCounter); + +}; + +#endif /*_FORTE_STRUCT_H_*/ diff --git a/src/core/datatypes/forte_time.cpp b/src/core/datatypes/forte_time.cpp new file mode 100644 index 000000000..f99f62f3d --- /dev/null +++ b/src/core/datatypes/forte_time.cpp @@ -0,0 +1,184 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Ingo Hegny, + * Martin Melik Merkumians, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_time.h" + +#include "../../arch/timerha.h" +#include +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "forte_lint.h" +#else + #include "forte_dint.h" +#endif + + +#define MILISECONDS_PER_SECOND 1000 +#define MICROSECONDS_PER_SECOND 1000000 + +DEFINE_FIRMWARE_DATATYPE(TIME, g_nStringIdTIME) + +const TForteUInt16 CIEC_TIME::scm_unMaxStringBufSize = 100; + +int CIEC_TIME::fromString(const char *pa_pacValue){ + int nRetVal = -1; + char* pcEnd; + + TValueType nIntVal = 0; + + if((pa_pacValue[0] == 'T') || (pa_pacValue[0] == 't')){ + nRetVal = 1; + pa_pacValue++; + if(('i' == tolower(pa_pacValue[0])) && ('m' == tolower(pa_pacValue[1])) && ('e' == tolower(pa_pacValue[2]))){ + pa_pacValue += 3; + nRetVal += 3; + } + + if(*pa_pacValue == '#'){ // the string has to start with T# + pa_pacValue++; + nRetVal++; + long nTimeFactor = 1; + bool bEnd = false; + do{ + long nBuf = forte::core::util::strtol(pa_pacValue, &pcEnd, 10); + switch (tolower(*pcEnd)){ + case 'd': + nTimeFactor = 86400000; + break; + + case 'h': + nTimeFactor = 3600000; + break; + + case 'm': + if('s' == *(pcEnd + 1) || 'S' == *(pcEnd + 1)){ + nTimeFactor = 1; + ++pcEnd; + } + else{ + nTimeFactor = 60000; + } + break; + + case 's': + nTimeFactor = 1000; + break; + case '_': + //ignore leading underscores + break; + default: + if(pa_pacValue == pcEnd){ + //we couldn't parse anything + return -1; + } + bEnd = true; + break; + } + nRetVal += static_cast(pcEnd - pa_pacValue); + if(!bEnd){ + ++nRetVal; + } + pa_pacValue = pcEnd + 1; + nIntVal += (nBuf * nTimeFactor); + } while(('\0' != *pa_pacValue) && (!bEnd)); + } + else{ + return -1; + } + } + else{ + nIntVal = forte::core::util::strtol(pa_pacValue, &pcEnd, 10); + nRetVal = static_cast(pcEnd - pa_pacValue); + } + + //the intval is represented in ms + setFromMiliSeconds(nIntVal); + return nRetVal; + +} + +int CIEC_TIME::toString(char* pa_pacValue, unsigned int pa_nBufferSize) const{ + int nRetVal = -1; + + if(pa_nBufferSize > 4){ + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT timeInMilliSeconds(getInMiliSeconds()); +#else + CIEC_DINT timeInMilliSeconds(getInMiliSeconds()); +#endif + nRetVal = timeInMilliSeconds.toString(pa_pacValue + 2, pa_nBufferSize - 4); + if(-1 != nRetVal){ + pa_pacValue[0] = 'T'; + pa_pacValue[1] = '#'; + pa_pacValue[nRetVal + 2] = 'm'; + pa_pacValue[nRetVal + 3] = 's'; + pa_pacValue[nRetVal + 4] = '\0'; + nRetVal += 4; + } + } + return nRetVal; +} + +CIEC_TIME::TValueType CIEC_TIME::getInSeconds() const { + return (TValueType) *this / FORTE_TIME_BASE_UNITS_PER_SECOND; +} + +CIEC_TIME::TValueType CIEC_TIME::getInMiliSeconds() const{ + TValueType nRetVal; + #if MILISECONDS_PER_SECOND < FORTE_TIME_BASE_UNITS_PER_SECOND + nRetVal = (TValueType) *this / (FORTE_TIME_BASE_UNITS_PER_SECOND / MILISECONDS_PER_SECOND); + #else + nRetVal = (TValueType) *this * (MILISECONDS_PER_SECOND / FORTE_TIME_BASE_UNITS_PER_SECOND); + #endif + return nRetVal; +} + +CIEC_TIME::TValueType CIEC_TIME::getInMicroSeconds() const{ + TValueType nRetVal; + #if MICROSECONDS_PER_SECOND < FORTE_TIME_BASE_UNITS_PER_SECOND + nRetVal = (TValueType) *this / (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000000); + #else + nRetVal = (TValueType) *this * (MICROSECONDS_PER_SECOND / FORTE_TIME_BASE_UNITS_PER_SECOND); + #endif + //fprintf(stderr,"time us: %lld\n",nRetVal); + return nRetVal; +} + +void CIEC_TIME::setFromSeconds(TValueType pa_nValue){ + *this = pa_nValue * FORTE_TIME_BASE_UNITS_PER_SECOND; +} + +void CIEC_TIME::setFromMiliSeconds(TValueType pa_nValue){ + #if MILISECONDS_PER_SECOND < FORTE_TIME_BASE_UNITS_PER_SECOND + *this = pa_nValue * (FORTE_TIME_BASE_UNITS_PER_SECOND / MILISECONDS_PER_SECOND); + #else + *this = pa_nValue / (MILISECONDS_PER_SECOND / FORTE_TIME_BASE_UNITS_PER_SECOND); + #endif +} + +void CIEC_TIME::setFromMicroSeconds(TValueType pa_nValue){ + #if MICROSECONDS_PER_SECOND < FORTE_TIME_BASE_UNITS_PER_SECOND + *this = pa_nValue * (FORTE_TIME_BASE_UNITS_PER_SECOND / MICROSECONDS_PER_SECOND); + #else + *this = pa_nValue / (MICROSECONDS_PER_SECOND / FORTE_TIME_BASE_UNITS_PER_SECOND); + #endif +} + +const CIEC_TIME TIME(){ + SForteTime tx = CTimerHandler::sm_poFORTETimer->getForteTime(); + TForteUInt64 temp = ((((TForteUInt64) tx.m_nUpperValue) << 32) & 0xFFFFFFFF00000000ULL) + (((TForteUInt64) tx.m_nLowerValue) & 0xFFFFFFFFULL); + //fprintf(stderr,"time: %lld, %lld\n",temp, temp * (1000000 / cg_nForteTicksPerSecond)); + return CIEC_TIME( temp * (FORTE_TIME_BASE_UNITS_PER_SECOND / cg_nForteTicksPerSecond) ); +}; + diff --git a/src/core/datatypes/forte_time.h b/src/core/datatypes/forte_time.h new file mode 100644 index 000000000..aa1fda240 --- /dev/null +++ b/src/core/datatypes/forte_time.h @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Monika Wenger, Ingo Hegny, Martin Melik Merkumians, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_TIME_H_ +#define _FORTE_TIME_H_ + +#include "forte_any_magnitude.h" + +/*!\ingroup COREDTS CIEC_TIME represents the time data types according to IEC 61131. + */ + +class CIEC_TIME : public CIEC_ANY_MAGNITUDE{ + DECLARE_FIRMWARE_DATATYPE(TIME) + public: + typedef TLargestIntValueType TValueType; + + CIEC_TIME(){ + } + + CIEC_TIME(const CIEC_TIME& pa_roValue) : + CIEC_ANY_MAGNITUDE(){ + setValueSimple(pa_roValue); + } + + CIEC_TIME(TValueType pa_nValue){ + *this = pa_nValue; + } + + CIEC_TIME(const char *pa_pacValue){ + if(-1 == CIEC_TIME::fromString(pa_pacValue)){ //explicitly state that you like to have the fromString of this class to avoid potential virtual function clashes in the constructor + //we had an error in string parsing set a default value + *this = 0; + } + } + + virtual ~CIEC_TIME(){ + } + + CIEC_TIME& operator =(TValueType pa_nValue){ + setLargestInt(pa_nValue); + return *this; + } + + CIEC_TIME& operator =(const CIEC_TIME &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + CIEC_TIME& operator ++(void){ + *this = 1 + (*this); + return *this; + } + + operator TValueType() const{ + return getLargestInt(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_TIME; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the buffer String + * \param pa_nBufferSize Size of the given buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; + + TValueType getInSeconds() const; + TValueType getInMiliSeconds() const; + TValueType getInMicroSeconds() const; + + void setFromSeconds(TValueType pa_nValue); + void setFromMiliSeconds(TValueType pa_nValue); + void setFromMicroSeconds(TValueType pa_nValue); + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +const CIEC_TIME TIME(); + +#endif /*_MTIME_H_*/ diff --git a/src/core/datatypes/forte_time_of_day.cpp b/src/core/datatypes/forte_time_of_day.cpp new file mode 100644 index 000000000..14e07d78f --- /dev/null +++ b/src/core/datatypes/forte_time_of_day.cpp @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 nxtControl GmbH, ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include +#include +#include +#include "forte_time_of_day.h" +#include "../../arch/timerha.h" + +DEFINE_FIRMWARE_DATATYPE(TIME_OF_DAY, g_nStringIdTIME_OF_DAY) + +int CIEC_TIME_OF_DAY::fromString(const char *pa_pacValue){ + // 15:00:00.000 + struct tm tm; + int msec = 0; + char *acBuffer = const_cast(pa_pacValue); + + memset(&tm, 0, sizeof(tm)); + + if('t' == tolower(*acBuffer) ){ + if(('o' == tolower(acBuffer[1])) && ('d' == tolower(acBuffer[2]))){ + acBuffer += 3; + } + else{ + //TODO maybe allow to turn this check of for small devices + if((0 == strncmp("time_of_day", acBuffer, 11)) || + (0 == strncmp("TIME_OF_DAY", acBuffer, 11))){ + acBuffer += 11; + } + } + + if('#' != *acBuffer){ + return -1; + } + acBuffer++; + } + + if('\0' != *acBuffer){ + tm.tm_hour = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10)); + if(':' == *acBuffer){ + ++acBuffer; + tm.tm_min = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10)); + if(':' == *acBuffer){ + ++acBuffer; + tm.tm_sec = static_cast(forte::core::util::strtoul(acBuffer, &acBuffer, 10)); + if('.' == *acBuffer){ + unsigned int nNums = 0; + ++acBuffer; + while (isdigit(*acBuffer)) { + msec = 10*msec + forte::core::util::charDigitToInt(*acBuffer); + ++acBuffer; + ++nNums; + } + + if(nNums < 3){ + for (unsigned int i=nNums; i < 3; ++i) + msec *= 10; + } + else{ + for (unsigned int i = 0; i < (nNums - 3); ++i) + msec /= 10; + } + } + } + } + else{ + if('\0' != *acBuffer){ + return -1; + } + } + } + else{ + return -1; + } + + setTUINT64((tm.tm_hour * 3600 + tm.tm_min * 60 + tm.tm_sec) * 1000ULL + msec); + + return static_cast(acBuffer - pa_pacValue); +} + +int CIEC_TIME_OF_DAY::toString(char* pa_pacValue, unsigned int pa_nBufferSize) const{ + int nRetVal = -1; + TForteUInt64 ntoStingBuffer = getTUINT64(); + time_t t = static_cast(ntoStingBuffer / 1000); + +#ifdef WIN32 + nRetVal = _snprintf(pa_pacValue, pa_nBufferSize, "%02d:%02d:%02d.%03d", + (int) (t / 3600), + (int) ((t % 3600) / 60), + (int) (t % 60), + (int) (ntoStingBuffer % 1000)); +#else + nRetVal = snprintf(pa_pacValue, pa_nBufferSize, "%02d:%02d:%02d.%03d", + (int) (t / 3600), + (int) ((t % 3600) / 60), + (int) (t % 60), + (int) (ntoStingBuffer % 1000)); +#endif + if((nRetVal < -1) || (nRetVal >= (int) pa_nBufferSize)){ + nRetVal = -1; + } + return nRetVal; +} + diff --git a/src/core/datatypes/forte_time_of_day.h b/src/core/datatypes/forte_time_of_day.h new file mode 100644 index 000000000..af11e5568 --- /dev/null +++ b/src/core/datatypes/forte_time_of_day.h @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2013 nxtControl GmbH, ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians, + * Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_TOD_H_ +#define _FORTE_TOD_H_ + +#include "forte_any_date.h" +#include +#if defined(WINCE) +#include +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +/*!\ingroup COREDTS CIEC_TIME_OF_DAY represents the time data types according to IEC 61131. + */ + +class CIEC_TIME_OF_DAY : public CIEC_ANY_DATE{ + DECLARE_FIRMWARE_DATATYPE(TIME_OF_DAY) + + public: + typedef TForteUInt64 TValueType; + + CIEC_TIME_OF_DAY(){ + } + + CIEC_TIME_OF_DAY(const CIEC_TIME_OF_DAY& pa_roValue) : + CIEC_ANY_DATE(){ + setValueSimple(pa_roValue); + } + + CIEC_TIME_OF_DAY(TForteUInt64 pa_nValue){ + setTUINT64(pa_nValue); + } + + virtual ~CIEC_TIME_OF_DAY(){ + } + + /*! \brief Operator: CIEC_TIME_OF_DAY data type = long data type + * + * This command implements the assignment operator for the C++ datatype long long. + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_TIME_OF_DAY& operator =(TForteInt64 pa_nValue){ + setTUINT64(pa_nValue); + return *this; + } + + CIEC_TIME_OF_DAY& operator =(const CIEC_TIME_OF_DAY &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Operator: CIEC_TIME data type operator++ + * + * This command implements the increment operator for the IEC61131 datatype TIME. + * The parameter value is represented by a C++ variable (call by value). + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_TIME_OF_DAY& operator ++(void){ + setTUINT64(getTUINT64() + 1); + return *this; + } + /*! \brief Converts CIEC_SINT to elementary 32 bit integer + * + * Conversion operator for converting CIEC_SINT to elementary 32 bit integer + */ + operator TForteUInt64() const{ + return getTUINT64(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_TIME_OF_DAY; + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the given String + * \return Can be the following response: + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_pacValue Pointer to the buffer String + * \param pa_nBufferSize Size of the given buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_pacValue, unsigned int pa_nBufferSize) const; + + /*! \brief Set the variable to current time + */ + void setCurrentTime(){ +#if ! defined(WINCE) + setTUINT64(time(0) * 1000ULL); +#else + setTUINT64(wceex_time(0) * 1000ULL); +#endif + } + ; +}; + +#endif /* #ifdef FORTE_USE_64BIT_DATATYPES */ + +#endif /*_FORTE_TOD_H_*/ diff --git a/src/core/datatypes/forte_udint.cpp b/src/core/datatypes/forte_udint.cpp new file mode 100644 index 000000000..df9f4fc70 --- /dev/null +++ b/src/core/datatypes/forte_udint.cpp @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Rene Smodic, Ingo Hegny, + * Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_udint.h" + +DEFINE_FIRMWARE_DATATYPE(UDINT, g_nStringIdUDINT) + +const TForteUInt16 CIEC_UDINT::scm_unMaxStringBufSize = 100; + +const CIEC_UDINT::TValueType CIEC_UDINT::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_udint.h b/src/core/datatypes/forte_udint.h new file mode 100644 index 000000000..6abd154a1 --- /dev/null +++ b/src/core/datatypes/forte_udint.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_UDINT_H_ +#define _FORTE_UDINT_H_ + +#include "forte_any_int.h" +#include + +/*!\ingroup COREDTS CIEC_UDINT represents the udint data type according to IEC 61131. + */ +class CIEC_UDINT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(UDINT) + + public: + typedef TForteUInt32 TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_UDINT(){ + } + + CIEC_UDINT(const CIEC_UDINT& pa_roValue) : + CIEC_ANY_INT(){ + setValueSimple(pa_roValue); + } + + CIEC_UDINT(TForteUInt32 pa_nValue){ + setTUINT32(pa_nValue); + } + + virtual ~CIEC_UDINT(){ + } + + /*! \brief Operator: CIEC_UDINT data type = unsigned long data type + * + * This command implements the assignment operator for the C++ datatype UNSIGNED LONG + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_UDINT& operator =(TForteUInt32 pa_nValue){ + setTUINT32(pa_nValue); + return *this; + } + + CIEC_UDINT& operator =(const CIEC_UDINT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_UDINT to elementary unsigned 32 bit integer + * + * Conversion operator for converting CIEC_UDINT to elementary unsigned 32 bit integer + */ + operator TForteUInt32() const{ + return getTUINT32(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_UDINT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_UDINT_H_*/ diff --git a/src/core/datatypes/forte_uint.cpp b/src/core/datatypes/forte_uint.cpp new file mode 100644 index 000000000..c97dc3057 --- /dev/null +++ b/src/core/datatypes/forte_uint.cpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Ingo Hegny, Monika Wenger, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_uint.h" + +DEFINE_FIRMWARE_DATATYPE(UINT, g_nStringIdUINT) + +const TForteUInt16 CIEC_UINT::scm_unMaxStringBufSize = 100; + +const CIEC_UINT::TValueType CIEC_UINT::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_uint.h b/src/core/datatypes/forte_uint.h new file mode 100644 index 000000000..d143d0c28 --- /dev/null +++ b/src/core/datatypes/forte_uint.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_UINT_H_ +#define _FORTE_UINT_H_ + +#include "forte_any_int.h" +#include + +/*!\ingroup COREDTS CIEC_UINT represents the uint data type according to IEC 61131. + */ +class CIEC_UINT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(UINT) + + public: + typedef TForteUInt16 TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_UINT(){ + } + + CIEC_UINT(const CIEC_UINT& pa_roValue) : + CIEC_ANY_INT(){ + setValueSimple(pa_roValue); + } + + CIEC_UINT(TForteUInt16 pa_nValue){ + setTUINT16(pa_nValue); + } + + virtual ~CIEC_UINT(){ + } + + /*! \brief Operator: CIEC_UINT data type = unsigned short data type + * + * This command implements the assignment operator for the C++ datatype UNSIGNED SHORT + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_UINT& operator=(TForteUInt16 pa_nValue){ + setTUINT16(pa_nValue); + return *this; + } + + CIEC_UINT& operator =(const CIEC_UINT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_UDINT to elementary unsigned 16 bit integer + * + * Conversion operator for converting CIEC_UDINT to elementary unsigned 16 bit integer + */ + operator TForteUInt16() const{ + return getTUINT16(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_UINT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_UINT_H_*/ diff --git a/src/core/datatypes/forte_ulint.cpp b/src/core/datatypes/forte_ulint.cpp new file mode 100644 index 000000000..d3d34f4e9 --- /dev/null +++ b/src/core/datatypes/forte_ulint.cpp @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_ulint.h" + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_DATATYPE(ULINT, g_nStringIdULINT) + +const TForteUInt16 CIEC_ULINT::scm_unMaxStringBufSize = 100; + +const CIEC_ULINT::TValueType CIEC_ULINT::scm_nMaxVal = std::numeric_limits::max(); + +#endif diff --git a/src/core/datatypes/forte_ulint.h b/src/core/datatypes/forte_ulint.h new file mode 100644 index 000000000..7bfa8424a --- /dev/null +++ b/src/core/datatypes/forte_ulint.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_ULINT_H_ +#define _FORTE_ULINT_H_ + +#include "forte_any_int.h" +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +/*!\ingroup COREDTS CIEC_ULINT represents the ulint data type according to IEC 61131. + * @author mw & az + */ +class CIEC_ULINT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(ULINT) + + public: + typedef TForteUInt64 TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_ULINT(){ + } + + CIEC_ULINT(const CIEC_ULINT& pa_roValue) : CIEC_ANY_INT() { + setValueSimple(pa_roValue); + } + + CIEC_ULINT(TForteUInt64 pa_nValue){ + setTUINT64(pa_nValue); + } + + virtual ~CIEC_ULINT(){ + } + + /*! \brief Operator: CIEC_ULINT data type = unsigned long data type + * + * This command implements the assignment operator for the C++ datatype UNSIGNED LONG + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_ULINT& operator =(TForteUInt64 pa_nValue){ + setTUINT64(pa_nValue); + return *this; + } + + CIEC_ULINT& operator =(const CIEC_ULINT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_ULINT to elementary unsigned 64 bit integer + * + * Conversion operator for converting CIEC_ULINT to elementary unsigned 64 bit integer + */ + operator TForteUInt64() const{ + return getTUINT64(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_ULINT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif +#endif /*_FORTE_ULINT_H_*/ diff --git a/src/core/datatypes/forte_usint.cpp b/src/core/datatypes/forte_usint.cpp new file mode 100644 index 000000000..1ee18b91c --- /dev/null +++ b/src/core/datatypes/forte_usint.cpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_usint.h" + +DEFINE_FIRMWARE_DATATYPE(USINT, g_nStringIdUSINT) + +const TForteUInt16 CIEC_USINT::scm_unMaxStringBufSize = 100; + +const CIEC_USINT::TValueType CIEC_USINT::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_usint.h b/src/core/datatypes/forte_usint.h new file mode 100644 index 000000000..eca117107 --- /dev/null +++ b/src/core/datatypes/forte_usint.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Monika Wenger, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_USINT_H_ +#define _FORTE_USINT_H_ + +#include "forte_any_int.h" +#include + +/*!\ingroup COREDTS CIEC_USINT represents the usint data type according to IEC 61131. + */ +class CIEC_USINT : public CIEC_ANY_INT{ + DECLARE_FIRMWARE_DATATYPE(USINT) + + public: + typedef TForteUInt8 TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_USINT(){ + } + + CIEC_USINT(const CIEC_USINT& pa_roValue) : + CIEC_ANY_INT() { + setValueSimple(pa_roValue); + } + + CIEC_USINT(TForteUInt8 pa_nValue){ + setTUINT8(pa_nValue); + } + + virtual ~CIEC_USINT(){ + } + + /*! \brief Operator: CIEC_USINT data type = unsigned char data type + * + * This command implements the assignment operator for the C++ datatype UNSIGNED CHAR + * The parameter value is represented by a C++ variable (call by value). + * \param pa_nValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_USINT& operator =(TForteUInt8 pa_nValue){ + setTUINT8(pa_nValue); + return *this; + } + + CIEC_USINT& operator =(const CIEC_USINT &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_UDINT to elementary unsigned 16 bit integer + * + * Conversion operator for converting CIEC_UDINT to elementary unsigned 16 bit integer + */ + operator TForteUInt8() const{ + return getTUINT8(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_USINT; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_USINT_H_*/ diff --git a/src/core/datatypes/forte_word.cpp b/src/core/datatypes/forte_word.cpp new file mode 100644 index 000000000..dcd747319 --- /dev/null +++ b/src/core/datatypes/forte_word.cpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Ingo Hegny, Monika Wenger, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_word.h" + +DEFINE_FIRMWARE_DATATYPE(WORD, g_nStringIdWORD) + +const TForteUInt16 CIEC_WORD::scm_unMaxStringBufSize = 100; + +const CIEC_WORD::TValueType CIEC_WORD::scm_nMaxVal = std::numeric_limits::max(); diff --git a/src/core/datatypes/forte_word.h b/src/core/datatypes/forte_word.h new file mode 100644 index 000000000..e21698177 --- /dev/null +++ b/src/core/datatypes/forte_word.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_WORD_H_ +#define _FORTE_WORD_H_ + +#include "forte_any_bit.h" +#include + +/*!\ingroup COREDTS CIEC_WORD represents the word data type according to IEC 61131. + */ +class CIEC_WORD : public CIEC_ANY_BIT{ + DECLARE_FIRMWARE_DATATYPE(WORD) + + public: + typedef TForteWord TValueType; + + static const TValueType scm_nMinVal = 0; + static const TValueType scm_nMaxVal; + + CIEC_WORD(){ + } + + CIEC_WORD(const CIEC_WORD& pa_roValue) : + CIEC_ANY_BIT(){ + setValueSimple(pa_roValue); + } + + CIEC_WORD(TForteWord pa_cValue){ + setTUINT16(pa_cValue); + } + + virtual ~CIEC_WORD(){ + } + + /*! \brief Operator: CIEC_WORD data type = unsigned short data type + * + * This command implements the assignment operator for the C++ datatype UNSIGNED SHORT + * The parameter value is represented by a C++ variable (call by value). + * \param pa_cValue Value for assignment. + * \return Can be the following response: + * - Pointer to given object. + */ + CIEC_WORD& operator =(TForteWord pa_cValue){ + setTUINT16(pa_cValue); + return *this; + } + + CIEC_WORD& operator =(const CIEC_WORD &pa_roValue){ + setValueSimple(pa_roValue); + return *this; + } + + /*! \brief Converts CIEC_WORD to elementary word + * + * Conversion operator for converting CIEC_WORD to elementary word + */ + operator TForteWord() const{ + return getTUINT16(); + } + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_WORD; + } + + static const TForteUInt16 scm_unMaxStringBufSize; +}; + +#endif /*_FORTE_WORD_H_*/ diff --git a/src/core/datatypes/forte_wstring.cpp b/src/core/datatypes/forte_wstring.cpp new file mode 100644 index 000000000..5ea37f1b2 --- /dev/null +++ b/src/core/datatypes/forte_wstring.cpp @@ -0,0 +1,275 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Ingo Hegny, Stanislav Meduna + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "forte_wstring.h" +#include + +#include "unicode_utils.h" + +DEFINE_FIRMWARE_DATATYPE(WSTRING, g_nStringIdWSTRING) + +bool CIEC_WSTRING::fromUTF16(const TForteByte *pa_pacBuffer, unsigned int pa_nBufferLen){ + bool bLittleEndian = false; + TForteUInt32 nCodepoint; + int nRes; + unsigned int nRemLen = pa_nBufferLen; + const TForteByte *pacBuffer = pa_pacBuffer; + + if(pa_nBufferLen == 0){ + assign("", 0); + return true; + } + else if((pa_nBufferLen & 1) == 1){ + return false; + } + + // Check the BOM, default to big endian + nRes = CUnicodeUtilities::parseUTF16Codepoint(pa_pacBuffer, nCodepoint, false); + if(nRes < 0) + return false; + if(nRes == 2){ + if(nCodepoint == CUnicodeUtilities::scm_unBOMMarkerSwapped){ + bLittleEndian = true; + nRemLen -= 2; + pacBuffer += 2; + } + else if(nCodepoint == CUnicodeUtilities::scm_unBOMMarker){ + nRemLen -= 2; + pacBuffer += 2; + } + } + + // Count the needed space + const TForteByte *pRunner = pacBuffer; + unsigned int i = 0; + unsigned int nNeededLength = 0; + while(i < nRemLen){ + nRes = CUnicodeUtilities::parseUTF16Codepoint(pRunner, nCodepoint, bLittleEndian); + if(nRes < 0 || nRes + i > nRemLen) + return false; + i += nRes; + pRunner += nRes; + nRes = CUnicodeUtilities::encodeUTF8Codepoint(0, 0, nCodepoint); + if(nRes < 0) + return false; + nNeededLength += nRes; + } + + if(nNeededLength > scm_unMaxStringLen) + return false; + + // Reserve and encode + reserve(static_cast(nNeededLength)); + if(getGenData() == 0) + return false; + + TForteByte *pEncRunner = (TForteByte *) getValue(); + TForteByte *pDataEnd = pEncRunner + nNeededLength; + pRunner = pacBuffer; + i = 0; + while(i < nRemLen){ + nRes = CUnicodeUtilities::parseUTF16Codepoint(pRunner, nCodepoint, bLittleEndian); + i += nRes; + pRunner += nRes; + nRes = CUnicodeUtilities::encodeUTF8Codepoint(pEncRunner, static_cast(pDataEnd - pEncRunner), nCodepoint); + pEncRunner += nRes; + } + setLength(static_cast(nNeededLength)); + *pEncRunner = '\0'; + + return true; +} + +int CIEC_WSTRING::toUTF16(TForteByte* pa_pacBuffer, unsigned int pa_nBufferSize) const{ + // Count the needed space + const TForteByte *pRunner = (const TForteByte *) getValue(); + unsigned int i = 0; + unsigned int nNeededLength = 0; + unsigned int nRemLen = length(); + TForteUInt32 nCodepoint; + int nRes; + + while(i < nRemLen){ + nRes = CUnicodeUtilities::parseUTF8Codepoint(pRunner, nCodepoint); + if(nRes < 0 || nRes + i > nRemLen) + return -1; + i += nRes; + pRunner += nRes; + // Skip the BOM if present + if(nCodepoint != CUnicodeUtilities::scm_unBOMMarker){ + nRes = CUnicodeUtilities::encodeUTF16Codepoint(0, 0, nCodepoint, false); + if(nRes < 0) + return -1; + nNeededLength += nRes; + } + } + + if(pa_pacBuffer == 0) + return nNeededLength; + + if(nNeededLength > pa_nBufferSize) + return -1; + + TForteByte *pEncRunner = pa_pacBuffer; + TForteByte *pDataEnd = pa_pacBuffer + nNeededLength; + + pRunner = (const TForteByte *) getValue(); + nRemLen = length(); + i = 0; + while(i < nRemLen){ + nRes = CUnicodeUtilities::parseUTF8Codepoint(pRunner, nCodepoint); + if(nRes < 0 || nRes + i > nRemLen) + return -1; + i += nRes; + pRunner += nRes; + if(nCodepoint != CUnicodeUtilities::scm_unBOMMarker){ + nRes = CUnicodeUtilities::encodeUTF16Codepoint(pEncRunner, static_cast(pDataEnd - pEncRunner), nCodepoint, false); + if(nRes < 0) + return -1; + pEncRunner += nRes; + } + } + + return static_cast(pEncRunner - pa_pacBuffer); +} + +int CIEC_WSTRING::fromString(const char *pa_pacValue){ + int nRetVal = 0; + if(0 == strncmp(pa_pacValue, "WSTRING#", 8)){ + pa_pacValue += 8; + nRetVal = 8; + } + + int nUTF8Result = fromUTF8(pa_pacValue, -1, (*pa_pacValue == '"')); + + return (-1 == nUTF8Result) ? -1 : (nRetVal + nUTF8Result); +} + +int CIEC_WSTRING::toString(char* pa_acValue, unsigned int pa_nBufferSize) const{ + return toUTF8(pa_acValue, pa_nBufferSize, true); +} + +int CIEC_WSTRING::fromUTF8(const char *pa_pacValue, int pa_nLen, bool pa_bUnescape){ + int nSrcLen = pa_nLen >= 0 ? pa_nLen : (pa_bUnescape ? determineEscapedStringLength(pa_pacValue, '"') : strlen(pa_pacValue)); + int nSrcCappedLength = nSrcLen; + + if(0 <= nSrcLen){ + if((0 == pa_pacValue) || (pa_pacValue[0] == '\0') || (nSrcLen == 0)){ + assign("", 0); + return 0; + } + + if(nSrcLen > static_cast(scm_unMaxStringLen)){ + // If we get a to large string we will truncate it + // This is a conservative guess + nSrcCappedLength = scm_unMaxStringLen; + DEVLOG_WARNING("Too large string, destination will be truncated!\n"); + } + + // The needed space is surely not larger than original length - it can + // only be smaller if there are chars outside the BMP + reserve(static_cast(nSrcCappedLength)); + if(0 == getGenData()){ + return -1; + } + + unsigned int nMaxWidth; + int nLength = CUnicodeUtilities::checkUTF8((const char *) pa_pacValue, nSrcCappedLength, nMaxWidth); + + // Only accept if this is valid UTF-8, otherwise we can get major + // problems when serializing + if(nLength < 0){ + DEVLOG_WARNING("Invalid UTF-8 string given to fromString!\n"); + *this = "***INVALID UTF-8***"; + return -1; + } + else if(nMaxWidth > 16){ + DEVLOG_WARNING("UTF-8 string with characters outside of BMP given to fromString!\n"); + } + + // If BMP, all is well - simply assign + if(nMaxWidth <= 16){ + assign(pa_pacValue, static_cast(nSrcCappedLength)); + } + else{ + TForteUInt32 nCodepoint; + const TForteByte *pRunner = (const TForteByte *) pa_pacValue; + TForteByte *pEncBuffer = (TForteByte *) getValue(); + TForteByte *pEncRunner = pEncBuffer; + + while(*pRunner && (pRunner - (const TForteByte *) pa_pacValue) < nSrcCappedLength){ + int nRes; + nRes = CUnicodeUtilities::parseUTF8Codepoint(pRunner, nCodepoint); + pRunner += nRes; + if(nCodepoint == CUnicodeUtilities::scm_unBOMMarker) + continue; + if(nCodepoint >= 0x10000) + nCodepoint = '?'; + nRes = CUnicodeUtilities::encodeUTF8Codepoint(pEncRunner, static_cast(nSrcCappedLength - (pEncRunner - pEncBuffer)), nCodepoint); + if(nRes < 1) + break; + pEncRunner += nRes; + } + + *pEncRunner = '\0'; + setLength(static_cast(pEncRunner - pEncBuffer)); + } + + if(pa_bUnescape){ + nLength = unescapeFromString(getValue(), '"'); + if(-1 == nLength){ + return -1; + } + } + } + return nSrcLen; +} + +int CIEC_WSTRING::toUTF8(char* pa_pacBuffer, unsigned int pa_nBufferSize, bool pa_bEscape) const{ + if((TForteUInt32) length() + (pa_bEscape ? 2 : 0) + 1 > pa_nBufferSize) + return -1; + + if(!pa_bEscape){ + memcpy(pa_pacBuffer, getValue(), length() + 1); + return length(); + } + + const char *pRunner; + char *pEncRunner = pa_pacBuffer; + char *pDataEnd = pa_pacBuffer + pa_nBufferSize; + int nRes; + + *pEncRunner++ = '\"'; + + pRunner = getValue(); + while(*pRunner){ + if(pa_bEscape) + nRes = dollarEscapeChar(pEncRunner, *pRunner, static_cast(pDataEnd - pEncRunner)); + else{ + *pEncRunner = *pRunner; + nRes = 1; + } + + if(nRes < 0) + return -1; + + pEncRunner += nRes; + ++pRunner; + } + + if(pDataEnd - pEncRunner < 2) + return -1; + + *pEncRunner++ = '\"'; + *pEncRunner = '\0'; + + return static_cast(pEncRunner - pa_pacBuffer); +} diff --git a/src/core/datatypes/forte_wstring.h b/src/core/datatypes/forte_wstring.h new file mode 100644 index 000000000..a1d25838f --- /dev/null +++ b/src/core/datatypes/forte_wstring.h @@ -0,0 +1,150 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 Profactor GmbH, ACIN, nxtControl GmbH, + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Ingomar Müller, Alois Zoitl, Ingo Hegny, Stanislav Meduna + * Martin Melik Merkumians, Matthias Plasch, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FORTE_WSTRING_H_ +#define _FORTE_WSTRING_H_ + +#include "forte_any_string.h" + +#ifdef FORTE_USE_WSTRING_DATATYPE + +/*!\ingroup COREDTS \brief CIEC_WSTRING represents the wide string data type according to IEC 61131. + * + * "wstring" is implemented like the "string" - the following first implementation + * "typedef std::basic_string TWSTRING; didn't work well" + */ +class CIEC_WSTRING : public CIEC_ANY_STRING{ + DECLARE_FIRMWARE_DATATYPE(WSTRING) + public: + CIEC_WSTRING(){ + } + + CIEC_WSTRING(const CIEC_WSTRING& pa_roValue) : + CIEC_ANY_STRING(){ + (*this) = pa_roValue.getValue(); + } + + CIEC_WSTRING(const char* pa_pacValue){ + (*this) = pa_pacValue; + } + + virtual ~CIEC_WSTRING(){ + } + + CIEC_WSTRING &operator =(const char* const pa_pacValue){ + CIEC_ANY_STRING::operator =(pa_pacValue); + return *this; + } + + /*! \brief Converts a UTF-8 encoded string to a WSTRING (ISO 10646 Row 00 internally) + * + * This command implements a conversion function from a UTF-8 + * encoded string (found e.g. in XML to the internal + * ISO 10646 Row 00 encoding. + * \param pa_pacBuffer Reference to the given UTF-8 encoded byte array + * \param pa_nLen Length to read (-1 for null-terminated) + * \param pa_bUnescape Handle $-escapes and delimiter characters at the beginning and end + * \return number of bytes used from srcString + * -1 on error + */ + virtual int fromUTF8(const char *pa_pacValue, int pa_nLen, bool pa_bUnescape); + + /*! \brief Converts the WSTRING to a UTF-8 representation + * + * This command implements a conversion function from a WSTRING + * to a UTF-8 encoding, usable e.g. for the serialization. + * \param pa_pacBuffer Reference to the output buffer. If 0, only the needed size will be computed. + * \param pa_nBufferSize Size of the provided buffer. + * \param pa_bEscape Produce $-escapes and delimiter characters at the beginning and end + * \return number of bytes used in the buffer + * -1 on error + */ + virtual int toUTF8(char* pa_pacBuffer, unsigned int pa_nBufferSize, bool pa_bEscape) const; + + /*! \brief Converts a UTF-16 encoded string to a WSTRING (UTF-8 internally) + * + * This command implements a conversion function from a UTF-16 + * encoded string (found e.g. in serialized WSTRING type) to the internal + * UTF-8 encoding. + * \param pa_pacBuffer Reference to the given UTF-16 encoded byte array + * \param pa_nBufferLen Length of the provided byte array + * \return Can be the following response: + * - false....conversion was not successful - something went wrong! + * - true....conversion was successful. + */ + bool fromUTF16(const TForteByte *pa_pacBuffer, unsigned int pa_nBufferLen); + + /*! \brief Converts the WSTRING to a UTF-16 representation + * + * This command implements a conversion function from a WSTRING + * to a big-endian UTF-16 encoding, usable e.g. for the serialization. + * \param pa_pacBuffer Reference to the output buffer. If 0, only the needed size will be computed. + * \param pa_nBufferSize Size of the provided buffer. + * \return number of bytes used in the buffer + * -1 on error + */ + int toUTF16(TForteByte* pa_pacBuffer, unsigned int pa_nBufferSize) const; + + virtual EDataTypeID getDataTypeID() const{ + return CIEC_ANY::e_WSTRING; + } + + virtual void setValue(const CIEC_ANY& pa_roValue){ + if(pa_roValue.getDataTypeID() == CIEC_ANY::e_WSTRING){ + const CIEC_WSTRING &roSrc(static_cast(pa_roValue)); + this->assign(roSrc.getValue(), roSrc.length()); + } + } + + /*! \brief Converts string value to data type value + * + * This command implements a conversion function from IEC61131 + * data type (string format) to a C++ conform type. + * This function is necessary for communication with a proper engineering system. + * It is expecting a UTF-8 string and will check whether its content is constrained + * to the basic multilingual plane. + * \param pa_pacValue string buffer + * \return number of bytes taken used from the buffer + * -1 on on error + */ + virtual int fromString(const char *pa_pacValue); + + /*! \brief Converts data type value to string + * + * This command implements a conversion function from C++ data type + * to IEC61131 conform data type (string format). + * This function is necessary for communication with a proper engineering system. + * \param pa_acValue Pointer to char-array for the result + * \param pa_nBufferSize Size of the buffer + * \return number of bytes used in the buffer without trailing 0x00 + * -1 on error + */ + virtual int toString(char* pa_acValue, unsigned int pa_nBufferSize) const; + + protected: + + private: +}; + +inline +bool operator ==(const CIEC_WSTRING &pa_roLeft, const CIEC_WSTRING &pa_roRight){ + return (0 == strcmp(pa_roLeft.getValue(), pa_roRight.getValue())); +} + +inline +bool operator !=(const CIEC_WSTRING &pa_roLeft, const CIEC_WSTRING &pa_roRight){ + return !(pa_roLeft == pa_roRight); +} + +#endif + +#endif /*_FORTE_WSTRING_H_*/ diff --git a/src/core/datatypes/unicode_utils.cpp b/src/core/datatypes/unicode_utils.cpp new file mode 100644 index 000000000..3744c39a6 --- /dev/null +++ b/src/core/datatypes/unicode_utils.cpp @@ -0,0 +1,205 @@ +/******************************************************************************* + * Copyright (c) 2011 nxtControl GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Ingo Hegny, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "unicode_utils.h" +#include + +const TForteUInt32 CUnicodeUtilities::scm_unBOMMarker = 0xfeff; +const TForteUInt32 CUnicodeUtilities::scm_unBOMMarkerSwapped = 0xfffe; + +/* RFC 3629 + Char. number range | UTF-8 octet sequence + (hexadecimal) | (binary) + --------------------+--------------------------------------------- + 0000 0000-0000 007F | 0xxxxxxx + 0000 0080-0000 07FF | 110xxxxx 10xxxxxx + 0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx + 0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx +*/ +int CUnicodeUtilities::parseUTF8Codepoint(const TForteByte *pa_pacCodepoint, TForteUInt32 &pa_rValue) { + if ((pa_pacCodepoint[0] & 0x80) == 0) { + pa_rValue = (pa_pacCodepoint[0] & 0x7f); + return 1; + } else if ((pa_pacCodepoint[0] & 0xe0) == 0xc0) { + if ((pa_pacCodepoint[1] & 0xc0) != 0x80) + return -1; + pa_rValue = ((pa_pacCodepoint[0] & 0x1f) << 6) | + ((pa_pacCodepoint[1] & 0x3f) ); + return 2; + } else if ((pa_pacCodepoint[0] & 0xf0) == 0xe0) { + if ((pa_pacCodepoint[1] & 0xc0) != 0x80 || + (pa_pacCodepoint[2] & 0xc0) != 0x80) + return -1; + pa_rValue = ((pa_pacCodepoint[0] & 0x0f) << 12) | + ((pa_pacCodepoint[1] & 0x3f) << 6) | + ((pa_pacCodepoint[2] & 0x3f) ); + return 3; + } else if ((pa_pacCodepoint[0] & 0xf8) == 0xf0) { + if ((pa_pacCodepoint[1] & 0xc0) != 0x80 || + (pa_pacCodepoint[2] & 0xc0) != 0x80 || + (pa_pacCodepoint[3] & 0xc0) != 0x80) + return -1; + pa_rValue = ((pa_pacCodepoint[0] & 0x07) << 18) | + ((pa_pacCodepoint[1] & 0x3f) << 12) | + ((pa_pacCodepoint[2] & 0x3f) << 6) | + ((pa_pacCodepoint[3] & 0x3f) ); + return 4; + } + + pa_rValue = 0; + return -1; +} + +int CUnicodeUtilities::encodeUTF8Codepoint(TForteByte *pa_pacCodepoint, unsigned int pa_nBufferSize, TForteUInt32 pa_nValue) { + if (pa_nValue < 0x80) { + if (pa_pacCodepoint) { + if (pa_nBufferSize < 1) + return -1; + pa_pacCodepoint[0] = (TForteByte) pa_nValue; + } + return 1; + } else if (pa_nValue < 0x800) { + if (pa_pacCodepoint) { + if (pa_nBufferSize < 2) + return -1; + pa_pacCodepoint[0] = (TForteByte) (0xc0 | ((pa_nValue >> 6) & 0x1f)); + pa_pacCodepoint[1] = (TForteByte) (0x80 | ((pa_nValue ) & 0x3f)); + } + return 2; + } else if (pa_nValue < 0x10000) { + if (pa_pacCodepoint) { + if (pa_nBufferSize < 3) + return -1; + pa_pacCodepoint[0] = (TForteByte) (0xe0 | ((pa_nValue >> 12) & 0x1f)); + pa_pacCodepoint[1] = (TForteByte) (0x80 | ((pa_nValue >> 6) & 0x3f)); + pa_pacCodepoint[2] = (TForteByte) (0x80 | ((pa_nValue ) & 0x3f)); + } + return 3; + } else if (pa_nValue < 0x110000) { + if (pa_pacCodepoint) { + if (pa_nBufferSize < 4) + return -1; + pa_pacCodepoint[0] = (TForteByte) (0xf0 | ((pa_nValue >> 18) & 0x1f)); + pa_pacCodepoint[1] = (TForteByte) (0x80 | ((pa_nValue >> 12) & 0x3f)); + pa_pacCodepoint[2] = (TForteByte) (0x80 | ((pa_nValue >> 6) & 0x3f)); + pa_pacCodepoint[3] = (TForteByte) (0x80 | ((pa_nValue ) & 0x3f)); + } + return 4; + } + + return -1; +} + +/* + * UTF-16 converts > 0xffff into two 16-bit code units, called a surrogate pair, by the following scheme: + * + * 0x10000 is subtracted from the code point, leaving a 20 bit number in the range 0..0xFFFFF. + * The top ten bits (a number in the range 0..0x3FF) are added to 0xD800 to give the first code unit + * or high surrogate, which will be in the range 0xD800..0xDBFF. + * The low ten bits (also in the range 0..0x3FF) are added to 0xDC00 to give the second + * code unit or low surrogate, which will be in the range 0xDC00..0xDFFF. +*/ +int CUnicodeUtilities::parseUTF16Codepoint(const TForteByte *pa_pacCodepoint, TForteUInt32 &pa_rValue, bool pa_bLittleEndian) { + TForteUInt16 nFirstWord = static_cast(pa_bLittleEndian ? + (pa_pacCodepoint[0] | (pa_pacCodepoint[1] << 8)) : + ((pa_pacCodepoint[0] << 8) | pa_pacCodepoint[1])); + + if ((nFirstWord & 0xfc00) == 0xd800) { + TForteUInt16 nSecondWord = static_cast(pa_bLittleEndian ? + (pa_pacCodepoint[2] | (pa_pacCodepoint[3] << 8)) : + ((pa_pacCodepoint[2] << 8) | pa_pacCodepoint[3])); + + if ((nSecondWord & 0xfc00) != 0xdc00) + return -1; + + pa_rValue = 0x10000 + (((nFirstWord & 0x3ff) << 10) | (nSecondWord & 0x3ff)); + + return 4; + } + + pa_rValue = nFirstWord; + + return 2; +} + + +int CUnicodeUtilities::encodeUTF16Codepoint(TForteByte *pa_pacCodepoint, unsigned int pa_nBufferSize, TForteUInt32 pa_nValue, bool pa_bLittleEndian) { + if ((pa_nValue >= 0xd800 && pa_nValue < 0xe000) || pa_nValue >= 0x110000) + return -1; + + if (pa_nValue < 0x10000) { + if (pa_pacCodepoint) { + if (pa_nBufferSize < 2) + return -1; + if (pa_bLittleEndian) { + pa_pacCodepoint[0] = (TForteByte) ((pa_nValue ) & 0xff); + pa_pacCodepoint[1] = (TForteByte) ((pa_nValue >> 8) & 0xff); + } else { + pa_pacCodepoint[0] = (TForteByte) ((pa_nValue >> 8) & 0xff); + pa_pacCodepoint[1] = (TForteByte) ((pa_nValue ) & 0xff); + } + } + return 2; + } else { + if (pa_pacCodepoint) { + TForteUInt32 nVal = pa_nValue - 0x10000; + TForteUInt16 nHighSurrogate = static_cast(0xd800 | ((nVal >> 10) & 0x3ff)); + TForteUInt16 nLowSurrogate = static_cast(0xdc00 | ((nVal ) & 0x3ff)); + + if (pa_nBufferSize < 4) + return -1; + + if (pa_bLittleEndian) { + pa_pacCodepoint[0] = (TForteByte) ((nHighSurrogate ) & 0xff); + pa_pacCodepoint[1] = (TForteByte) ((nHighSurrogate >> 8) & 0xff); + pa_pacCodepoint[2] = (TForteByte) ((nLowSurrogate ) & 0xff); + pa_pacCodepoint[3] = (TForteByte) ((nLowSurrogate >> 8) & 0xff); + } else { + pa_pacCodepoint[0] = (TForteByte) ((nHighSurrogate >> 8) & 0xff); + pa_pacCodepoint[1] = (TForteByte) ((nHighSurrogate ) & 0xff); + pa_pacCodepoint[2] = (TForteByte) ((nLowSurrogate >> 8) & 0xff); + pa_pacCodepoint[3] = (TForteByte) ((nLowSurrogate ) & 0xff); + } + } + return 4; + } +} + +int CUnicodeUtilities::checkUTF8(const char *pa_pacValue, int pa_nLength, unsigned int &pa_rnMaxWidth) { + const TForteByte *pRunner = (const TForteByte *) pa_pacValue; + size_t nRemLen = (pa_nLength == -1) ? strlen(pa_pacValue) : (size_t) pa_nLength; + TForteUInt32 nCodepoint; + int nRes; + int nRetVal = 0; + size_t i = 0; + pa_rnMaxWidth = 7; + + while (i < nRemLen) { + nRes = parseUTF8Codepoint(pRunner, nCodepoint); + if (nRes < 0 || nRes + i > nRemLen) { + return -1; + } + if (nCodepoint != CUnicodeUtilities::scm_unBOMMarker) { + if (nCodepoint >= 0x10000) + pa_rnMaxWidth = 21; + else if (nCodepoint >= 0x100 && pa_rnMaxWidth < 16) + pa_rnMaxWidth = 16; + else if (nCodepoint >= 0x80 && pa_rnMaxWidth < 8) + pa_rnMaxWidth = 8; + } + + i += nRes; + pRunner += nRes; + ++nRetVal; + } + + return nRetVal; +} diff --git a/src/core/datatypes/unicode_utils.h b/src/core/datatypes/unicode_utils.h new file mode 100644 index 000000000..d56ff2836 --- /dev/null +++ b/src/core/datatypes/unicode_utils.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011 nxtControl GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _UNICODE_UTILS_H_ +#define _UNICODE_UTILS_H_ + +#include "../../arch/datatype.h" + +/*!\ingroup COREDTS CUnicodeUtilities is a collection of utility methods managing Unicode processing. + */ + +/*!\ingroup CORE \defgroup COREDTS Core Data Types + * \brief Unicode processing. + * + */ + +class CUnicodeUtilities { + public: + static const TForteUInt32 scm_unBOMMarker; + static const TForteUInt32 scm_unBOMMarkerSwapped; + + /*! \brief Parse a UTF-8 codepoint + * + * \param pa_pacCodepoint Codepoint to parse + * \param pa_rValue Parsed value + * \return Number of bytes consumed or -1 for error + */ + static int parseUTF8Codepoint(const TForteByte *pa_pacCodepoint, TForteUInt32 &pa_rValue); + + /*! \brief Encode a UTF-8 codepoint + * + * \param pa_pacCodepoint Pointer to the codepoint (0 for no output) + * \param pa_nBufferSize Size of the provided buffer. + * \param pa_nValue Input value + * \return Number of bytes produced or -1 for error + */ + static int encodeUTF8Codepoint(TForteByte *pa_pacCodepoint, unsigned int pa_nBufferSize, TForteUInt32 pa_nValue); + + /*! \brief Parse a UTF-16 codepoint + * + * \param pa_pacCodepoint Codepoint to parse + * \param pa_rValue Parsed value + * \param pa_bLittleEndian Endianess to use + * \return Number of bytes consumed or -1 for error + */ + static int parseUTF16Codepoint(const TForteByte *pa_pacCodepoint, TForteUInt32 &pa_rValue, bool pa_bLittleEndian); + + /*! \brief Encode a UTF-16 codepoint + * + * \param pa_pacCodepoint Pointer to the codepoint (0 for no output) + * \param pa_nBufferSize Size of the provided buffer. + * \param pa_nValue Input value + * \param pa_bLittleEndian Endianess to use + * \return Number of bytes produced or -1 for error + */ + static int encodeUTF16Codepoint(TForteByte *pa_pacCodepoint, unsigned int pa_nBufferSize, TForteUInt32 pa_nValue, bool pa_bLittleEndian); + + /*! \brief Check whether a given string is a valid UTF-8 string + * + * \param pa_pacString String to check + * \param pa_nLength Length of the string to check (use -1 for null-terminated strings) + * \param pa_rnMaxWidth Returns the max. width of the codepoint (BOM is not considered). + * 7 ... IRV (ASCII) + * 8 ... Row 00 only + * 16 ... Basic Multilingual Plane only (UCS-2) + * 21 ... Rest of UTF-8 (and UTF-16) representable codepoints + * \return Number of codepoints in string or -1 for invalid input + */ + static int checkUTF8(const char *pa_pacValue, int pa_nLength, unsigned int &pa_rnMaxWidth); +}; + +#endif /*_UNICODE_UTILS_H_*/ diff --git a/src/core/devexec.cpp b/src/core/devexec.cpp new file mode 100644 index 000000000..a5e2c1e54 --- /dev/null +++ b/src/core/devexec.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2012 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "devexec.h" +#include "esfb.h" +#include "../arch/timerha.h" +#include "ecet.h" +#include "extevhan.h" + + + +CDeviceExecution::CDeviceExecution(): + m_nNumberofExternalEventHandler(0){ + CExternalEventHandler::setDeviceExecution(this); // let all the external event handlers know where to report events to + CTimerHandler::createTimerHandler(); + CTimerHandler::sm_poFORTETimer->enableHandler(); // will result in an registration for the timer handler (automatically it will be the first registration) +} + +CDeviceExecution::~CDeviceExecution(){ + delete CTimerHandler::sm_poFORTETimer; + CTimerHandler::sm_poFORTETimer = 0; +}; + +int CDeviceExecution::registerExternalEventHandler(CExternalEventHandler *pa_poHandler){ + int retval = -1; + if(cg_MaxRegisteredEventHandlers > m_nNumberofExternalEventHandler){ + retval = m_nNumberofExternalEventHandler; + m_astRegisteredEventHandlers[retval].m_poHandler = pa_poHandler; + m_astRegisteredEventHandlers[retval].m_bOccured = false; + ++m_nNumberofExternalEventHandler; + } + return retval; +} + +void CDeviceExecution::startNewEventChain(CEventSourceFB *pa_poECStartFB){ + // maybe in the future here has to be added something for handling priority adaption and stuff like this. + if(0 != pa_poECStartFB){ + CEventChainExecutionThread *poEventChainExecutor = pa_poECStartFB->getEventChainExecutor(); + if(0 != poEventChainExecutor){ + poEventChainExecutor->startEventChain(pa_poECStartFB->getEventSourceEventEntry()); + } + // TODO add log output if one if these two ifs is not met + } +} + diff --git a/src/core/devexec.h b/src/core/devexec.h new file mode 100644 index 000000000..f68c79c35 --- /dev/null +++ b/src/core/devexec.h @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2011 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _DEVEXEC_H +#define _DEVEXEC_H + + +const int cg_MaxRegisteredEventHandlers = 10; + +class CEventSourceFB; +class CExternalEventHandler; +struct SForteTime; + +/**\ingroup CORE + Handles all the IEC 61499 execution requests and aspects within one device + + @author az +*/ +class CDeviceExecution{ + private: +/*!\brief Structure for holding the information belonging to one external event. + * + */ + struct SEventHandlerElement{ + bool m_bOccured; //! +#include "device.h" +#include "resource.h" +#include "if2indco.h" + +EMGMResponse CDevice::executeMGMCommand(forte::core::SManagementCMD &pa_oCommand){ + EMGMResponse retval = e_INVALID_DST; + + if(CStringDictionary::scm_nInvalidStringId == pa_oCommand.mDestination){ + retval = CResource::executeMGMCommand(pa_oCommand); + } + else{ + CResource *res = (CResource *)CFBContainer::getFB(pa_oCommand.mDestination); + if(0 != res){ + pa_oCommand.mDestination = CStringDictionary::scm_nInvalidStringId; + retval = res->executeMGMCommand(pa_oCommand); + } + } + return retval; +} + + diff --git a/src/core/device.h b/src/core/device.h new file mode 100644 index 000000000..2650d06a8 --- /dev/null +++ b/src/core/device.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _DEVICE_H +#define _DEVICE_H + +#include "resource.h" +#include "devexec.h" + +/*!\ingroup CORE CDevice represents a device according to IEC 61499. CDevice contains + - one or more IEC 61499 compliant resources (CResource), + - a device management (CDeviceAdministrator) + - a function block execution environment (CFBNExecution) + - a library (CTypeLib) which administrates the types the 1499 device is + capable of + - External event interface for handling interrupts and other external notifications. + - FORTE-HAL: FORTE Hardware Abstraction Layer + + There are different device type's available (e.g. remote device RMT_DEV) + for different tasks which have different device configurations + (resources function blocks) and device parameters. +*/ +class CDevice : public CResource{ + private: +/*! \brief + * + */ + CDeviceExecution m_oDeviceExecution; + + protected: + virtual void executeEvent(int ){}; + + public: +/*! \brief Sets up all the necessary data and classes necessary for execution. + * + */ + CDevice(const SFBInterfaceSpec *pa_pstInterfaceSpec, const CStringDictionary::TStringId pa_nInstanceNameId, + TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData): + CResource(pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData), + m_oDeviceExecution(){ + }; + virtual ~CDevice(){}; + + virtual CStringDictionary::TStringId getFBTypeId(void) const { return CStringDictionary::scm_nInvalidStringId; }; + +/*! \brief Starts to execute FBNs. + * + * This function will send a IEC 61499 start command to all existing resources in the device (if any). + * The function will return after the start. The Forte HAL has to ensure that it is waited till the device + * finishes its execution. + * \return 0 on success -1 on error + */ + virtual int startDevice(void){ + changeFBExecutionState(cg_nMGM_CMD_Start); + return 1; + }; +/*!\brief Execute the given management command + * + * Evaluates the m_sDestination parameter of the command if empty this class tries to execute the management command if not + * the referenced resource is called for handling the command. + * \param pa_oCommand FORTE internal representation of the management command + * \return response of the MGMCommand execution as defined in IEC 61499 + */ + virtual EMGMResponse executeMGMCommand(forte::core::SManagementCMD &pa_oCommand); + +//! Retrieve the device execution of this device + CDeviceExecution &getDeviceExecution(void) {return m_oDeviceExecution; }; +}; + +#endif diff --git a/src/core/ecet.cpp b/src/core/ecet.cpp new file mode 100644 index 000000000..8236c3398 --- /dev/null +++ b/src/core/ecet.cpp @@ -0,0 +1,157 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Gerhard Ebenhofer, Ingo Hegny + * Micheal Hofmann + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include "ecet.h" +#include "esfb.h" +#include "utils/criticalregion.h" + +CEventChainExecutionThread::CEventChainExecutionThread() : + CThread(), mProcessingEvents(false){ + clear(); +} + +CEventChainExecutionThread::~CEventChainExecutionThread(){ +} + +void CEventChainExecutionThread::run(void){ + while(isAlive()){ //thread is allowed to execute + if(externalEventOccured()){ + transferExternalEvents(); + } + if(m_pstEventListEnd == m_pstEventListStart){ + mProcessingEvents = false; + selfSuspend(); + mProcessingEvents = true; //set this flag here to true as well in case the suspend just went through and processing was not finished + } + else{ + if(0 != *m_pstEventListStart){ + (*m_pstEventListStart)->mFB->receiveInputEvent((*m_pstEventListStart)->mPortId, *this); + } + *m_pstEventListStart = 0; + + if(m_pstEventListStart == &m_astEventList[0]){ + //wrap the ringbuffer + m_pstEventListStart = &m_astEventList[cg_nEventChainEventListSize - 1]; + } + else{ + m_pstEventListStart--; + } + } + } +} + +void CEventChainExecutionThread::clear(void){ + memset(m_astEventList, 0, cg_nEventChainEventListSize * sizeof(TEventEntryPtr)); + m_pstEventListEnd = m_pstEventListStart = &m_astEventList[cg_nEventChainEventListSize - 1]; + + { + CCriticalRegion criticalRegion(m_oExternalEventListSync); + memset(m_astExternalEventList, 0, cg_nEventChainExternalEventListSize * sizeof(TEventEntryPtr)); + m_pstExternalEventListEnd = m_pstExternalEventListStart = &m_astExternalEventList[cg_nEventChainExternalEventListSize - 1]; + } +} + +void CEventChainExecutionThread::transferExternalEvents(){ + CCriticalRegion criticalRegion(m_oExternalEventListSync); + //this while is built in a way that it checks also if we got here by accident + while(m_pstExternalEventListStart != m_pstExternalEventListEnd){ + if(0 != *m_pstExternalEventListStart){ + //add only valid entries + addEventEntry(*m_pstExternalEventListStart); + *m_pstExternalEventListStart = 0; + + if(m_pstExternalEventListStart == &m_astExternalEventList[0]){ + //wrap the ringbuffer + m_pstExternalEventListStart = &m_astExternalEventList[cg_nEventChainExternalEventListSize - 1]; + } + else{ + m_pstExternalEventListStart--; + } + } + } +} + +void CEventChainExecutionThread::startEventChain(SEventEntry *pa_poEventToAdd){ + FORTE_TRACE("CEventChainExecutionThread::startEventChain\n"); + { + CCriticalRegion criticalRegion(m_oExternalEventListSync); + if(0 == *m_pstExternalEventListEnd){ + *m_pstExternalEventListEnd = pa_poEventToAdd; + TEventEntryPtr* pstNextEventListElem; + + if(m_pstExternalEventListEnd == &m_astExternalEventList[0]){ + //wrap the ringbuffer + pstNextEventListElem = &m_astExternalEventList[cg_nEventChainExternalEventListSize - 1]; + } + else{ + pstNextEventListElem = (m_pstExternalEventListEnd - 1); + } + + if(m_pstExternalEventListStart != pstNextEventListElem){ + //the list is not full + m_pstExternalEventListEnd = pstNextEventListElem; + } + } + else{ + DEVLOG_ERROR("External event queue is full, external event dropped!\n"); + } + } // End critical region + + mProcessingEvents = true; + resumeSelfSuspend(); +} + +void CEventChainExecutionThread::addEventEntry(SEventEntry *pa_poEventToAdd){ + if(0 == *m_pstEventListEnd){ + *m_pstEventListEnd = pa_poEventToAdd; + TEventEntryPtr* pstNextEventListElem; + + if(m_pstEventListEnd == &m_astEventList[0]){ + //wrap the ringbuffer + pstNextEventListElem = &m_astEventList[cg_nEventChainEventListSize - 1]; + } + else{ + pstNextEventListElem = (m_pstEventListEnd - 1); + } + + if(m_pstEventListStart != pstNextEventListElem){ + //the list is not full + m_pstEventListEnd = pstNextEventListElem; + } + } + else{ + DEVLOG_ERROR("Event queue is full, event dropped!\n"); + } +} + +void CEventChainExecutionThread::changeExecutionState(EMGMCommandType pa_unCommand){ + switch (pa_unCommand){ + case cg_nMGM_CMD_Start: + if(!isAlive()){ + //only start the thread when we are not already running + start(); + } + break; + case cg_nMGM_CMD_Kill: + clear(); + end(); + break; + case cg_nMGM_CMD_Stop: + end(); + break; + default: + break; + } +} + diff --git a/src/core/ecet.h b/src/core/ecet.h new file mode 100644 index 000000000..ed376d2d9 --- /dev/null +++ b/src/core/ecet.h @@ -0,0 +1,127 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gunnar Grabmaier, Thomas Strasser, Rene Smodic, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ECET_H_ +#define _ECET_H_ + +#include "eventconn.h" +#include "event.h" +#include "datatypes/forte_time.h" +#include +#include + +class CEventSourceFB; + +/*! \ingroup CORE\brief Class for executing one event chain. + * + */ +class CEventChainExecutionThread : public CThread{ + public: + CEventChainExecutionThread(); + virtual ~CEventChainExecutionThread(); + + /*!\brief Start the a new event chain with the given event. + * + * + * \param pa_poEventToAdd event of the EC to start + */ + void startEventChain(SEventEntry *pa_poEventToAdd); + + /*!\brief Add an new event entry to the event chain + * + * \param pa_poEventToAdd new event entry + */ + void addEventEntry(SEventEntry *pa_poEventToAdd); + + /*!\brief allow to start, stop, and kill the execution of the event chain execution thread + * + * @param pa_unCommand the management command to be executed + */ + void changeExecutionState(EMGMCommandType pa_unCommand); + + void joinEventChainExecutionThread(){ + CThread::join(); + } + + void setDeadline(const CIEC_TIME &pa_roVal){ + CThread::setDeadline(pa_roVal); + } + + bool isProcessingEvents() const { + return mProcessingEvents; + } + + protected: + //@{ + /*! \brief List of input events to deliver. + * + * This list stores the necessary information for all events to deliver that occurred within this event chain. + */ + + TEventEntryPtr m_astEventList[cg_nEventChainEventListSize]; + TEventEntryPtr* m_pstEventListStart; + TEventEntryPtr* m_pstEventListEnd; + //@} + + private: + /*! \brief The thread run()-method where the events are sent to the FBs and the FBs are executed in. + * + * If there is an entry in the Event List the event will be delivered and the FB executed. + * If there is no entry in this list the CEventChainExecutionThread will suspend itself and remove itself from the + * active EventChainExecutionlist in CFBNExecution. + * \return true if thread execution ended successfully + */ + virtual void run(void); + + /*! \brief Clear the event chain. + */ + void clear(void); + + bool externalEventOccured(){ + /* we should not need a protection here as we are just comparing the both + * the only value that could change during the compare is m_pstExternalEventListEnd. In the worst case + * this results in a to early or to late detection. However as the transfer is protected this should be no + * big issue. + * TODO perform test to verify this assumption + */ + return (m_pstExternalEventListStart != m_pstExternalEventListEnd); + } + + //! Transfer elements stored in the external event list to the main event list + void transferExternalEvents(); + + //@{ + /*! \brief List of external events that occurred during one FB's execution + * + * This list stores external events that may have occurred during the execution of a FB or during when the + * Event-Chain execution was sleeping. with this second list we omit the need for a mutex protection of the event + * list. This is a great performance gain. + */ + TEventEntryPtr m_astExternalEventList[cg_nEventChainExternalEventListSize]; + TEventEntryPtr* m_pstExternalEventListStart; + TEventEntryPtr* m_pstExternalEventListEnd; + //@} + + //! SyncObject for protecting the list in regard to several accesses + CSyncObject m_oExternalEventListSync; + + /*! \brief Flag indicating if this event chain execution thread is currently processing any events + * + * Initially this flag is false. + * This flag is activated when a new event chain is started and deactivated when the event queue is empty. + * + * Currently this flag is only needed for the FB tester. + * TODO consider surrounding the usage points of this flag with #defines such that it is only used for testing. + */ + bool mProcessingEvents; +}; + +#endif /*ECET_H_*/ diff --git a/src/core/esfb.h b/src/core/esfb.h new file mode 100644 index 000000000..51375cf2f --- /dev/null +++ b/src/core/esfb.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _ESFB_H_ +#define _ESFB_H_ + +#include "funcbloc.h" + +/*!\ingroup CORE\brief Base-Class for all event sources. + */ +class CEventSourceFB : public CFunctionBlock{ +private: + +/* \brief the event chain executor used by this ES. + */ + CEventChainExecutionThread *m_poEventChainExecutor; + SEventEntry mEventSourceEventEntry; //! the event entry to start the event chain + +public: + CEventSourceFB(CResource *pa_poSrcRes, + const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) : + CFunctionBlock(pa_poSrcRes, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData), + m_poEventChainExecutor(0), + mEventSourceEventEntry(this, cg_nExternalEventID){ + } + virtual ~CEventSourceFB() {}; + void setEventChainExecutor(CEventChainExecutionThread *pa_poEventChainExecutor) { m_poEventChainExecutor = pa_poEventChainExecutor; }; + CEventChainExecutionThread * getEventChainExecutor(void) { return m_poEventChainExecutor; }; + + SEventEntry *getEventSourceEventEntry(void) { return &mEventSourceEventEntry; }; +}; + +#define EVENT_SOURCE_FUNCTION_BLOCK_CTOR(fbclass) \ + fbclass(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : \ + CEventSourceFB( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData) + +#endif /*_ESFB_H_*/ diff --git a/src/core/event.h b/src/core/event.h new file mode 100644 index 000000000..d65dab748 --- /dev/null +++ b/src/core/event.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gunnar Grabmaier, Thomas Strasser, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _EVENT_H_ +#define _EVENT_H_ + +#include "../arch/datatype.h" + + +//forward declaration of a few classes to reduce includefile dependencies +class CFunctionBlock; + +struct SConnectionPoint; + +/*! \ingroup CORE\brief Datatype for holding the IDs of event inputs. + * + * With the current implementation at max 255 event inputs per FB are possible. + * That should be enough. + */ +typedef TForteUInt8 TEventID; + +//!\ingroup CORE Constant for the invalid event input id +const TEventID cg_nInvalidEventID = cg_unInvalidPortId; +//!\ingroup CORE Constant for the invalid event input id +const TEventID cg_nExternalEventID = 254; + +//!\brief With this marker events are anotated that are from the internals of a CFB to the interface of the CFB +const TPortId cgInternal2InterfaceMarker = 0x100; + +const TPortId cgInternal2InterfaceRemovalMask = 0xFF; + +/*!\ingroup CORE \brief Structure to hold the information needed for delivering input events to FBs. +*/ +typedef SConnectionPoint SEventEntry; + +typedef SEventEntry *TEventEntryPtr; + +#endif /*_EVENT_H_*/ diff --git a/src/core/eventconn.cpp b/src/core/eventconn.cpp new file mode 100644 index 000000000..2fbe3ba26 --- /dev/null +++ b/src/core/eventconn.cpp @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "eventconn.h" +#include "ecet.h" +#include "funcbloc.h" + +CEventConnection::CEventConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId) : + CConnection(paSrcFB, paSrcPortId){ +} + +CEventConnection::~CEventConnection(){ +} + +EMGMResponse CEventConnection::connect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retval = e_NO_SUCH_OBJECT; + TPortId nEIID = paDstFB->getEIID(paDstPortNameId); + + if(cg_nInvalidEventID != nEIID){ + retval = CConnection::addDestination(SConnectionPoint(paDstFB, nEIID)); + } + return retval; +} + +EMGMResponse CEventConnection::connectToCFBInterface(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retval = e_NO_SUCH_OBJECT; + TPortId nEOID = paDstFB->getEOID(paDstPortNameId); + + if(cg_nInvalidEventID != nEOID){ + nEOID |= cgInternal2InterfaceMarker; + retval = CConnection::addDestination(SConnectionPoint(paDstFB, nEOID)); + } + return retval; +} + + + +#ifndef FORTE_CLASS_0 +EMGMResponse CEventConnection::disconnect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId){ + EMGMResponse retval = e_NO_SUCH_OBJECT; + TEventID nEIID = paDstFB->getEIID(paDstPortNameId); + + if(cg_nInvalidEventID != nEIID){ + retval = CConnection::removeDestination(SConnectionPoint(paDstFB, nEIID)); + } + return retval; +} +#endif + +void CEventConnection::triggerEvent(CEventChainExecutionThread &pa_poExecEnv){ + for(TDestinationIdList::Iterator it = mDestinationIds.begin(); + 0 != it.getPosition(); ++it){ + pa_poExecEnv.addEventEntry(&(*it)); + } +} + + diff --git a/src/core/eventconn.h b/src/core/eventconn.h new file mode 100644 index 000000000..ee5e50c9a --- /dev/null +++ b/src/core/eventconn.h @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _EVENCONN_H_ +#define _EVENCONN_H_ + +#include "conn.h" +#include "event.h" +#include "fortelist.h" + +class CEventChainExecutionThread; + +/*!\ingroup CORE \brief Class for handling an event connection. + * + */ +class CEventConnection : public CConnection{ + public: + CEventConnection(CFunctionBlock *paSrcFB, TPortId paSrcPortId); + + virtual ~CEventConnection(); + + virtual EMGMResponse connect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); + + virtual EMGMResponse connectToCFBInterface(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); + +#ifndef FORTE_CLASS_0 + virtual EMGMResponse disconnect(CFunctionBlock *paDstFB, CStringDictionary::TStringId paDstPortNameId); +#endif + + /*! \brief Triggers the event connection and all destinations are notified. + * + * + * \param pa_poExecEnv Pointer to the execution environment the event is sent in. + */ + void triggerEvent(CEventChainExecutionThread &pa_poExecEnv); + protected: + + private: + +}; + +typedef CEventConnection *TEventConnectionPtr; + +#endif /*_EVENCONN_H_*/ diff --git a/src/core/extevhan.cpp b/src/core/extevhan.cpp new file mode 100644 index 000000000..a1ccecde0 --- /dev/null +++ b/src/core/extevhan.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "extevhan.h" +#include "devexec.h" +#include + +CDeviceExecution *CExternalEventHandler::sm_poDeviceExecution = 0; + +CExternalEventHandler::CExternalEventHandler() : + m_nExtEvHandID(-1){ + // register at the device Execution + m_nExtEvHandID = sm_poDeviceExecution->registerExternalEventHandler(this); +} + +bool CExternalEventHandler::isAllowed(){ + return getDeviceExecution()->extEvHandlerIsAllowed(m_nExtEvHandID); +} + +void CExternalEventHandler::startNewEventChain(CEventSourceFB *pa_poECStartFB){ + if(isAllowed()){ + FORTE_TRACE("Starting EC\n"); + getDeviceExecution()->startNewEventChain(pa_poECStartFB); + } + else{ + //TODO: handle this !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + DEVLOG_DEBUG("Starting EC NOT ALLOWED !!!!!!!!!!!!!!!1\n"); + } +} diff --git a/src/core/extevhan.h b/src/core/extevhan.h new file mode 100644 index 000000000..442761e72 --- /dev/null +++ b/src/core/extevhan.h @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _EXTEVHAN_H_ +#define _EXTEVHAN_H_ + +class CDeviceExecution; +class CEventSourceFB; + +/** \defgroup FORTE_HAL FORTE Hardware Abstraction Layer - FORTE-HAL + * \brief The FORTE-HAL is the abstraction of HW dependent features important + * and needed in each port of FORTE. + */ +/*@{*/ + +/**\defgroup EXTEVHAND External Event Handling + */ +/*@{*/ + +/*! \brief Baseclass for handling incoming interrupts and similar external events. + * + * Implementations of such classes should provide the following functions for ES-FBs: + * - registerFB(CFunctionBlock *pa_poESFB, ...) allows the ES-FB to register to this ExternalEventHandler for recieving external + * events (e.g. INIT+). the specific parameters depend on the ExternalEventHandler. + * - unregisterFB(CFunctionBlock *pa_poESFB) the ES-FB doesn't want to receive any external events any more (e.g. INIT-). + */ +class CExternalEventHandler{ + public: + CExternalEventHandler(); + + virtual ~CExternalEventHandler(){ + } + ; + /*!\brief Enables this event source + * + */ + virtual void enableHandler(void) = 0; + /*!\brief Disable this event source + */ + virtual void disableHandler(void) = 0; + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority) = 0; + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const = 0; + + static void setDeviceExecution(CDeviceExecution *pa_poDevExec){ + sm_poDeviceExecution = pa_poDevExec; + } + ; + static CDeviceExecution *getDeviceExecution(void){ + return sm_poDeviceExecution; + } + ; + protected: + + int getExternalEventHandlerID(){ + return m_nExtEvHandID; + } + + /*! \brief Check if the external event handler is allowed to start event chains + * + */ + bool isAllowed(); + + /*!\brief register event source at device execution for starting a new event chain + * + * this function checks if the external event handler is allowed to start new event chains and if yes performs the necessary actions. + * + * @param pa_poECStartFB the event source function block which starts the new event chain + */ + void startNewEventChain(CEventSourceFB *pa_poECStartFB); + + private: + static CDeviceExecution *sm_poDeviceExecution; //!< Reference to the device execution needed for all external event handlers to ask for execution and start new event chains. + + //!ID for this timer callback as given by the CDeviceExecution + int m_nExtEvHandID; + + private: + +}; + +/*@}*/ +/*@}*/ +#endif /*EXTEVHAN_H_*/ diff --git a/src/core/fbcontainer.cpp b/src/core/fbcontainer.cpp new file mode 100644 index 000000000..1aa15233f --- /dev/null +++ b/src/core/fbcontainer.cpp @@ -0,0 +1,197 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "fbcontainer.h" + +using namespace forte::core; + +CFBContainer::CFBContainer(CStringDictionary::TStringId paContainerName, CFBContainer *paParent) : + mContainerName(paContainerName), + mParent(paParent){ + +} + +CFBContainer::~CFBContainer(){ + + for(TFunctionBlockList::Iterator itRunner(mFunctionBlocks.begin()); + itRunner != mFunctionBlocks.end(); ++itRunner){ + CTypeLib::deleteFB(*itRunner); + } + mFunctionBlocks.clearAll(); + + for(TFBContainerList::Iterator itRunner(mSubContainers.begin()); + itRunner != mSubContainers.end(); ++itRunner){ + delete (*itRunner); + } + mSubContainers.clearAll(); +} + +EMGMResponse CFBContainer::addFB(CFunctionBlock* pa_poFuncBlock){ + EMGMResponse eRetVal = e_INVALID_OBJECT; + if(0 != pa_poFuncBlock){ + mFunctionBlocks.push_back(pa_poFuncBlock); + eRetVal = e_RDY; + } + return eRetVal; +} + + +EMGMResponse CFBContainer::createFB(forte::core::TNameIdentifier::CIterator &paNameListIt, CStringDictionary::TStringId paTypeName, CResource *paRes){ + EMGMResponse retval = e_INVALID_STATE; + + if(paNameListIt.isLastEntry()){ + // test if the container does not contain any FB or a container with the same name + if((0 == getFB(*paNameListIt)) && (0 == getFBContainer(*paNameListIt))){ + CFunctionBlock *newFB = CTypeLib::createFB(*paNameListIt, paTypeName, paRes); + if(0 != newFB){ + //we could create a FB now add it to the list of contained FBs + mFunctionBlocks.push_back(newFB); + retval = e_RDY; + } + else{ + retval = CTypeLib::getLastError(); + } + } + } + else{ + //we have more than one name in the fb name list. Find or create the container and hand the create command to this container. + CFBContainer *childCont = findOrCreateContainer(*paNameListIt); + if(0 != childCont){ + //remove the container from the name list + ++paNameListIt; + retval = childCont->createFB(paNameListIt, paTypeName, paRes); + } + } + return retval; +} + +EMGMResponse CFBContainer::deleteFB(forte::core::TNameIdentifier::CIterator &paNameListIt){ + EMGMResponse retval = e_NO_SUCH_OBJECT; + + if(!paNameListIt.isLastEntry()){ + //we have more than one name in the fb name list. Find or create the container and hand the create command to this container. + CFBContainer *childCont = findOrCreateContainer(*paNameListIt); + if(0 != childCont){ + //remove the container from the name list + ++paNameListIt; + retval = childCont->deleteFB(paNameListIt); + } + } + else{ + CStringDictionary::TStringId fBNameId = *paNameListIt; + + if((CStringDictionary::scm_nInvalidStringId != fBNameId) && (!mFunctionBlocks.isEmpty())){ + + TFunctionBlockList::Iterator itRunner = mFunctionBlocks.begin(); + TFunctionBlockList::Iterator itRefNode = mFunctionBlocks.end(); + + while(itRunner != mFunctionBlocks.end()){ + if(fBNameId == (*itRunner)->getInstanceNameId()){ + if((*itRunner)->isCurrentlyDeleteable()){ + CTypeLib::deleteFB(*itRunner); + if(itRefNode == mFunctionBlocks.end()){ + //we have the first entry in the list + mFunctionBlocks.pop_front(); + } + else{ + mFunctionBlocks.eraseAfter(itRefNode); + } + retval = e_RDY; + } + else{ + retval = e_INVALID_STATE; + } + break; + } + + itRefNode = itRunner; + ++itRunner; + } + } + } + return retval; +} + +CFunctionBlock *CFBContainer::getFB(CStringDictionary::TStringId paFBName) { + CFunctionBlock *retVal = 0; + + if(CStringDictionary::scm_nInvalidStringId != paFBName){ + for(TFunctionBlockList::Iterator it = mFunctionBlocks.begin(); it != mFunctionBlocks.end(); + ++it){ + if(paFBName == ((*(*it)).getInstanceNameId())){ + retVal = (*it); + break; + } + } + } + return retVal; +} + +CFunctionBlock* CFBContainer::getContainedFB(forte::core::TNameIdentifier::CIterator &paNameListIt) { + if(!paNameListIt.isLastEntry()){ + //we have more than one name in the fb name list. Find or create the container and hand the create command to this container. + CFBContainer *childCont = getFBContainer(*paNameListIt); + if(0 != childCont){ + //remove the container from the name list + ++paNameListIt; + return childCont->getContainedFB(paNameListIt); + } + } + + return getFB(*paNameListIt); +} + +CFBContainer *CFBContainer::getFBContainer(CStringDictionary::TStringId paContainerName) { + CFBContainer *retVal = 0; + + if(CStringDictionary::scm_nInvalidStringId != paContainerName){ + for(TFBContainerList::Iterator it = mSubContainers.begin(); it != mSubContainers.end(); + ++it){ + if(paContainerName == ((*(*it)).getName())){ + retVal = (*it); + break; + } + } + } + return retVal; +} + +CFBContainer *CFBContainer::findOrCreateContainer(CStringDictionary::TStringId paContainerName){ + CFBContainer *retVal = getFBContainer(paContainerName); + if(0 == retVal){ + //the container with the given name does not exist create a new one + if(0 == getFB(paContainerName)){ + //only create it if there is no FB with the same name. + retVal = new CFBContainer(paContainerName, this); + mSubContainers.push_back(retVal); + } + } + return retVal; +} + +EMGMResponse CFBContainer::changeContainedFBsExecutionState(EMGMCommandType paCommand){ + EMGMResponse retVal = e_RDY; + + for(TFBContainerList::Iterator it(mSubContainers.begin()); + ((it != mSubContainers.end()) && (e_RDY == retVal)); + ++it){ + retVal = (*it)->changeContainedFBsExecutionState(paCommand); + } + + if(e_RDY == retVal){ + for(TFunctionBlockList::Iterator itRunner(mFunctionBlocks.begin()); + ((itRunner != mFunctionBlocks.end()) && (e_RDY == retVal)); + ++itRunner){ + retVal = (*itRunner)->changeFBExecutionState(paCommand); + } + } + return retVal; +} diff --git a/src/core/fbcontainer.h b/src/core/fbcontainer.h new file mode 100644 index 000000000..9cfb97b94 --- /dev/null +++ b/src/core/fbcontainer.h @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FBCONTAINER_H_ +#define _FBCONTAINER_H_ + +#include "fortelist.h" +#include "stringdict.h" +#include "funcbloc.h" +#include "mgmcmdstruct.h" + +namespace forte { + namespace core { + + class CFBContainer{ + public: + CFBContainer(CStringDictionary::TStringId paContainerName, CFBContainer *paParent); + virtual ~CFBContainer(); + + CStringDictionary::TStringId getName(){ + return mContainerName; + } + + /*!\brief Gets a function block from the container or recursively from its subcontainers + * + * @param paNameList itartor to the name hierarchy the requested function block, if retval is not 0 it will point to the the item which found the FB + * @return pointer to the requested function block, returns 0 if function block is not in the list + */ + CFunctionBlock* getContainedFB(forte::core::TNameIdentifier::CIterator &paNameListIt); + + /*!\brief Adds a created function block to the FB-List + * + * @param pa_poFuncBlock new function block to add to the FB-List + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse addFB(CFunctionBlock *pa_poFuncBlock); + + typedef CSinglyLinkedList TFunctionBlockList; + + TFunctionBlockList &getFBList(){ + return mFunctionBlocks; + } + + protected: + + /*!\brief Create a new FB instance of given type and name + * + * @param paNameListIt iterator to the current position in the name list for the FB to be created (e.g., SubApp1.SubApp2.FBName, FBName2) + * @param paTypeName the type name of the FB to be created + * @param paRes the resource this container is contained in and in which the fb should reside + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse createFB(forte::core::TNameIdentifier::CIterator &paNameListIt, + CStringDictionary::TStringId paTypeName, CResource *paRes); + + /*!\brief Delete a FB instance with given name + * + * @param paNameListIt iterator to the current position in the name list for the FB to be deleted (e.g., SubApp1.SubApp2.FBName, FBName2) + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse deleteFB(forte::core::TNameIdentifier::CIterator &paNameListIt); + + /*! get fb contained in this fbcontainer + * + */ + CFunctionBlock *getFB(CStringDictionary::TStringId paFBName); + CFBContainer *getFBContainer(CStringDictionary::TStringId paContainerName); + + //! Change the execution state of all contained FBs and also recursively in all contained containers + EMGMResponse changeContainedFBsExecutionState(EMGMCommandType paCommand); + + + typedef CSinglyLinkedList TFBContainerList; + + private: + /*!\brief Retrieve a FBContainer with given name. If it does not exist create it. + * + * @param paContainerName name of the container + * @return pointer to the container or 0 if an FB with the same name exists in this container + */ + CFBContainer *findOrCreateContainer(CStringDictionary::TStringId paContainerName); + + CStringDictionary::TStringId mContainerName; //!< name of the container + CFBContainer *mParent; //!< the parent FBContainer this FBContainer is contained in. The parent of a resource is 0 + + TFunctionBlockList mFunctionBlocks; //!< The functionblocks hold in this container + TFBContainerList mSubContainers; //!< List of subcontainers (i.e, subapplications in this container) + }; + + } /* namespace core */ +} /* namespace forte */ + +#endif /* FBCONTAINER_H_ */ diff --git a/src/core/forteiterator.h b/src/core/forteiterator.h new file mode 100644 index 000000000..02283bf93 --- /dev/null +++ b/src/core/forteiterator.h @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians, Alois Zoitl, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef FORTEITERATOR_H_ +#define FORTEITERATOR_H_ + +/*! \ingroup CORE\brief FORTE implementation of a Singly Linked List Iterator + */ + + + /*!\brief Iterator class of the Singly linked list + * + * This is the iterator class of this singly linked list, with minimum functionality needed for read and write access. + * It's nested in the singly linked list template class for reuse + * + * T ... Data Type + * C ... Node Class i.e. CSinglyLinkedListNode + */ + +template +class CIterator { +public: + CIterator(Container* pa_poNode) : m_poCurrentPosition(pa_poNode) { + + } + + ~CIterator() { + } + + /*!\brief returns the pointer of the current node element + */ + + Container* getPosition() const { + return m_poCurrentPosition; + } + + /*!\brief moves iterator to the next element + */ + CIterator& operator++() { + m_poCurrentPosition = m_poCurrentPosition->getNext(); + return *this; + } + + /*!\brief returns reference to contained object + * + * \return reference of the contained object of type T + */ + T& operator*() { + return m_poCurrentPosition->getData(); + } + + /*!\brief Returns a pointer to the contained object + * \return A Pointer to the contained object of type T + */ + T* operator->() { + return &(**this); + } + + /*!\brief equality operator for the iterator + * + * \return true if position of iterators match, false if otherwise + */ + bool operator==(CIterator const& rhs) const { + return m_poCurrentPosition == rhs.m_poCurrentPosition; + } + + /*!\brief inequality operator of the iterator + * + * \return false if positions of the iterators match, true if otherwise + */ + bool operator!=(CIterator const& rhs) const { + return !(*this == rhs); + } + +private: + CIterator(); + Container* m_poCurrentPosition; +}; + +template +class CIterator { +public: + CIterator(Container* pa_poNode) : m_poCurrentPosition(pa_poNode) { + + } + + ~CIterator() { + + } + + /*!\brief returns the pointer of the current node element + */ + + Container* getPosition() const { + return m_poCurrentPosition; + } + + /*!\brief moves iterator to the next element + */ + CIterator& operator++() { + m_poCurrentPosition = m_poCurrentPosition->getNext(); + return *this; + } + + /*!\brief returns reference to contained object + * + * \return reference of the contained object of type T + */ + T* operator*() { + return (T*)m_poCurrentPosition->getData(); + } + + /*!\brief Returns a pointer to the contained object + * \return A Pointer to the contained object of type T + */ + T* operator->() { + return (T*)m_poCurrentPosition->getData(); + } + + /*!\brief equality operator for the iterator + * + * \return true if position of iterators match, false if otherwise + */ + bool operator==(CIterator const& rhs) const { + return m_poCurrentPosition == rhs.m_poCurrentPosition; + } + + /*!\brief inequality operator of the iterator + * + * \return false if positions of the iterators match, true if otherwise + */ + bool operator!=(CIterator const& rhs) const { + return !(*this == rhs); + } + +private: + CIterator(); + Container* m_poCurrentPosition; +}; + +#endif /* FORTEITERATOR_H_ */ diff --git a/src/core/fortelist.h b/src/core/fortelist.h new file mode 100644 index 000000000..d4c8aadf3 --- /dev/null +++ b/src/core/fortelist.h @@ -0,0 +1,370 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians, Alois Zoitl, Ingo Hegny, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "fortenode.h" +#include "forteiterator.h" + +#ifndef _FORTELIST_H_ +#define _FORTELIST_H_ + +/*! \ingroup CORE\brief FORTE implementation of a Singly Linked List + */ + +template > +class CSinglyLinkedList { +private: + + friend class CIterator; + + /*!\brief First element of the singly linked list + */ + Container* m_poFirstNode; + + /*!\brief Last element of the singly linked list + */ + Container* m_poLastNode; + +public: + CSinglyLinkedList(); + ~CSinglyLinkedList(); + + /*!\brief Typedef for getting the right iterator for the list + * */ + typedef CIterator Iterator; + + /*!\brief Add's the given object at the start of the singly linked list + * + * \param pa_roElement the reference to the object to be added + */ + void push_front(T const& pa_roElement); + + /*!\brief Add's the given object at the end of the singly linked list + * + * \param pa_roElement the reference to the object to be added + */ + void push_back(T const& pa_roElement); + + /*!\brief Deletes the first object of the singly linked list + * + */ + void pop_front(); + + /*!\brief Deletes all objects in the singly linked list + */ + void clearAll(); + + /*!\brief checks if the singly linked list is empty or not + * + * \return true if the list is empty, false if not + */ + bool isEmpty() const { + return (0 == m_poFirstNode); + } + + /*!\brief returns an iterator with it's current position set to the start of the singly linked list + * + * \return iterator on position FirstNode + */ + const Iterator begin() { + return Iterator(m_poFirstNode); + } + + /*!\brief returns an iterator with it's current position set to 0 + * + * \return iterator with current position 0 + */ + const Iterator end() const { + return Iterator(0); + } + + const Iterator back() { + return Iterator(m_poLastNode); + } + + /*!\brief erases the next node element after the position of the iterator + * + * \param it iterator set on the element before the element to delete + * \return Iterator set on the new next node element + */ + const Iterator eraseAfter(Iterator& it); + + + +}; + +template +inline CSinglyLinkedList::CSinglyLinkedList() : m_poFirstNode(0), m_poLastNode(0) { +} + +template +inline CSinglyLinkedList::~CSinglyLinkedList() { + clearAll(); +} + +template +void CSinglyLinkedList::push_front(T const& pa_roElement) { + Container* poNewNode = new Container(pa_roElement, m_poFirstNode); + m_poFirstNode = poNewNode; + if(0 == m_poLastNode){ + m_poLastNode = poNewNode; + } +} + +template +void CSinglyLinkedList::push_back(T const& pa_roElement) { + Container* poNewNode = new Container(pa_roElement); + + if(0 != m_poLastNode){ + m_poLastNode->setNext(poNewNode); + } + else{ + m_poFirstNode = poNewNode; + } + m_poLastNode = poNewNode; +} + +template +void CSinglyLinkedList::pop_front() { + Container* pNodeToDelete = m_poFirstNode; + m_poFirstNode = m_poFirstNode->getNext(); + if(0 == m_poFirstNode) { + m_poLastNode = 0; + } + delete pNodeToDelete; +} + +template +inline void CSinglyLinkedList::clearAll() { + while(m_poFirstNode != 0) { + pop_front(); + } +} + +template +const CIterator CSinglyLinkedList::eraseAfter(Iterator& it) { + Container* pNodeToDelete = (it.getPosition())->getNext(); + it.getPosition()->setNext(pNodeToDelete->getNext()); + if(0 == it.getPosition()->getNext()) { + m_poLastNode = it.getPosition(); + } + delete pNodeToDelete; + return Iterator((it.getPosition())->getNext()); +} + +/*!\brief explicit specialization for a void* list + * + */ + +template<> +class CSinglyLinkedList > { +private: + + friend class CIterator >; + + /*!\brief First element of the singly linked list + */ + CSinglyLinkedListNode* m_poFirstNode; + + /*!\brief Last element of the singly linked list + */ + CSinglyLinkedListNode* m_poLastNode; + +public: + CSinglyLinkedList() : m_poFirstNode(0), m_poLastNode(0) { + + } + ~CSinglyLinkedList() { + clearAll(); + } + + /*!\brief Typedef for getting the right iterator for the list + * */ + typedef CIterator > Iterator; + + /*!\brief Add's the given object at the start of the singly linked list + * + * \param pa_poElement the reference to the object to be added + */ + void push_front(void* const pa_poElement) { + CSinglyLinkedListNode* poNewNode = new CSinglyLinkedListNode(pa_poElement, m_poFirstNode); + m_poFirstNode = poNewNode; + if(0 == m_poLastNode){ + m_poLastNode = poNewNode; + } + } + + /*!\brief Add's the given object at the end of the singly linked list + * + * \param pa_poElement the reference to the object to be added + */ + void push_back(void* const pa_poElement) { + CSinglyLinkedListNode* poNewNode = new CSinglyLinkedListNode(pa_poElement); + + if(0 != m_poLastNode){ + m_poLastNode->setNext(poNewNode); + } + else{ + m_poFirstNode = poNewNode; + } + m_poLastNode = poNewNode; + } + + /*!\brief Deletes the first object of the singly linked list + * + */ + inline void pop_front() { + CSinglyLinkedListNode* pNodeToDelete = m_poFirstNode; + m_poFirstNode = m_poFirstNode->getNext(); + if(0 == m_poFirstNode) { + m_poLastNode = 0; + } + delete pNodeToDelete; + } + + /*!\brief Deletes all objects in the singly linked list + */ + inline void clearAll() { + while(0 != m_poFirstNode) { + pop_front(); + } + } + + /*!\brief checks if the singly linked list is empty or not + * + * \return true if the list is empty, false if not + */ + inline bool isEmpty() const { + return (0 == m_poFirstNode); + } + + /*!\brief returns an iterator with it's current position set to the start of the singly linked list + * + * \return iterator on position FirstNode + */ + inline const Iterator begin() { + return Iterator(m_poFirstNode); + } + + /*!\brief returns an iterator with it's current position set to 0 + * + * \return iterator with current position 0 + */ + inline const Iterator end() const { + return Iterator(0); + } + + /*!\brief erases the next node element after the position of the iterator + * + * \param it an iterator set on the element before the element to delete + * \return Iterator set on the new next node element + */ + const Iterator eraseAfter(Iterator& it) { + CSinglyLinkedListNode* pNodeToDelete = (it.getPosition())->getNext(); + it.getPosition()->setNext(pNodeToDelete->getNext()); + if(0 == it.getPosition()->getNext()) { + m_poLastNode = it.getPosition(); + } + delete pNodeToDelete; + return Iterator((it.getPosition())->getNext()); + } + +}; + +/*!\brief partial specialization for pointer lists + */ + +template +class CSinglyLinkedList { +private: + friend class CIterator >; + CSinglyLinkedList m_List; + +public: + CSinglyLinkedList() { + + } + + ~CSinglyLinkedList() { + clearAll(); + } + + /*!\brief Typedef for getting the right iterator for the list + * */ + typedef CIterator > Iterator; + + /*!\brief Add's the given object at the start of the singly linked list + * + * \param pa_pElement the reference to the object to be added + */ + inline void push_front(T* const pa_pElement) { + m_List.push_front(pa_pElement); + } + + /*!\brief Add's the given object at the end of the singly linked list + * + * \param pa_pElement the reference to the object to be added + */ + inline void push_back(T* const pa_pElement) { + m_List.push_back(pa_pElement); + } + + /*!\brief Deletes the first object of the singly linked list + * + */ + inline void pop_front() { + m_List.pop_front(); + } + + /*!\brief Deletes all objects in the singly linked list + */ + inline void clearAll() { + m_List.clearAll(); + } + + /*!\brief checks if the singly linked list is empty or not + * + * \return true if the list is empty, false if not + */ + inline bool isEmpty() const { + return m_List.isEmpty(); + } + + /*!\brief returns an iterator with it's current position set to the start of the singly linked list + * + * \return iterator on position FirstNode + */ + inline const Iterator begin() { + return Iterator((m_List.begin()).getPosition()); + } + + /*!\brief returns an iterator with it's current position set to 0 + * + * \return iterator with current position 0 + */ + inline const Iterator end() const { + return Iterator((m_List.end()).getPosition()); + } + + /*!\brief erases the next node element after the position of the iterator + * + * \param it an iterator set on the element before the element to delete + * \return Iterator set on the new next node element + */ + const Iterator eraseAfter(Iterator& it) { + CSinglyLinkedList::Iterator itBuff(it.getPosition()); + return Iterator((m_List.eraseAfter(itBuff)).getPosition()); + } + +}; + + +#endif /* CSINGLYLINKEDLIST_H_ */ diff --git a/src/core/fortenode.h b/src/core/fortenode.h new file mode 100644 index 000000000..4acd36628 --- /dev/null +++ b/src/core/fortenode.h @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef FORTENODE_H_ +#define FORTENODE_H_ + +/*! \ingroup CORE\brief FORTE implementation of a Singly Linked List Node + */ + + + /*!\brief container element of the singly linked list + * + * This struct is the container element of the singly linked list. + * It's nested in the singly linked list class for reuse in the template class + */ + +template +class CSinglyLinkedListNode { +private: + /*!\brief contained object of the node element + */ + T m_oNodeElement; + /*!\brief pointer to the next node element + */ + CSinglyLinkedListNode* m_poNextNode; + CSinglyLinkedListNode(); +public: + CSinglyLinkedListNode(T pa_oNodeElement, CSinglyLinkedListNode* pa_poNextNode = 0) : m_oNodeElement(pa_oNodeElement), m_poNextNode(pa_poNextNode) { + + } + + ~CSinglyLinkedListNode() { + + } + + T& getData() { + return m_oNodeElement; + } + + CSinglyLinkedListNode* getNext() const { + return m_poNextNode; + } + + void setNext(CSinglyLinkedListNode* pa_poNextNode) { + m_poNextNode = pa_poNextNode; + } + +}; + +#endif /* FORTENODE_H_ */ diff --git a/src/core/funcbloc.cpp b/src/core/funcbloc.cpp new file mode 100644 index 000000000..9e4f97fb6 --- /dev/null +++ b/src/core/funcbloc.cpp @@ -0,0 +1,739 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Gunnar Grabmaier, Alois Zoitl, Smodic Rene, Ingo Hegny, + * Gerhard Ebenhofer, Michael Hofmann, Martin Melik Merkumians, Monika Wenger, + * Matthias Plasch + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include +#include "timerha.h" +#include "funcbloc.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "funcbloc_gen.cpp" +#endif +#include "resource.h" +#include "adapter.h" +#include "datatypes/forte_array.h" +#include "utils/criticalregion.h" + +CFunctionBlock::CFunctionBlock(CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) : + mEOConns(0), m_apoDIConns(0), mDOConns(0), + m_apoAdapters(0), m_poResource(pa_poSrcRes), m_aoDIs(0), m_aoDOs(0), m_nFBInstanceName(pa_nInstanceNameId), + m_enFBState(e_KILLED), //put the FB in the killed state so that reseting it after creation will correctly initialize it + m_bDeletable(true){ + + #ifdef FORTE_SUPPORT_MONITORING + m_nEIMonitorCount = 0; + m_nEOMonitorCount = 0; + mContainer = 0; +#endif + + setupFBInterface(pa_pstInterfaceSpec, pa_acFBConnData, pa_acFBVarsData, false); +} + +CFunctionBlock::~CFunctionBlock(){ + freeAllData(); +} + +void CFunctionBlock::freeAllData(){ + if(0 != m_pstInterfaceSpec){ + for(int i = 0; i < m_pstInterfaceSpec->m_nNumEOs; ++i){ + (mEOConns + i)->~CEventConnection(); + } + + for(int i = 0; i < m_pstInterfaceSpec->m_nNumDIs; ++i){ + getDI(i)->~CIEC_ANY(); + } + + for(int i = 0; i < m_pstInterfaceSpec->m_nNumDOs; ++i){ + getDO(i)->~CIEC_ANY(); + (mDOConns + i)->~CDataConnection(); + } + + for(unsigned int i = 0; i < m_pstInterfaceSpec->m_nNumAdapters; ++i){ + delete m_apoAdapters[i]; + } + } + + if(m_bManagesFBData){ + TForteByte *acFBConnData = 0; + TForteByte *acFBVarsData = 0; + + if(0 != mEOConns){ + //if not 0 m_apoEOConns points to the start of the connection data array + acFBConnData = reinterpret_cast(mEOConns); + } + else{ + if(0 != m_apoDIConns){ + //if not 0 m_apoDIConns points to the start of the connection data array + acFBConnData = reinterpret_cast(m_apoDIConns); + } + else{ + if(0 != mDOConns){ + //if not 0 m_apoDOConns points to the start of the connection data array + acFBConnData = reinterpret_cast(mDOConns); + } + } + } + + if(0 != m_aoDIs){ + //if not 0 m_aoDIs points to the start of the vars data array + acFBVarsData = reinterpret_cast(m_aoDIs); + } + else{ + if(0 != m_aoDOs){ + //if not 0 m_aoDOs points to the start of the vars data array + acFBVarsData = reinterpret_cast(m_aoDOs); + } + else{ + if(0 != m_apoAdapters){ + //if not 0 m_apoAdapters points to the start of the vars data array + acFBVarsData = reinterpret_cast(m_apoAdapters); + } + } + } + + delete[] acFBConnData; + delete[] acFBVarsData; + delete m_pstInterfaceSpec; + } +#ifdef FORTE_SUPPORT_MONITORING + delete[] m_nEOMonitorCount; + delete[] m_nEIMonitorCount; +#endif //FORTE_SUPPORT_MONITORING +} + +void CFunctionBlock::setupAdapters(const SFBInterfaceSpec *pa_pstInterfaceSpec, TForteByte *pa_acFBData){ + if((0 != pa_pstInterfaceSpec) && (0 != pa_acFBData)){ + if(pa_pstInterfaceSpec->m_nNumAdapters){ + m_apoAdapters = reinterpret_cast(pa_acFBData); + for(unsigned int i = 0; i < pa_pstInterfaceSpec->m_nNumAdapters; ++i){ + //set pointer to right place in pa_acFBData + m_apoAdapters[i] = ((CAdapter*) CTypeLib::createAdapter(pa_pstInterfaceSpec->m_pstAdapterInstanceDefinition[i].m_nAdapterNameID, pa_pstInterfaceSpec->m_pstAdapterInstanceDefinition[i].m_nAdapterTypeNameID, getResourcePtr(), pa_pstInterfaceSpec->m_pstAdapterInstanceDefinition[i].m_bIsPlug)); + if(0 != m_apoAdapters[i]){ + ((CAdapter*) m_apoAdapters[i])->setParentFB(this, static_cast(i)); +#ifdef FORTE_SUPPORT_MONITORING + m_apoAdapters[i]->setContainer(this); +#endif + } + } + } + } +} + +CEventConnection *CFunctionBlock::getEOConection(CStringDictionary::TStringId paEONameId) const{ + CEventConnection *retVal = 0; + unsigned int portId = getPortId(paEONameId, m_pstInterfaceSpec->m_nNumEOs, m_pstInterfaceSpec->m_aunEONames); + if(cg_unInvalidPortId != portId){ + retVal = getEOConUnchecked(portId); + } + return retVal; +} + +bool CFunctionBlock::connectDI(TPortId paDIPortId, CDataConnection *pa_poDataCon){ + bool bRetVal = false; + + if(m_pstInterfaceSpec->m_nNumDIs > paDIPortId){ //catch invalid ID + if(0 == pa_poDataCon){ + m_apoDIConns[paDIPortId] = 0; + bRetVal = true; + } + else{ + //only perform connection checks if it is not a disconnection request. + if(0 != m_apoDIConns[paDIPortId]){ + if(m_apoDIConns[paDIPortId] == pa_poDataCon){ + //we have a reconfiguration attempt + configureGenericDI(paDIPortId, pa_poDataCon->getValue()); + bRetVal = true; + }else{ + DEVLOG_ERROR("%s cannot connect input data %s to more sources, using the latest connection attempt\n", CStringDictionary::getInstance().get(getFBTypeId()), CStringDictionary::getInstance().get(m_pstInterfaceSpec->m_aunDINames[paDIPortId])); + } + }else{ + m_apoDIConns[paDIPortId] = pa_poDataCon; + configureGenericDI(paDIPortId, pa_poDataCon->getValue()); + bRetVal = true; + } + } + } + return bRetVal; +} + +void CFunctionBlock::configureGenericDI(TPortId paDIPortId, const CIEC_ANY *paRefValue){ + if(getDI(paDIPortId)->getDataTypeID() == CIEC_ANY::e_ANY){ + if(0 != paRefValue){ + paRefValue->clone(reinterpret_cast(getDI(paDIPortId))); + } + } +} + +CDataConnection *CFunctionBlock::getDOConnection(CStringDictionary::TStringId paDONameId) const{ + CDataConnection *retVal = 0; + TPortId doPortID = getDOID(paDONameId); + if(cg_unInvalidPortId != doPortID){ + retVal = mDOConns + doPortID; + } + return retVal; +} + +bool CFunctionBlock::configureGenericDO(TPortId paDOPortId, const CIEC_ANY &paRefValue){ + bool retVal = false; + + if(m_pstInterfaceSpec->m_nNumDOs > paDOPortId){ + CIEC_ANY *dataOutput = getDO(paDOPortId); + if(dataOutput->getDataTypeID() == CIEC_ANY::e_ANY){ + paRefValue.clone(reinterpret_cast(dataOutput)); + retVal = true; + } + } + return retVal; +} + +CIEC_ANY *CFunctionBlock::getDataOutput(CStringDictionary::TStringId pa_unDONameId){ + CIEC_ANY *poRetVal = 0; + unsigned int unDID = getDOID(pa_unDONameId); + + if(cg_unInvalidPortId != unDID){ + poRetVal = getDO(unDID); + } + return poRetVal; +} + +CIEC_ANY *CFunctionBlock::getDataInput(CStringDictionary::TStringId pa_unDINameId){ + CIEC_ANY *poRetVal = 0; + unsigned int unDID = getDIID(pa_unDINameId); + + if(cg_unInvalidPortId != unDID){ + poRetVal = getDI(unDID); + } + return poRetVal; +} + +CIEC_ANY* CFunctionBlock::getDIFromPortId(TPortId paDIPortId){ + CIEC_ANY *retVal = 0; + if(paDIPortId < m_pstInterfaceSpec->m_nNumDIs){ + retVal = getDI(paDIPortId); + } + return retVal; +} + +CIEC_ANY *CFunctionBlock::getVar(CStringDictionary::TStringId *paNameList, + unsigned int paNameListSize){ + + CIEC_ANY *poRetVal = 0; + if(1 == paNameListSize){ + unsigned int portId = getDIID(*paNameList); + if(cg_unInvalidPortId != portId){ + poRetVal = getDI(portId); + } + else{ + portId = getDOID(*paNameList); + if(cg_unInvalidPortId != portId){ + poRetVal = getDO(portId); + } + } + } + return poRetVal; +} + +CAdapter *CFunctionBlock::getAdapter(CStringDictionary::TStringId paAdapterNameId){ + TPortId adpPortId = getAddapterPortId(paAdapterNameId); + + if(cg_unInvalidPortId != adpPortId){ + return m_apoAdapters[adpPortId]; + } + return 0; +} + +TPortId CFunctionBlock::getAddapterPortId(CStringDictionary::TStringId paAdapterNameId){ + for(TPortId i = 0; i < m_pstInterfaceSpec->m_nNumAdapters; ++i){ + if(m_apoAdapters[i]->getInstanceNameId() == paAdapterNameId){ + return i; + } + } + return cg_unInvalidPortId; +} + +void CFunctionBlock::sendOutputEvent(int pa_nEO){ + FORTE_TRACE("OutputEvent: Function Block sending event: %d (maxid: %d)\n", pa_nEO, m_pstInterfaceSpec->m_nNumEOs - 1); + if(pa_nEO < m_pstInterfaceSpec->m_nNumEOs){ +#ifdef FORTE_SUPPORT_MONITORING + forte::core::SMonitorEvent &eventMonitoring(m_nEOMonitorCount[pa_nEO]); + forte::core::SMonitorEvent::SMonitorEventData &monitoringData(eventMonitoring.mMonitorEventData[eventMonitoring.mBufPos]); + // breakpoint set, ignore all other events + if(forte::core::eActive != eventMonitoring.mBreakpointSet){ +#endif //FORTE_SUPPORT_MONITORING + if(0 != m_pstInterfaceSpec->m_anEOWithIndexes){ + if(-1 != m_pstInterfaceSpec->m_anEOWithIndexes[pa_nEO]){ + const TDataIOID *poEOWithStart = &(m_pstInterfaceSpec->m_anEOWith[m_pstInterfaceSpec->m_anEOWithIndexes[pa_nEO]]); + //TODO think on this lock + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + for(int i = 0; poEOWithStart[i] != 255; ++i){ + CDataConnection *con = getDOConUnchecked(poEOWithStart[i]); + if(con->isConnected()){ + CIEC_ANY *poDO = getDO(poEOWithStart[i]); +#ifdef FORTE_SUPPORT_MONITORING + if(poDO->isForced() != true){ +#endif //FORTE_SUPPORT_MONITORING + con->writeData(poDO); +#ifdef FORTE_SUPPORT_MONITORING + } + else{ + //when forcing we write back the value from the connection to keep the forced value on the output + con->readData(poDO); + } +#endif //FORTE_SUPPORT_MONITORING + } + } + } + } + + getEOConUnchecked(pa_nEO)->triggerEvent(*m_poInvokingExecEnv); + +#ifdef FORTE_SUPPORT_MONITORING + // stop execution on Breakpoint + if(eventMonitoring.mBreakpointEnable){ + if(forte::core::eOnce == eventMonitoring.mBreakpointSet){ // if < 0 -> continue called + eventMonitoring.mBreakpointSet = forte::core::eInactive; + } + else{ + eventMonitoring.mBreakpointSet = forte::core::eActive; + return; + } + // Get Resource + //CResource &res = this->getResource(); + //res.stopManagedObject(); // we cant restart it, + } + // Count Event for monitoring + monitoringData.mEventCount++; + monitoringData.mTimeStamp = CTimerHandler::sm_poFORTETimer->getForteTime(); + eventMonitoring.mBufPos = (eventMonitoring.mBufPos + 1) % forte::core::cgMonitorBufferLength; + m_updated = true; + } // if(forte::core::eActive != eventMonitoring.mMonitorEventData[eventMonitoring.mBufPos].mBreakpointSet){ +#endif //FORTE_SUPPORT_MONITORING + } +} + +void CFunctionBlock::sendAdapterEvent(int pa_nAdapterID, int pa_nEID) const{ + if(0 != m_apoAdapters[pa_nAdapterID]){ + ((CAdapter*) m_apoAdapters[pa_nAdapterID])->receiveInputEvent(pa_nEID, *m_poInvokingExecEnv); + } +} + +bool CFunctionBlock::configureFB(const char *){ + return true; +} + +void CFunctionBlock::receiveInputEvent(int pa_nEIID, CEventChainExecutionThread &pa_poExecEnv){ + FORTE_TRACE("InputEvent: Function Block (%s) got event: %d (maxid: %d)\n", CStringDictionary::getInstance().get(getInstanceNameId()), pa_nEIID, m_pstInterfaceSpec->m_nNumEIs - 1); + + if(e_RUNNING == getState()){ + if(pa_nEIID < m_pstInterfaceSpec->m_nNumEIs){ +#ifdef FORTE_SUPPORT_MONITORING + forte::core::SMonitorEvent &eventMonitoring(m_nEIMonitorCount[pa_nEIID]); + forte::core::SMonitorEvent::SMonitorEventData &monitoringData(eventMonitoring.mMonitorEventData[eventMonitoring.mBufPos]); + // breakpoint set, ignore all other events + if(forte::core::eActive == eventMonitoring.mBreakpointSet){ + return; + } +#endif //FORTE_SUPPORT_MONITORING + if(0 != m_pstInterfaceSpec->m_anEIWithIndexes){ + + // printf( "Event name: %s\n", m_pstInterfaceSpec->m_acEINames[pa_nEIID]); + if(-1 != m_pstInterfaceSpec->m_anEIWithIndexes[pa_nEIID]){ + const TDataIOID *poEIWithStart = &(m_pstInterfaceSpec->m_anEIWith[m_pstInterfaceSpec->m_anEIWithIndexes[pa_nEIID]]); + + // TODO think on this lock + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + for(int i = 0; poEIWithStart[i] != 255; ++i){ + if(0 != m_apoDIConns[poEIWithStart[i]]){ + CIEC_ANY *poDI = getDI(poEIWithStart[i]); +#ifdef FORTE_SUPPORT_MONITORING + if(true != poDI->isForced()){ +#endif //FORTE_SUPPORT_MONITORING + m_apoDIConns[poEIWithStart[i]]->readData(poDI); +#ifdef FORTE_SUPPORT_MONITORING + } +#endif //FORTE_SUPPORT_MONITORING + } + } + } + } +#ifdef FORTE_SUPPORT_MONITORING + // stop execution on Breakpoint + if(eventMonitoring.mBreakpointEnable){ + if(forte::core::eOnce == eventMonitoring.mBreakpointSet){ // if < 0 -> continue called + eventMonitoring.mBreakpointSet = forte::core::eInactive; + } + else{ + eventMonitoring.mBreakpointSet = forte::core::eActive; + return; + } + // Get Resource + //CResource &res = this->getResource(); + //res.stopManagedObject(); // we cant restart it, + } + // Count Event for monitoring + monitoringData.mEventCount++; + monitoringData.mTimeStamp = CTimerHandler::sm_poFORTETimer->getForteTime(); + eventMonitoring.mBufPos = (eventMonitoring.mBufPos + 1) % forte::core::cgMonitorBufferLength; + m_updated = true; +#endif //FORTE_SUPPORT_MONITORING + } + m_poInvokingExecEnv = &pa_poExecEnv; + executeEvent(pa_nEIID); + } +} + +EMGMResponse CFunctionBlock::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse nRetVal = e_INVALID_STATE; + switch (pa_unCommand){ + case cg_nMGM_CMD_Start: + if((e_IDLE == m_enFBState) || (e_STOPPED == m_enFBState)){ + m_enFBState = e_RUNNING; + nRetVal = e_RDY; + } + break; + case cg_nMGM_CMD_Stop: + if(e_RUNNING == m_enFBState){ + m_enFBState = e_STOPPED; + nRetVal = e_RDY; + } + break; + case cg_nMGM_CMD_Kill: + if(e_RUNNING == m_enFBState){ + m_enFBState = e_KILLED; + nRetVal = e_RDY; + } + break; + case cg_nMGM_CMD_Reset: + if((e_STOPPED == m_enFBState) || (e_KILLED == m_enFBState)){ + m_enFBState = e_IDLE; + nRetVal = e_RDY; + setInitialValues(); + } + break; + default: + nRetVal = e_INVALID_OPERATION; + break; + } + + if(e_RDY == nRetVal){ + if(0 != m_pstInterfaceSpec){ + for(int i = 0; i < m_pstInterfaceSpec->m_nNumAdapters; ++i){ + if(0 != m_apoAdapters[i]){ + m_apoAdapters[i]->changeFBExecutionState(pa_unCommand); + } + } + } + } + return nRetVal; +} + +CIEC_ANY *CFunctionBlock::createDataPoint(const CStringDictionary::TStringId **pa_panDataTypeIds, TForteByte *pa_acDataBuf){ + CIEC_ANY *poRetVal = CTypeLib::createDataTypeInstance(**pa_panDataTypeIds, pa_acDataBuf); + ++(*pa_panDataTypeIds); +#ifdef FORTE_SUPPORT_ARRAYS + if(g_nStringIdARRAY == (*pa_panDataTypeIds)[-1]){ + if(0 != poRetVal){ + //For an array we have to do more + ((CIEC_ARRAY *) poRetVal)->setup(static_cast(**pa_panDataTypeIds), (*pa_panDataTypeIds)[1]); + } + (*pa_panDataTypeIds) += 2; + } +#endif + return poRetVal; +} + +void CFunctionBlock::setupFBInterface(const SFBInterfaceSpec *pa_pstInterfaceSpec, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData, bool pa_bManagesFBData){ + m_pstInterfaceSpec = const_cast(pa_pstInterfaceSpec); + m_bManagesFBData = pa_bManagesFBData; + + if(0 != pa_pstInterfaceSpec){ + if((0 != pa_acFBConnData) && (0 != pa_acFBVarsData)){ + TPortId i; + if(m_pstInterfaceSpec->m_nNumEOs){ + mEOConns = reinterpret_cast(pa_acFBConnData); + + for(i = 0; i < m_pstInterfaceSpec->m_nNumEOs; ++i){ + //create an event connection for each event output and initialize its source port + new (pa_acFBConnData)CEventConnection(this, i); + pa_acFBConnData += sizeof(CEventConnection); + } + } + else{ + mEOConns = 0; + } + + const CStringDictionary::TStringId *pnDataIds; + if(m_pstInterfaceSpec->m_nNumDIs){ + m_apoDIConns = reinterpret_cast(pa_acFBConnData); + pa_acFBConnData += sizeof(TDataConnectionPtr) * m_pstInterfaceSpec->m_nNumDIs; + + //let m_aoDIs point to the first data input + m_aoDIs = reinterpret_cast(pa_acFBVarsData); + + pnDataIds = pa_pstInterfaceSpec->m_aunDIDataTypeNames; + for(i = 0; i < m_pstInterfaceSpec->m_nNumDIs; ++i){ + m_apoDIConns[i] = 0; + createDataPoint(&pnDataIds, pa_acFBVarsData); + pa_acFBVarsData += sizeof(CIEC_ANY); + } + } + else{ + m_apoDIConns = 0; + m_aoDIs = 0; + } + + if(m_pstInterfaceSpec->m_nNumDOs){ + //let mDOConns point to the first data output connection + mDOConns = reinterpret_cast(pa_acFBConnData); + + //let m_aoDIs point to the first data output + m_aoDOs = reinterpret_cast(pa_acFBVarsData); + + pnDataIds = pa_pstInterfaceSpec->m_aunDODataTypeNames; + for(i = 0; i < m_pstInterfaceSpec->m_nNumDOs; ++i){ + createDataPoint(&pnDataIds, pa_acFBVarsData); + pa_acFBVarsData += sizeof(CIEC_ANY); + //create an data connection for each data output and initialize its source port + new (pa_acFBConnData)CDataConnection(this, i, getDO(i)); + pa_acFBConnData += sizeof(CDataConnection); + } + } + else{ + mDOConns = 0; + m_aoDOs = 0; + } + if(m_pstInterfaceSpec->m_nNumAdapters){ + setupAdapters(pa_pstInterfaceSpec, pa_acFBVarsData); + } + } +#ifdef FORTE_SUPPORT_MONITORING + setupEventMonitoringData(); +#endif + } + +} + +TPortId CFunctionBlock::getPortId(CStringDictionary::TStringId pa_unPortNameId, TPortId pa_unMaxPortNames, const CStringDictionary::TStringId* pa_aunPortNames){ + for(TPortId i = 0; i < pa_unMaxPortNames; ++i){ + if(pa_unPortNameId == pa_aunPortNames[i]){ + return i; + } + } + return cg_unInvalidPortId; +} + +void CFunctionBlock::generateGenericInterfacePointNameArray(const char * const pa_acPrefix, CStringDictionary::TStringId* pa_anNamesArayStart, unsigned int pa_unNumGenericDataPoints){ + TIdentifier acBuffer; + + size_t unLen = strlen(pa_acPrefix); + + if(cg_nIdentifierLength > unLen){ + memcpy(acBuffer, pa_acPrefix, unLen); + char *acRunner = &acBuffer[unLen]; + char *acTenth = 0; + char *acHundret = 0; + acRunner[1] = '\0'; + + for(unsigned int i = 1, j = 0, jj = 0; i <= pa_unNumGenericDataPoints; i++){ + if(0 == (i % 10)){ + if(j == 0){ + acTenth = acRunner; + acRunner++; + acRunner[1] = '\0'; + } + j++; + + if(0 == (j % 10)){ + if(jj == 0){ + acHundret = acTenth; + acTenth = acRunner; + acRunner++; + acRunner[1] = '\0'; + } + jj++; + *acHundret = static_cast(0x30 + (jj % 10)); + } + *acTenth = static_cast(0x30 + (j % 10)); + } + *acRunner = static_cast(0x30 + (i % 10)); + pa_anNamesArayStart[i - 1] = CStringDictionary::getInstance().insert(acBuffer); + } + } +} + +void CFunctionBlock::generateGenericDataPointArrays(const char * const pa_acPrefix, CStringDictionary::TStringId* pa_anDataTypeNamesArrayStart, CStringDictionary::TStringId* pa_anNamesArrayStart, unsigned int pa_unNumGenericDataPoints){ + generateGenericInterfacePointNameArray(pa_acPrefix, pa_anNamesArrayStart, pa_unNumGenericDataPoints); + + for(unsigned int i = 0; i < pa_unNumGenericDataPoints; i++){ + pa_anDataTypeNamesArrayStart[i] = g_nStringIdANY; + } +} + +#ifdef FORTE_SUPPORT_MONITORING +void CFunctionBlock::setupEventMonitoringData(){ + if(0 != m_pstInterfaceSpec->m_nNumEIs){ + m_nEIMonitorCount = new forte::core::SMonitorEvent[m_pstInterfaceSpec->m_nNumEIs]; + } + + if(0 != m_pstInterfaceSpec->m_nNumEOs){ + m_nEOMonitorCount = new forte::core::SMonitorEvent[m_pstInterfaceSpec->m_nNumEOs]; + } +} + +////////////////////////////////////////////////////////////////////////////// +// EO-Monitor functions +////////////////////////////////////////////////////////////////////////////// +bool CFunctionBlock::startEIBreakpoint(TEventID p_nEventId){ + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId < cg_unInvalidPortId){ + m_nEIMonitorCount[p_nEventId].mBreakpointEnable = true; + } + return true; +} + +bool CFunctionBlock::stopEIBreakpoint(TEventID p_nEventId){ + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId < cg_unInvalidPortId){ + m_nEIMonitorCount[p_nEventId].mBreakpointEnable = false; + } + return true; +} + +bool CFunctionBlock::clearEIBreakpoint(TEventID p_nEventId){ + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId != cg_unInvalidPortId){ + forte::core::SMonitorEvent &monitorEventData(m_nEIMonitorCount[p_nEventId]); + if(monitorEventData.mBreakpointSet > 0){ + // Get Resource + //CResource &res = this->getResource(); + //res.startManagedObject(); + if(monitorEventData.mBreakpointEnable == true){ + monitorEventData.mBreakpointSet = forte::core::eOnce; // clear breakpoint, execute once + } + else{ + monitorEventData.mBreakpointSet = forte::core::eInactive; // clear breakpoint + } + } + } + return true; +} + +////////////////////////////////////////////////////////////////////////////// +// EI-Monitor functions +////////////////////////////////////////////////////////////////////////////// +bool CFunctionBlock::startEOBreakpoint(TEventID p_nEventId){ + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId < cg_unInvalidPortId){ + forte::core::SMonitorEvent &monitorEventData(m_nEOMonitorCount[p_nEventId]); + monitorEventData.mBreakpointEnable = true; + monitorEventData.mBreakpointSet = forte::core::eInactive; + } + return true; +} + +bool CFunctionBlock::stopEOBreakpoint(TEventID p_nEventId){ + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId < cg_unInvalidPortId){ + forte::core::SMonitorEvent &monitorEventData(m_nEOMonitorCount[p_nEventId]); + monitorEventData.mBreakpointEnable = false; + monitorEventData.mBreakpointSet = forte::core::eInactive; + } + return true; +} + +bool CFunctionBlock::clearEOBreakpoint(TEventID p_nEventId){ + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId != cg_unInvalidPortId){ + forte::core::SMonitorEvent &monitorEventData(m_nEOMonitorCount[p_nEventId]); + if(monitorEventData.mBreakpointSet > 0){ + // Get Resource + //CResource &res = this->getResource(); + //res.startManagedObject(); + if(monitorEventData.mBreakpointEnable == true){ + monitorEventData.mBreakpointSet = forte::core::eOnce; // clear breakpoint, execute once + } + else{ + monitorEventData.mBreakpointSet = forte::core::eInactive; // clear breakpoint + } + } + } + return true; +} + +bool CFunctionBlock::getEIBreakpoint(TEventID p_nEventId, bool & enable, int & set){ + bool ret = false; + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId < cg_unInvalidPortId){ + forte::core::SMonitorEvent &monitorEventData(m_nEIMonitorCount[p_nEventId]); + enable = monitorEventData.mBreakpointEnable; + set = monitorEventData.mBreakpointSet; // > 0; + ret = true; + } + return ret; +} + +bool CFunctionBlock::getEOBreakpoint(TEventID p_nEventId, bool & enable, int & set){ + bool ret = false; + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + if(p_nEventId < cg_unInvalidPortId){ + forte::core::SMonitorEvent &monitorEventData(m_nEOMonitorCount[p_nEventId]); + enable = monitorEventData.mBreakpointEnable; + set = monitorEventData.mBreakpointSet; // > 0; + ret = true; + } + return ret; +} + +CFunctionBlock *CFunctionBlock::getFB(forte::core::TNameIdentifier::CIterator &paNameListIt){ + CFunctionBlock *retVal = 0; + + if(paNameListIt.isLastEntry()){ + //only check for adpaters if it we have the last entry in the line + retVal = getAdapter(*paNameListIt); + } + + return retVal; +} + +////////////////////////////////////////////////////////////////////////////// +// Data-Monitor functions +////////////////////////////////////////////////////////////////////////////// +bool CFunctionBlock::forceData(CStringDictionary::TStringId pa_acName, const char * forceValue){ + + TPortId portID = getDOID(pa_acName); + if(portID != cg_unInvalidPortId){ + CIEC_ANY *poDO = getDO(portID); + poDO->setForced(true); + poDO->fromString(forceValue); + + + CDataConnection *con = getDOConUnchecked(portID); + if(con->isConnected()){ + CCriticalRegion criticalRegion(m_poResource->m_oResDataConSync); + con->writeData(poDO); + } + return true; + } + + portID = getDIID(pa_acName); + + if(portID != cg_unInvalidPortId){ + CIEC_ANY *poDI = getDI(portID); + poDI->setForced(true); + poDI->fromString(forceValue); + return true; + } + + return false; +} + +#endif //FORTE_SUPPORT_MONITORING diff --git a/src/core/funcbloc.h b/src/core/funcbloc.h new file mode 100644 index 000000000..1ea7d3289 --- /dev/null +++ b/src/core/funcbloc.h @@ -0,0 +1,607 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, nxtControl GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Gunnar Grabmaier, Smodic Rene, + * Gerhard Ebenhofer, Michael Hofmann, Martin Melik Merkumians, Ingo Hegny, + * Stanislav Meduna, Patrick Smejkal, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _FUNCBLOC_H_ +#define _FUNCBLOC_H_ + +#include +#include "mgmcmd.h" +#include "event.h" +#include "typelib.h" +#include "dataconn.h" +#include "eventconn.h" +#include "stringdict.h" +#include "../arch/devlog.h" +#include "iec61131_functions.h" +#include + +class CEventChainExecutionThread; +class CResource; +class CAdapter; + +#ifdef FORTE_SUPPORT_MONITORING +#include "mgmcmdstruct.h" +#include "monitoring.h" +#endif //FORTE_SUPPORT_MONITORING + +#ifndef FORTE_FB_DATA_ARRAY //with this check we can overwrite this define in a platform specific file (e.g., config.h) +/*! Define that adds the data array to a SIFB, simple FB or CFB + * May be overwritten by a platform specific version that adapts for example some alignment requirements + */ +#define FORTE_FB_DATA_ARRAY(a_nNumEOs, a_nNumDIs, a_nNumDOs, a_nNumAdapters) \ + union{ \ + TForteByte m_anFBConnData[genFBConnDataSizeTemplate::value]; \ + void *m_apoDummyConnPointerAlign; \ + };\ + union{ \ + TForteByte m_anFBVarsData[genFBVarsDataSizeTemplate::value]; \ + CIEC_ANY::TLargestUIntValueType m_uDummyDataAlign; \ + }; +#endif + +typedef CAdapter *TAdapterPtr; + +typedef TForteUInt8 TDataIOID; //!< \ingroup CORE Type for holding an data In- or output ID (max value 254) + +/*!\ingroup CORE\brief Structure to hold all data of adapters instantiated in the function block. + */ +struct SAdapterInstanceDef{ + CStringDictionary::TStringId m_nAdapterTypeNameID; //!< Adapter type name + CStringDictionary::TStringId m_nAdapterNameID; //!< Adapter instance name + bool m_bIsPlug; //!< Flag for distinction of adapter nature (plug/socket) +}; + +/*!\ingroup CORE\brief Structure to hold all the data for specifying a function block interface. + */ +struct SFBInterfaceSpec{ + TForteUInt8 m_nNumEIs; //!< Number of event inputs (max 254) + const CStringDictionary::TStringId* m_aunEINames; //!< List of the event input names + const TDataIOID* m_anEIWith; //!< Input WITH reference list. This list contains an array of input data ids. For each input event the assiciated data inputs are listed. The start for each input event is specified in the m_anEIWithIndexes field. The end is defined trough the value 255. + const TForteInt16* m_anEIWithIndexes; //!< Index list for each input event. This list gives for each input event an entry in the m_anEIWith. Input events are numbered starting from 0. if the input event has no assciated data inputs -1 is the entry at this event inputs postion. + TForteUInt8 m_nNumEOs; //!< Number of event outputs (max 254) + const CStringDictionary::TStringId* m_aunEONames; //!< List of the event output names + const TDataIOID* m_anEOWith; //!< Output WITH reference list. This list contains an array of output data ids. For each output event the assiciated data outputs are listed. The start for each output event is specified in the m_anEOWithIndexes field. The end is defined trough the value 255. + const TForteInt16* m_anEOWithIndexes; //!< Index list for each output event. This list gives for each output event an entry in the m_anEOWith. Output events are numbered starting from 0. if the output event has no assciated data outputs -1 is the entry at this event outputs postion. Additionally at the postion m_nNumEOs in this list an index to an own list in the m_anEOWith list is stored specifying all output data port that are not associated with any output event. That values will be updated on every FB invocation. + TForteUInt8 m_nNumDIs; //!< Number of data inputs (max 254) + const CStringDictionary::TStringId* m_aunDINames; //!< List of the data input names + const CStringDictionary::TStringId* m_aunDIDataTypeNames; //!< List of the data type names for the data inputs + TForteUInt8 m_nNumDOs; //!< Number of data outputs (max 254) + const CStringDictionary::TStringId* m_aunDONames; //!< List of the data output names + const CStringDictionary::TStringId* m_aunDODataTypeNames; //!< List of the data type names for the data outputs + TForteUInt8 m_nNumAdapters; //!< Number of Adapters + const SAdapterInstanceDef* m_pstAdapterInstanceDefinition; //!< List of adapter instances +}; + +class SFBInterfaceSpecforGenerics : public SFBInterfaceSpec{ + public: + SFBInterfaceSpecforGenerics(TForteUInt8 pa_nNumEIs, + const CStringDictionary::TStringId * const pa_aunEINames, + const TDataIOID * const pa_anEIWith, const TForteInt16 * const pa_anEIWithIndexes, + TForteUInt8 pa_nNumEOs, const CStringDictionary::TStringId * const pa_aunEONames, + const TDataIOID * const pa_anEOWith, const TForteInt16 * const pa_anEOWithIndexes, + TForteUInt8 pa_nNumDIs, const CStringDictionary::TStringId * const pa_aunDINames, + const CStringDictionary::TStringId * const pa_aunDIDataTypeNames, TForteUInt8 pa_nNumDOs, + const CStringDictionary::TStringId * const pa_aunDONames, + const CStringDictionary::TStringId * const pa_aunDODataTypeNames){ + m_nNumEIs = pa_nNumEIs; + m_aunEINames = pa_aunEINames; + m_anEIWith = pa_anEIWith; + m_anEIWithIndexes = pa_anEIWithIndexes; + m_nNumEOs = pa_nNumEOs; + m_aunEONames = pa_aunEONames; + m_anEOWith = pa_anEOWith; + m_anEOWithIndexes = pa_anEOWithIndexes; + m_nNumDIs = pa_nNumDIs; + m_aunDINames = pa_aunDINames; + m_aunDIDataTypeNames = pa_aunDIDataTypeNames; + m_nNumDOs = pa_nNumDOs; + m_aunDONames = pa_aunDONames; + m_aunDODataTypeNames = pa_aunDODataTypeNames; + m_nNumAdapters = 0; + m_pstAdapterInstanceDefinition = 0; + } + private: + SFBInterfaceSpecforGenerics(); +}; + +#ifdef FORTE_SUPPORT_MONITORING +namespace forte { + namespace core{ + struct SMonitorEvent; + } +} +#endif // FORTE_SUPPORT_MONITORING +/*!\ingroup CORE\brief Base class for all function blocks. + */ +class CFunctionBlock{ + public: + /*!\brief Possible states of a runable object. + * + */ + enum E_FBStates{ + e_RUNNING = 0, // in the most critical execution path of FORTE we are checking for this enum value it is faster if this is the zero entry + e_IDLE, e_STOPPED, e_KILLED + }; + + /*! \brief Indicator that the given EventID is an included adapter's eventID. + * + * This will allow 255 Input and Output Events. + * + * EventIDs > scm_nMaxInterfaceEvents: highByte indicates (AdapterID+1) + */ + static const TForteUInt16 scm_nMaxInterfaceEvents = 0x00FF; + + virtual ~CFunctionBlock(); + + /*!\brief Get the resource the function block is contained in. + */ + CResource &getResource(void){ + return *m_poResource; + } + + CResource *getResourcePtr(void){ + return m_poResource; + } + + /*!\brief Returns the type of this FB instance + */ + virtual CStringDictionary::TStringId getFBTypeId(void) const = 0; + /*!\brief Get the ID of a specific event input of the FB. + * + * \param pa_unEINameId StringId to the event input name. + * \return The ID of the event input or cg_nInvalidEventID. + */ + TEventID getEIID(CStringDictionary::TStringId pa_unEINameId) const{ + return static_cast(getPortId(pa_unEINameId, m_pstInterfaceSpec->m_nNumEIs, m_pstInterfaceSpec->m_aunEINames)); + } + + /*!\brief Get the ID of a specific event output of the FB. + * + * \param pa_unEONameId string id to the event output name. + * \return The ID of the event output or cg_nInvalidEventID. + */ + TEventID getEOID(CStringDictionary::TStringId pa_unEONameId) const{ + return static_cast(getPortId(pa_unEONameId, m_pstInterfaceSpec->m_nNumEOs, m_pstInterfaceSpec->m_aunEONames)); + } + + CEventConnection *getEOConection(CStringDictionary::TStringId paEONameId) const; + + /*!\brief Connects specific data input of a FB with a specific data connection. + * + * If the connection pointer is 0 then it is equal to a disconnect. Furthermore, if their is already a connection + * to the given data port the connection attempt will be rejected. However if the further connection attempt + * is done with the same connection object then it is a reconfiguration attempt for any data inputs. This is necessary + * when during the first connection the data type of the connection was not clear. + * + * \param pa_unDINameId StringID of the data input name. + * \param pa_poDataCon Pointer to the data connection the FB should be connected to. + * \return TRUE on success, FALSE if data output not exists or output is already connected. + */ + virtual bool connectDI(TPortId paDIPortId, CDataConnection *pa_poDataCon); + + /*! \brief Gets the index of the m_acDINames array of a specific data output of a FB + * + * \param pa_unDINameId StringId of the data input name. + * \return Returns index of the Data Input Array of a FB + */ + TPortId getDIID(CStringDictionary::TStringId pa_unDINameId) const{ + return getPortId(pa_unDINameId, m_pstInterfaceSpec->m_nNumDIs, m_pstInterfaceSpec->m_aunDINames); + } + + /*!\brief Get the pointer to a data input of the FB. + * + * \param pa_unDINameId ID of the data input name. + * \return Pointer to the data input or 0. If 0 is returned DataInput is ANY + */ + CIEC_ANY* getDataInput(CStringDictionary::TStringId pa_unDINameId); + + /*!\brief get the pointer to a data input using the portId as identifier + */ + CIEC_ANY* getDIFromPortId(TPortId paDIPortId); + + /*! \brief Gets the index of the m_acDONames array of a specific data output of a FB + * \param pa_unDONameId StringId of the data input name. + * \return Returns index of the Data Output Array of a FB + */ + TPortId getDOID(CStringDictionary::TStringId pa_unDONameId) const{ + return getPortId(pa_unDONameId, m_pstInterfaceSpec->m_nNumDOs, m_pstInterfaceSpec->m_aunDONames); + } + + CDataConnection *getDOConnection(CStringDictionary::TStringId paDONameId) const; + + /*!\brief if the data output is of generic type (i.e, ANY) this function allows an data connection to configure + * the DO with the specific type coming from the other end of the connection + */ + virtual bool configureGenericDO(TPortId paDOPortId, const CIEC_ANY &paRefValue); + + /*!\brief Get the pointer to a data output of the FB. + * + * \param pa_unDONameId StringID of the data output name. + * \return Pointer to the data output or 0. If 0 is returned DataOutput is ANY + */ + CIEC_ANY* getDataOutput(CStringDictionary::TStringId pa_unDONameId); + + /*!\brief Get the pointer to a variable of the FB. + * + * @param paNameList array of the name hierarchy the requested variable + * @param paNameListSize length of the array + * \return Pointer to the variable or 0. + * The variable may be input, output or in the case of a BFB an internal var. + */ + virtual CIEC_ANY* getVar(CStringDictionary::TStringId *paNameList, + unsigned int paNameListSize); + + /*!\brief Get the pointer to the adapter instance of the FB. + * + * \param pa_uAdapterNameId StringId of the adapter name. + * \return Pointer to the data output or 0. + */ + CAdapter* getAdapter(CStringDictionary::TStringId paAdapterNameId); + + TPortId getAddapterPortId(CStringDictionary::TStringId paAdapterNameId); + + /*!\brief Function that handles incoming events. + * + * \param pa_nEIID ID if the input event that has occurred. + * \param pa_poExecEnv Event chain execution environment the FB will be executed in (used for adding output events). + */ + void + receiveInputEvent(int pa_nEIID, CEventChainExecutionThread &pa_poExecEnv); + + /*!\brief Configuration interface used by the typelib to parameterize generic function blocks. + * + * \param pa_acConfigString A string containing the needed configuration data. + * \return TRUE if configuration went ok, else FALSE. + * + */ + virtual bool configureFB(const char *pa_acConfigString); + + void setupFBInterface(const SFBInterfaceSpec *pa_pstInterfaceSpec, TForteByte *pa_acFBConnData, + TForteByte *pa_acFBVarsData, bool pa_bManagesFBData); + + const SFBInterfaceSpec* getFBInterfaceSpec(){ + return m_pstInterfaceSpec; + } + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); + + /*!\brief Get/set the instance name + */ + CStringDictionary::TStringId getInstanceNameId(void) const{ + return m_nFBInstanceName; + } + ; + + const char *getInstanceName(void) const{ + return CStringDictionary::getInstance().get(m_nFBInstanceName); + } + + void setInstanceNameId(const CStringDictionary::TStringId pa_nInstanceNameId){ + m_nFBInstanceName = pa_nInstanceNameId; + } + + /*!\brief Get information if the runable object is deletable by a management command. + * + */ + bool getDeletable(void) const{ + return m_bDeletable; + } + ; + /*!\brief Set attribute to enable/disable the runable object deletion by a management command. + * + */ + void setDeletable(const bool &pa_bDelAble){ + m_bDeletable = pa_bDelAble; + } + ; + /*!\brief Return if the runable object is allowed to be deleted now. + * + * This is more complex then the simple deleteable flag as the current state has to be incorporated. + * According to IEC 61499-1 Figure 24 an FB is deleteable if it is not in the Running state + * \return true if currently all conditions are met to be deleteable + */ + bool isCurrentlyDeleteable(void) const{ + return ((m_bDeletable) && (m_enFBState != e_RUNNING)); + } + ; + + /*!\brief return the current execution state of the managed object + */ + E_FBStates getState(void) const{ + return m_enFBState; + } + ; + + template + struct genFBConnDataSizeTemplate{ + enum { + value = (sizeof(CEventConnection) * ta_nNumEOs + sizeof(TDataConnectionPtr) * ta_nNumDIs + + sizeof(CDataConnection) * ta_nNumDOs) + }; + }; + + static size_t genFBConnDataSize(unsigned int pa_nNumEOs, unsigned int pa_nNumDIs, + unsigned int pa_nNumDOs){ + return (sizeof(CEventConnection) * pa_nNumEOs + sizeof(TDataConnectionPtr) * pa_nNumDIs + + sizeof(CDataConnection) * pa_nNumDOs); + } + + template + struct genFBVarsDataSizeTemplate{ + enum { + value = (sizeof(CIEC_ANY) * ta_nNumDIs + sizeof(CIEC_ANY) * ta_nNumDOs + sizeof(TAdapterPtr) * ta_nNumAdapters) + }; + }; + + static size_t genFBVarsDataSize(unsigned int pa_nNumDIs, unsigned int pa_nNumDOs, + unsigned int pa_nNumAdapters = 0){ + return (sizeof(CIEC_ANY) * pa_nNumDIs + sizeof(CIEC_ANY) * pa_nNumDOs + sizeof(TAdapterPtr) * pa_nNumAdapters); + + } +#ifdef FORTE_SUPPORT_MONITORING + // public monitoring + void setUpdated(bool updated){ + m_updated = updated; + } + ; + + bool getUpdated(){ + return m_updated; + } + ; + + forte::core::SMonitorEvent &getEIMontiorData(TEventID pa_unEIID){ + return m_nEIMonitorCount[pa_unEIID]; + } + + forte::core::SMonitorEvent &getEOMontiorData(TEventID pa_unEOID){ + return m_nEOMonitorCount[pa_unEOID]; + } + + // DATA-Monitor-functions + bool forceData(CStringDictionary::TStringId pa_acDOName, const char * forceValue); + + bool startEIBreakpoint(TEventID p_nEventId); + bool startEOBreakpoint(TEventID p_nEventId); + bool stopEIBreakpoint(TEventID p_nEventId); + bool stopEOBreakpoint(TEventID p_nEventId); + bool clearEIBreakpoint(TEventID p_nEventId); + bool clearEOBreakpoint(TEventID p_nEventId); + + bool getEIBreakpoint(TEventID p_nEventId, bool & enable, int & set); + bool getEOBreakpoint(TEventID p_nEventId, bool & enable, int & set); + + /*!\brief get any internal FB referenced by the iterator to the name list + * + * This allows that also adapters and the internals of a CFB can be monitored. + */ + virtual CFunctionBlock *getFB(forte::core::TNameIdentifier::CIterator &paNameListIt); + + CFunctionBlock *getContainer(){ + return mContainer; + } + + void setContainer(CFunctionBlock *paContainer){ + mContainer = paContainer; + } + +#endif //FORTE_SUPPORT_MONITORING + protected: + + /*!\brief The main constructor for a function block. + * + * \param pa_poSrcRes pointer to the resource this function block is contained in (mainly necessary for management functions and service interfaces) + * \param pa_pstInterfaceSpec const pointer to the interface spec + * \param pa_nInstanceNameId string id + * \param pa_acFBConnData Byte-array for fb-specific connection data. It will need space for the event output connections, + * data input connections, and data output connections, in that order. The space requirements are: + * sizeof(TEventConnectionPtr) * Number of Event outputs + + * sizeof(TDataConnectionPtr) * Number of Data inputs + + * sizeof(TDataConnectionPtr) * Number of Data outputs + * \param pa_acFBVarsData Byte-array for fb-specific variable data. It will need space for the data inputs, data outputs, and adapters in that order. + * The space requirements are: + * sizeof(CIEC_ANY)) * Number of Data inputs + + * sizeof(CIEC_ANY)) * Number of Data outputs + + * sizeof(TAdapterPtr) * ta_nNumAdapters + */ + CFunctionBlock(CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, + TForteByte *pa_acFBVarsData); + + static TPortId getPortId(CStringDictionary::TStringId pa_unPortNameId, + TPortId pa_unMaxPortNames, const CStringDictionary::TStringId* pa_aunPortNames); + + static void generateGenericInterfacePointNameArray(const char * const pa_acPrefix, + CStringDictionary::TStringId* pa_anNamesArayStart, unsigned int pa_unNumGenericDataPoints); + static void generateGenericDataPointArrays(const char * const pa_acPrefix, + CStringDictionary::TStringId* pa_anDataTypeNamesArrayStart, + CStringDictionary::TStringId* pa_anNamesArrayStart, unsigned int pa_unNumGenericDataPoints); + + /*!\brief Function to send an output event of the FB. + * + * \param pa_nEO Event output ID where event should be fired. + */ + void sendOutputEvent(int pa_nEO); + + /*!\brief Function to send an output event via the adapter. + * + * \param pa_nAdapterID ID of Adapter in current FBs adapter list. + * \param pa_nEID Event ID where event should be fired. + */ + void sendAdapterEvent(int pa_nAdapterID, int pa_nEID) const; + + void setupAdapters(const SFBInterfaceSpec *pa_pstInterfaceSpec, TForteByte *pa_acFBData); + + + CEventConnection *getEOConUnchecked(TPortId paEONum) const { + return (mEOConns + paEONum); + } + + /*! \brief Get the data input with given number + * + * Attention this function will not perform any range checks on the pa_nDINum parameter! + * @param pa_nDINum number of the data input starting with 0 + * @return pointer to the data input + */ + TIEC_ANYPtr getDI(unsigned int pa_nDINum){ + return m_aoDIs + pa_nDINum; + } + + /*! \brief Get the data output with given number + * + * Attention this function will not perform any range checks on the pa_nDONum parameter! + * @param pa_nDONum number of the data output starting with 0 + * @return pointer to the data output + */ + CIEC_ANY *getDO(unsigned int pa_nDONum){ + return m_aoDOs + pa_nDONum; + } + + /*! \brief Get the data output connection with given number + * + * Attention this function will not perform any range checks on the pa_nDONum parameter! + * @param pa_nDONum number of the data output starting with 0 + * @return pointer to the data output connection + */ + CDataConnection *getDOConUnchecked(TPortId paDONum){ + return mDOConns + paDONum; + } + + const CIEC_ANY *getDO(unsigned int pa_nDONum) const{ + return m_aoDOs + pa_nDONum; + } + + /*!\brief Function to create an data type instance of given type + * + * @param pa_panDataTypeIds pointer to the data type ids. If the datatype + * is an Array to more values are taken from the array. If the given + * type is Any 0 is returned as necessary for maintaining the FB's interface. + * The functions puts the pointer in the datatype array to the next data point's id. + * @param pa_acDataBuf pointer to the data buffer which should be used by the data type to create + * @return on success... pointer to the datatype instance + * on error... 0 + */ + static CIEC_ANY *createDataPoint(const CStringDictionary::TStringId **pa_panDataTypeIds, + TForteByte *pa_acDataBuf); + + void freeAllData(); + + const SFBInterfaceSpec* m_pstInterfaceSpec; //!< Pointer to the interface specification + CEventConnection *mEOConns; //!< A list of event connections pointers storing for each event output the event connection. If the output event is not connected the pointer is 0. + TDataConnectionPtr *m_apoDIConns; //!< A list of data connections pointers storing for each data input the data connection. If the data input is not connected the pointer is 0. + CDataConnection *mDOConns; //!< A list of data connections pointers storing for each data output the data connection. If the data output is not connected the pointer is 0. + CEventChainExecutionThread *m_poInvokingExecEnv; //!< A pointer to the execution thread that invoked the FB. This value is stored here to reduce function parameters and reduce therefore stack usage. + CAdapter **m_apoAdapters; //!< A list of pointers to the adapters. This allows to implement a general getAdapter(). + + private: + /*!\brief Function providing the functionality of the FB (e.g. execute ECC for basic FBs). + * + * \param pa_nEIID Event input ID where event occurred. + */ + virtual void executeEvent(int pa_nEIID) = 0; + + /*!\brief Set the initial values of data inputs, outputs, and internal vars. + * + * Functionblocks which need to specify special initial values for their + * data inputs, outputs, or internal vars other than 0 need to implement this + * function. The function will be invoked on entering the IDLE state (i.e., + * on creation and on RESET). + */ + virtual void setInitialValues(){ + } + + //!declared but undefined copy constructor as we don't want FBs to be directly copied. + CFunctionBlock(const CFunctionBlock&); + + void configureGenericDI(TPortId paDIPortId, const CIEC_ANY *paRefValue); + + CResource *m_poResource; //!< A pointer to the resource containing the function block. + CIEC_ANY *m_aoDIs; //!< A list of pointers to the data inputs. This allows to implement a general getDataInput() + CIEC_ANY *m_aoDOs; //!< A list of pointers to the data outputs. This allows to implement a general getDataOutput() + +#ifdef FORTE_SUPPORT_MONITORING + void setupEventMonitoringData(); + + // monitoring stuff + forte::core::SMonitorEvent *m_nEOMonitorCount; + forte::core::SMonitorEvent *m_nEIMonitorCount; + CFunctionBlock *mContainer; //!< points to the cfb this FB may be contained in + bool m_updated; +#endif + + //! the instance name of the object + CStringDictionary::TStringId m_nFBInstanceName; + + /*!\brief Current state of the runnable object. + * + */ + E_FBStates m_enFBState; + + /*!\brief Flag to indicate if the FB manages the given data + * + * If true the FB will delete the data arrays given in the constructor or through the setupFBInterface function. + * This is especially necessary for configurable FBs which allocate the data exra on heap. + */ + bool m_bManagesFBData; + + /*!\brief Attribute defines if runnable object can be deleted by a management command. + * + * Default value is set to true. + * If the runnable object is declared in a device or resource specification it must be set to false. + */ + bool m_bDeletable; + + //FIXME remove these friends + friend class CAdapter; + +#ifdef FORTE_SUPPORT_MONITORING + friend class forte::core::CMonitoringHandler; +#endif //FORTE_SUPPORT_MONITORING +}; + +template<> +struct CFunctionBlock::genFBConnDataSizeTemplate<0, 0, 0>{ + enum { + value = 1 + }; +}; + +template<> +struct CFunctionBlock::genFBVarsDataSizeTemplate<0, 0, 0>{ + enum { + value = 1 + }; +}; + +typedef CFunctionBlock *TFunctionBlockPtr; + +#define FUNCTION_BLOCK_CTOR(fbclass) \ + fbclass(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : \ + CFunctionBlock( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData) + +#define FUNCTION_BLOCK_CTOR_WITH_BASE_CLASS(fbclass, fbBaseClass) \ + fbclass(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : \ + fbBaseClass( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData) + +#ifdef _WIN32 +#undef IN +#undef OUT +#endif + +#ifdef NET_OS +#undef IN +#undef OUT +#undef OPTIONAL +#endif + +#endif /*_FUNCBLOC_H_*/ diff --git a/src/core/iec61131_functions.cpp b/src/core/iec61131_functions.cpp new file mode 100644 index 000000000..d520ae504 --- /dev/null +++ b/src/core/iec61131_functions.cpp @@ -0,0 +1,119 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "iec61131_functions.h" + +/* +-------+ + | TRUNC | + ANY_REAL--| |--ANY_INT + +-------+*/ +#ifdef FORTE_USE_REAL_DATATYPE +TForteInt32 TRUNC(const CIEC_REAL& pa_roIN){ + return static_cast(pa_roIN); +} + +#ifdef FORTE_USE_LREAL_DATATYPE +TForteInt64 TRUNC(const CIEC_LREAL& pa_roIN){ + return static_cast(pa_roIN); +} +#endif +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +/* +--------------+ + | ADD_TOD_TIME | + TOD ---|IN1 |--- TOD + TIME ---|IN2 | + +--------------+*/ +const CIEC_TIME_OF_DAY ADD_TOD_TIME(const CIEC_TIME_OF_DAY& pa_roIN1, const CIEC_TIME& pa_roIN2){ + return static_cast(pa_roIN1 + pa_roIN2.getInMiliSeconds()); +} + +/* +-------------+ + | ADD_DT_TIME | + DT ---|IN1 |--- DT + TIME ---|IN2 | + +-------------+*/ +const CIEC_DATE_AND_TIME ADD_DT_TIME(const CIEC_DATE_AND_TIME& pa_roIN1, const CIEC_TIME& pa_roIN2){ + return static_cast(pa_roIN1 + pa_roIN2.getInMiliSeconds()); +} + +/* +--------------+ + | SUB_TOD_TIME | + TOD ---|IN1 |--- TOD + TIME ---|IN2 | + +--------------+*/ +const CIEC_TIME_OF_DAY SUB_TOD_TIME(const CIEC_TIME_OF_DAY& pa_roIN1, const CIEC_TIME& pa_roIN2){ + return static_cast(pa_roIN1 - pa_roIN2.getInMiliSeconds()); +} + +/* +-------------+ + | SUB_DT_TIME | + DT ---|IN1 |--- DT + TIME ---|IN2 | + +-------------+*/ +const CIEC_DATE_AND_TIME SUB_DT_TIME(const CIEC_DATE_AND_TIME& pa_roIN1, const CIEC_TIME& pa_roIN2){ + return static_cast(pa_roIN1 - pa_roIN2.getInMiliSeconds()); +} + +/* +-----------+ + | SUB_DT_DT | + DT ---|IN1 |--- TIME + DT ---|IN2 | + +-----------+*/ +const CIEC_TIME SUB_DT_DT(const CIEC_DATE_AND_TIME& pa_roIN1, const CIEC_DATE_AND_TIME& pa_roIN2){ + CIEC_TIME temp; + temp.setFromMiliSeconds(pa_roIN1 - pa_roIN2); + return temp; +} + +/* +-------------+ + | SUB_TOD_TOD | + TOD ---|IN1 |--- TIME + TOD ---|IN2 | + +-------------+*/ +const CIEC_TIME SUB_TOD_TOD(const CIEC_TIME_OF_DAY &pa_roIN1, const CIEC_TIME_OF_DAY &pa_roIN2){ + CIEC_TIME temp; + temp.setFromMiliSeconds(pa_roIN1 - pa_roIN2); + return temp; +} + +/* +---------------+ + | SUB_DATE_DATE | + DATE ---|IN1 |--- TIME + DATE ---|IN2 | + +---------------+*/ +const CIEC_TIME SUB_DATE_DATE(const CIEC_DATE &pa_roIN1, const CIEC_DATE &pa_roIN2){ + CIEC_TIME temp; + temp.setFromMiliSeconds(pa_roIN1 - pa_roIN2); + return temp; +} + +/* +-----------------+ + | CONCAT_DATE_TOD | + DATE ---|IN1 |--- DT + TOD ---|IN2 | + +-----------------+*/ +const CIEC_DATE_AND_TIME CONCAT_DATE_TOD(const CIEC_DATE& pa_roIN1, const CIEC_TIME_OF_DAY& pa_roIN2){ + CIEC_DATE_AND_TIME retVal; + + struct tm *pstTime = pa_roIN1.getTimeStruct(); + + time_t t = static_cast( pa_roIN2 / 1000ULL); + pstTime->tm_hour = (int) (t / 3600); + pstTime->tm_min = (int) ((t % 3600) / 60); + pstTime->tm_sec = (int) (t % 60); + + retVal.setDateAndTime(*pstTime, pa_roIN2.getMilliSeconds()); + return retVal; +} + +#endif diff --git a/src/core/iec61131_functions.h b/src/core/iec61131_functions.h new file mode 100644 index 000000000..577d758af --- /dev/null +++ b/src/core/iec61131_functions.h @@ -0,0 +1,923 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Monika Wenger, Ingo Hegny, Patrick Smejkal, Gerhard Ebenhofer, + * Matthias Plasch, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef IEC61131_FUNCTIONS_H_ +#define IEC61131_FUNCTIONS_H_ + +#include +#include +//#include +#include "datatypes/forte_real.h" +#include "datatypes/forte_lreal.h" +#include "datatypes/forte_any_int.h" +#include "datatypes/forte_any_bit.h" +#include "../arch/devlog.h" +#include "datatypes/forte_string.h" +//bring in the type conversion functions +#include "convert_functions.h" + +#ifdef VXWORKS +#define tanf(x) tan(x) +#define log10f(x) log10(x) +#define logf(x) log(x) +#define cosf(x) cos(x) +#define atanf(x) atan(x) +#define asinf(x) asin(x) +#define acosf(x) acos(x) +#define expf(x) exp(x) +#define sinf(x) sin(x) +#define sqrtf(x) sqrt(x) +#endif + +#ifdef FORTE_USE_WSTRING_DATATYPE +#include "datatypes/forte_wstring.h" +#endif + +/* numeric functions + * absolute value + * +----------+ + * | ABS | + * ANY_NUM ---| IN OUT |--- ANY_NUM + * +----------+ +*/ +template +const T ABS(const T& pa_roIN){ + return (0 > pa_roIN) ? T(pa_roIN * (-1)) : T((pa_roIN)); +} + +//CIEC_ANY::TLargestIntValueType ABS(CIEC_ANY::TLargestIntValueType pa_oIN){ +// return (0 > pa_oIN) ? (pa_oIN * -1) : pa_oIN; +//} + + +/* square root + * +----------+ + * | SQRT | + * ANY_REAL ---| IN OUT |--- ANY_REAL + * +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL SQRT(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(sqrtf(pa_roIN)); + } + +#ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL SQRT(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(sqrt(pa_roIN)); + } +#endif + +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* natural logarithm +* +----------+ +* | LN | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL LN(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(logf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL LN(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(log(pa_roIN)); + } + #endif + +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* Logarithm base 10 +* +----------+ +* | LOG | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL LOG(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(log10f(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL LOG(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(log10(pa_roIN)); + } + #endif +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* sine +* +----------+ +* | SIN | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL SIN(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(sinf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL SIN(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(sin(pa_roIN)); + } + #endif + +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* cosine in radians +* +----------+ +* | COS | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL COS(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(cosf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL COS(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(cos(pa_roIN)); + } + #endif +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* tangens in radians +* +----------+ +* | TAN | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL TAN(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(tanf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL TAN(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(tan(pa_roIN)); + } + #endif +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* Principal arc sine +* +----------+ +* | ASIN | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL ASIN(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(asinf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL ASIN(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(asin(pa_roIN)); + } + #endif + +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* Principal arc cosine +* +----------+ +* | ACOS | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL ACOS(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(acosf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL ACOS(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(acos(pa_roIN)); + } + #endif +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* Principal arc tangens +* +----------+ +* | ATAN | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL ATAN(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(atanf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL ATAN(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(atan(pa_roIN)); + } + #endif +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* Natural exponential +* +----------+ +* | EXP | +* ANY_REAL ---| IN OUT |--- ANY_REAL +* +----------+ +*/ +#ifdef FORTE_USE_REAL_DATATYPE + inline const CIEC_REAL EXP(const CIEC_REAL &pa_roIN){ + return CIEC_REAL(expf(pa_roIN)); + } + + #ifdef FORTE_USE_64BIT_DATATYPES + inline const CIEC_LREAL EXP(const CIEC_LREAL &pa_roIN){ + return CIEC_LREAL(exp(pa_roIN)); + } + #endif +#endif //#ifdef FORTE_USE_REAL_DATATYPE + +/* Bit string functions + * ANY_BIT (LWORD, DWORD, WORD, BYTE, BOOL) + * ANY_INT (LINT, DINT, INT, SINT, ULINT, UDINT, UINT, USINT) + * +-----+ + * | *** | + * ANY_BIT ---|IN |--- ANY_BIT + * ANY_INT ---|N | + * +-----+ + */ +#ifdef FORTE_USE_64BIT_DATATYPES + template const T ROL(const T& pa_roIn, const CIEC_ULINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)((pa_roIn << pa_roN.getUnsignedValue()) | (pa_roIn >> (sizeof(typename T::TValueType)*8 - pa_roN.getUnsignedValue())))); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } + + template const T ROR(const T& pa_roIn, const CIEC_ULINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)((pa_roIn >> pa_roN.getUnsignedValue()) | (pa_roIn << (sizeof(typename T::TValueType)*8 - pa_roN.getUnsignedValue())))); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } + + template const T SHL(const T& pa_roIn, const CIEC_ULINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)(pa_roIn << pa_roN.getUnsignedValue())); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } + + template const T SHR(const T& pa_roIn, const CIEC_ULINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)(pa_roIn >> pa_roN.getUnsignedValue())); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } +#else + template const T ROL(const T& pa_roIn, const CIEC_UDINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)((pa_roIn << pa_roN.getUnsignedValue()) | (pa_roIn >> (sizeof(typename T::TValueType)*8 - pa_roN.getUnsignedValue())))); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } + + template const T ROR(const T& pa_roIn, const CIEC_UDINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)((pa_roIn >> pa_roN.getUnsignedValue()) | (pa_roIn << (sizeof(typename T::TValueType)*8 - pa_roN.getUnsignedValue())))); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } + + template const T SHL(const T& pa_roIn, const CIEC_UDINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)(pa_roIn << pa_roN.getUnsignedValue())); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } + + template const T SHR(const T& pa_roIn, const CIEC_UDINT& pa_roN){ + if((true == pa_roN.isSigned() && 0 <= pa_roN.getSignedValue()) || false == pa_roN.isSigned()){ + return T((typename T::TValueType)(pa_roIn >> pa_roN.getUnsignedValue())); + } DEVLOG_ERROR("value of input N is less than zero"); + return T((typename T::TValueType)(0)); + } +#endif //#ifdef FORTE_USE_64BIT_DATATYPES + +/* Selection and comparison functions */ + +/* +-----+ + | AND | + ANY_BIT --|IN1 |--- ANY_BIT + : --| | + ANY_BIT --|INn | + +-----+ */ +template const T AND(const T& pa_roIN1, const T& pa_roIN2){ + return T((typename T::TValueType)(pa_roIN1 & pa_roIN2)); +} + +/* +-----+ + | OR | + ANY_BIT --|IN1 |--- ANY_BIT + : --| | + ANY_BIT --|INn | + +-----+ */ +template const T OR(const T& pa_roIN1, const T& pa_roIN2){ + return T((typename T::TValueType)(pa_roIN1 | pa_roIN2)); +} + +/* +-----+ + | XOR | + ANY_BIT --|IN1 |--- ANY_BIT + : --| | + ANY_BIT --|INn | + +-----+ */ +template const T XOR(const T& pa_roIN1, const T& pa_roIN2){ + return T((typename T::TValueType)(pa_roIN1 ^ pa_roIN2)); +} + +/* +-----+ + | NOT | + ANY_BIT --|IN1 |--- ANY_BIT + : --| | + ANY_BIT --|INn | + +-----+ */ +template const T NOT(const T& pa_roIN){ + if(pa_roIN.getDataTypeID() == CIEC_ANY::e_BOOL){ + return T((typename T::TValueType)(!pa_roIN)); + } + else{ + return T((typename T::TValueType)(~pa_roIN)); + } + +} + +/* +-----+ + | GT | + ANY_ELEMENTARY --|IN1 |--- BOOL + : --| | + ANY_ELEMENTARY --|INn | + +-----+ */ +template const CIEC_BOOL GT(const T& pa_roIN1, const T& pa_roIN2){ + CIEC_BOOL temp = false; + if(pa_roIN1 > pa_roIN2){ + temp = true; + } + return temp; +} + +/* +-----+ + | EQ | + ANY_ELEMENTARY --|IN1 |--- BOOL + : --| | + ANY_ELEMENTARY --|INn | + +-----+ */ +template const CIEC_BOOL EQ(const T& pa_roIN1, const T& pa_roIN2){ + CIEC_BOOL temp = false; + if(pa_roIN1 == pa_roIN2){ + temp = true; + } + return temp; +} + +/* +-----+ + | GE | + ANY_ELEMENTARY --|IN1 |--- BOOL + : --| | + ANY_ELEMENTARY --|INn | + +-----+ */ +template const CIEC_BOOL GE(const T& pa_roIN1, const T& pa_roIN2){ + CIEC_BOOL temp = false; + if(pa_roIN1 >= pa_roIN2){ + temp = true; + } + return temp; +} + +/* +-----+ + | LE | + ANY_ELEMENTARY --|IN1 |--- BOOL + : --| | + ANY_ELEMENTARY --|INn | + +-----+ */ +template const CIEC_BOOL LE(const T& pa_roIN1, const T& pa_roIN2){ + CIEC_BOOL temp = false; + if(pa_roIN1 <= pa_roIN2){ + temp = true; + } + return temp; +} + +/* +-----+ + | LT | + ANY_ELEMENTARY --|IN1 |--- BOOL + : --| | + ANY_ELEMENTARY --|INn | + +-----+ */ +template const CIEC_BOOL LT(const T& pa_roIN1, const T& pa_roIN2){ + CIEC_BOOL temp = false; + if(pa_roIN1 < pa_roIN2){ + temp = true; + } + return temp; +} + +/* +-----+ + | NE | + ANY_ELEMENTARY --|IN1 |--- BOOL + : --| | + ANY_ELEMENTARY --|INn | + +-----+ */ +template const CIEC_BOOL NE(const T& pa_roIN1, const T& pa_roIN2){ + CIEC_BOOL temp = false; + if(pa_roIN1 != pa_roIN2){ + temp = true; + } + return temp; +} + +/* + +-----+ + | SEL | + BOOL--|G |--ANY + ANY---|IN0 | + ANY---|IN1 | + +-----+ */ +template const T SEL(const CIEC_BOOL &G, const T& IN0, const T& IN1){ + return (G.operator bool()) ? IN1 : IN0; +} + +/* +-----+ + | MAX | + ANY_ELEMENTARY--| |--ANY_ELEMENTARY + : ---| | + ANY_ELEMENTARY--| | + +-----+ */ +template const T MAX(const T& pa_roIN1, const T& pa_roIN2){ + if(pa_roIN1 > pa_roIN2){ + return pa_roIN1; + } + else{ + return pa_roIN2; + } +} + +/* +-----+ + | MIN | + ANY_ELEMENTARY--| |--ANY_ELEMENTARY + : ---| | + ANY_ELEMENTARY--| | + +-----+ */ +template const T MIN(const T& pa_roIN1, const T& pa_roIN2){ + if(pa_roIN1 < pa_roIN2){ + return pa_roIN1; + } + else{ + return pa_roIN2; + } +} + +/* +-------+ + | LIMIT | + ANY_ELEMENTARY--|MN |--ANY_ELEMENTARY + ANY_ELEMENTARY--|IN | + ANY_ELEMENTARY--|MX | + +-------+ */ +template const T LIMIT(const T& pa_roMN, const T& pa_roIN, const T& pa_roMX){ + return MIN(MAX(pa_roIN, pa_roMN), pa_roMX); +} + +/* +-----+ + | MUX | + ANY_INT--|K |----ANY + ANY------| | + : ------| | + ANY------| | + +-----+ */ + + +/* +-----+ + | MOD | + ANY_INT--| |--ANY_NUM + : ---| | + ANY_INT--| | + +-----+ */ +template const T MOD(const T& pa_roIN1, const T& pa_roIN2){ + if(0 == pa_roIN2){ + return static_cast(0); + } + return static_cast(pa_roIN1.getSignedValue() % pa_roIN2.getSignedValue()); +} + +/* +------+ + | MOVE | + ANY --| |-- ANY + : ---| | + ANY --| | + +------+ */ +template const T MOVE(const T& pa_roIN){ + return static_cast(pa_roIN); +} + +/* +------+ + | EXPT | + ANY --| |-- ANY + : ---| | + ANY --| | + +------+ */ +template const T EXPT(const T& pa_roIN1, const T& pa_roIN2){ + return static_cast(pow(pa_roIN1, pa_roIN2)); +} + +/* +-----+ + | ADD | + ANY_MAGNITUDE--| |--ANY_MAGNITUDE + : ---| | + ANY_MAGNITUDE--| | + +-----+ */ +template const T ADD(const T& pa_roIN1, const T& pa_roIN2){ + return pa_roIN1 + pa_roIN2; +} + +/* +-----+ + | MUL | + ANY_NUM--| |--ANY_NUM + ---| | + ANY_NUM--| | + +-----+ */ +template const T MUL(const T& pa_roIN1, const T& pa_roIN2){ + return pa_roIN1 * pa_roIN2; +} + +/* +-----+ + | SUB | + ANY_MAGNITUDE--| |--ANY_MAGNITUDE + ANY_MAGNITUDE--| | + +-----+ */ +template const T SUB(const T& pa_roIN1, const T& pa_roIN2){ + return pa_roIN1 - pa_roIN2; +} + +/* +-----+ + | DIV | + ANY_NUM--| |--ANY_NUM + ANY_NUM--| | + +-----+ */ +template const T DIV(const T& pa_roIN1, const T& pa_roIN2){ + T temp = static_cast(pa_roIN1) / static_cast(pa_roIN2); + return temp; +} + +/* +-------+ + | TRUNC | + ANY_REAL--| |--ANY_INT + +-------+*/ +#ifdef FORTE_USE_REAL_DATATYPE +TForteInt32 TRUNC(const CIEC_REAL& pa_roIN); +#ifdef FORTE_USE_LREAL_DATATYPE +TForteInt64 TRUNC(const CIEC_LREAL& pa_roIN); +#endif +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES +/* +--------------+ + | ADD_TOD_TIME | + TOD ---|IN1 |--- TOD + TIME ---|IN2 | + +--------------+*/ +const CIEC_TIME_OF_DAY ADD_TOD_TIME(const CIEC_TIME_OF_DAY& pa_roIN1, const CIEC_TIME& pa_roIN2); + +/* +-------------+ + | ADD_DT_TIME | + DT ---|IN1 |--- DT + TIME ---|IN2 | + +-------------+*/ +const CIEC_DATE_AND_TIME ADD_DT_TIME(const CIEC_DATE_AND_TIME& pa_roIN1, const CIEC_TIME& pa_roIN2); + +/* +--------------+ + | SUB_TOD_TIME | + TOD ---|IN1 |--- TOD + TIME ---|IN2 | + +--------------+*/ +const CIEC_TIME_OF_DAY SUB_TOD_TIME(const CIEC_TIME_OF_DAY& pa_roIN1, const CIEC_TIME& pa_roIN2); + +/* +-------------+ + | SUB_DT_TIME | + DT ---|IN1 |--- DT + TIME ---|IN2 | + +-------------+*/ +const CIEC_DATE_AND_TIME SUB_DT_TIME(const CIEC_DATE_AND_TIME& pa_roIN1, const CIEC_TIME& pa_roIN2); + +/* +-----------+ + | SUB_DT_DT | + DT ---|IN1 |--- TIME + DT ---|IN2 | + +-----------+*/ +const CIEC_TIME SUB_DT_DT(const CIEC_DATE_AND_TIME& pa_roIN1, const CIEC_DATE_AND_TIME& pa_roIN2); + +/* +-------------+ + | SUB_TOD_TOD | + TOD ---|IN1 |--- TIME + TOD ---|IN2 | + +-------------+*/ +const CIEC_TIME SUB_TOD_TOD(const CIEC_TIME_OF_DAY &pa_roIN1, const CIEC_TIME_OF_DAY &pa_roIN2); + +/* +---------------+ + | SUB_DATE_DATE | + DATE ---|IN1 |--- TIME + DATE ---|IN2 | + +---------------+*/ +const CIEC_TIME SUB_DATE_DATE(const CIEC_DATE &pa_roIN1, const CIEC_DATE &pa_roIN2); + +/* +-----------------+ + | CONCAT_DATE_TOD | + DATE ---|IN1 |--- DT + TOD ---|IN2 | + +-----------------+*/ +const CIEC_DATE_AND_TIME CONCAT_DATE_TOD(const CIEC_DATE& pa_roIN1, const CIEC_TIME_OF_DAY& pa_roIN2); +#endif + +/* +---------+ + | MULTIME | + TIME ---|IN1 |--- TIME + ANY_NUM ---|IN2 | + +---------+*/ +#ifdef FORTE_USE_64BIT_DATATYPES +template const CIEC_TIME MULTIME(const CIEC_TIME& pa_roIN1, const T& pa_roIN2){ + return static_cast(pa_roIN1 * pa_roIN2); +} +#else +template const CIEC_TIME MULTIME(const CIEC_TIME& pa_roIN1, const T& pa_roIN2){ + return static_cast(pa_roIN1 * pa_roIN2); +} +#endif + +/* +---------+ + | DIVTIME | + TIME ---|IN1 |--- TIME + ANY_NUM ---|IN2 | + +---------+*/ +#ifdef FORTE_USE_64BIT_DATATYPES +template const CIEC_TIME DIVTIME(const CIEC_TIME& pa_roIN1, const T& pa_roIN2){ + if(0 != pa_roIN2){ + return static_cast(pa_roIN1 / pa_roIN2); + }else{ + return pa_roIN1; + } +} +#else +template const CIEC_TIME DIVTIME(const CIEC_TIME& pa_roIN1, const T& pa_roIN2 ){ + if(0 != pa_roIN2){ + return static_cast(pa_roIN1 / pa_roIN2); + }else{ + return pa_roIN1; + } +} +#endif + +/* Character string functions + * ANY_STRING (STRING, WSTRING) + * ANY_INT (LINT, DINT, INT, SINT, ULINT, UDINT, UINT, USINT) + * String length function + * +-----+ + * ANY_STRING--| LEN |--ANY_INT + * +-----+ + */ +#ifdef FORTE_USE_64BIT_DATATYPES +template CIEC_ULINT LEN(const T& pa_rsVal){ + return CIEC_ULINT(pa_rsVal.length()); +} +#else +template CIEC_UDINT LEN(const T& pa_rsVal){ + return CIEC_UDINT(pa_rsVal.length()); +} +#endif + +/* Leftmost L characters of IN + * +------+ + * | LEFT | + * ANY_STRING--|IN |--ANY_STRING + * ANY_INT-----|L | + * +------+ + */ +template const T LEFT(const T& pa_rsIn, const CIEC_ANY_INT& pa_roL){ + if(true == pa_roL.isSigned() && 0 > pa_roL.getSignedValue()){ + DEVLOG_ERROR("value of input L is less than zero"); + return pa_rsIn; + } + else{ + if(pa_rsIn.length() < pa_roL.getUnsignedValue()){ + DEVLOG_ERROR("string shorter than input L"); + return pa_rsIn; + } + else{ + T temp; + temp.reserve(static_cast(pa_roL.getUnsignedValue())); + memcpy(temp.getValue(), pa_rsIn.getValue(), static_cast(pa_roL.getUnsignedValue())); + temp.getValue()[pa_roL.getUnsignedValue()] = '\0'; + return temp.getValue(); + } + } +} + +/* Rightmost L characters of IN + * +-------+ + * | RIGHT | + * ANY_STRING--|IN |--ANY_STRING + * ANY_INT-----|L | + * +-------+ + */ +template const T RIGHT(const T& pa_rsIn, const CIEC_ANY_INT& pa_roL){ + if(true == pa_roL.isSigned() && 0 > pa_roL.getSignedValue()){ + DEVLOG_ERROR("value of input L is less than zero"); + return pa_rsIn; + } + else{ + if(pa_rsIn.length() < pa_roL.getUnsignedValue()){ + DEVLOG_ERROR("string shorter than input L"); + return pa_rsIn; + } + else{ + T temp; + temp.reserve(static_cast(pa_roL.getUnsignedValue())); + memcpy(temp.getValue(), pa_rsIn.getValue() + (pa_rsIn.length() - static_cast(pa_roL.getUnsignedValue())), static_cast(pa_roL.getUnsignedValue())); + temp.getValue()[pa_roL.getUnsignedValue()] = '\0'; + return temp.getValue(); + } + } +} + +/* L characters of IN, beginning at the P-th + * +-------+ + * | MID | + * ANY_STRING--|IN |--ANY_STRING + * ANY_INT-----|L | + * ANY_INT-----|P | + * +-------+ + */ +template const T MID(const T& pa_rsIn, const CIEC_ANY_INT& pa_roL, const CIEC_ANY_INT& pa_roP){ + if(true == pa_roP.isSigned() && 0 > pa_roP.getSignedValue()){ + DEVLOG_ERROR("value of input P is less than zero\n"); + return pa_rsIn; + } + else{ + CIEC_INT len_right = static_cast (pa_rsIn.length() - pa_roP.getUnsignedValue() + 1); + CIEC_INT len_left = static_cast(pa_roL.getUnsignedValue()); + return LEFT(RIGHT(pa_rsIn, len_right), len_left); + } +} + +/* Extensible concatenation + * +--------+ + * | CONCAT | + * ANY_STRING---| |--ANY_STRING + * : ---| | + * ANY_STRING---| | + * +--------+ + */ +/* + Example: + A := CONCAT('AB','CD','E') ; + is equivalent to + A := 'ABCDE' ; + * + */ +template const T CONCAT(const T& pa_rsIn1, const T& pa_rsIn2){ + T temp; + temp.reserve(static_cast(pa_rsIn1.length() + pa_rsIn2.length())); + strcpy(temp.getValue(), pa_rsIn1.getValue()); + strcat(temp.getValue(), pa_rsIn2.getValue()); + return temp.getValue(); +} + +/* Insert IN2 into IN1 after the P-th charaolcter position + * +--------+ + * | INSERT | + * ANY_STRING--|IN1 |--ANY_STRING + * ANY_STRING--|IN2 | + * ANY_INT-----|P | + * +--------+ + */ +template const T INSERT(const T& pa_rsIn1, const T& pa_rsIn2, const CIEC_ANY_INT& pa_roP){ + if(CIEC_UINT::scm_nMaxVal < (pa_rsIn1.length() + pa_rsIn2.length())){ + DEVLOG_ERROR("result would be longer than maximum allowed length"); + return pa_rsIn1; + } + CIEC_INT pos_right = static_cast(pa_rsIn1.length() - pa_roP.getSignedValue()); + return CONCAT(CONCAT(LEFT(pa_rsIn1, pa_roP), pa_rsIn2), RIGHT(pa_rsIn1, pos_right)); +} + +/* Delete L characters of IN, beginning at the P-th character position + * +--------+ + * | DELETE | + * ANY_STRING--|IN |--ANY_STRING + * ANY_INT-----|L | + * ANY_INT-----|P | + * +--------+ + * + Example: + A := DELETE(IN:='ABXYC',L:=2, P:=3) ; + is equivalent to + A := 'ABC' ;*/ + +#ifdef _WIN32 +#undef DELETE +#endif + +template const T DELETE(const T& pa_rsIn, const CIEC_ANY_INT& pa_roL, const CIEC_ANY_INT& pa_roP){ + CIEC_INT pos_right = static_cast(pa_rsIn.length() - (pa_roL.getSignedValue() + pa_roP.getSignedValue() - 1)); + CIEC_INT pos_left = static_cast(pa_roP.getSignedValue() - 1); + return CONCAT(LEFT(pa_rsIn, pos_left), RIGHT(pa_rsIn, pos_right)); +} + +/* +---------+ + | REPLACE | + ANY_STRING--|IN1 |--ANY_STRING + ANY_STRING--|IN2 | + ANY_INT-----|L | + ANY_INT-----|P | + +---------+ + Replace L characters of IN1 by IN2, starting at the P-th character position + Example: + A := REPLACE(IN1:='ABCDE',IN2:='X', + L:=2, P:=3) ; + is equivalent to + A := 'ABXE' ;*/ +template const T REPLACE(const T& pa_rsIn1, const T& pa_rsIn2, const CIEC_ANY_INT& pa_roL, const CIEC_ANY_INT& pa_roP){ + CIEC_INT pos_right = static_cast(pa_rsIn1.length() - (pa_roL.getSignedValue() + pa_roP.getSignedValue() - 1)); + CIEC_INT pos_left = static_cast(pa_roP.getSignedValue() - 1); + return CONCAT(CONCAT(LEFT(pa_rsIn1, pos_left), pa_rsIn2), RIGHT(pa_rsIn1, pos_right)); +} + +/* +-----------+ + | FIND | + ANY_STRING--|IN1 OUT |--ANY_INT + ANY_STRING--|IN2 | + +-----------+ + Find the character position of the beginning of the first occurrence of IN2 in IN1. If no occurrence of IN2 is found, then OUT := 0. + Example: + A := FIND(IN1:='ABCBC',IN2:='BC') ; + is equivalent to A := 2 ; + */ +template CIEC_ANY_INT FIND(const T& pa_rsIn1, const T& pa_rsIn2){ + const char* pc_Find = strstr(pa_rsIn1.getValue(), pa_rsIn2.getValue()); + CIEC_ANY_INT temp; + if (NULL != pc_Find) + { + temp.setSignedValue(pc_Find - pa_rsIn1.getValue()); + } + else + { + temp.setSignedValue(0); + } + return temp; +} + +/* +-----------+ + | TOUPPER | + ANY_STRING--|IN OUT |--ANY_STRING | + +-----------+ + Changes all characters of an ANY_STRING to its upper case equivalent. + Example: + A := TOUPPER(IN1:='abcAB'); + is equivalent to A := 'ABCAB' ; + */ +template const T TOUPPER(const T& pa_rsIn){ + T temp; + temp.reserve(static_cast(pa_rsIn.length())); + const char* orig = pa_rsIn.getValue(); + char* upper = temp.getValue(); + for (unsigned int i = 0; i <=pa_rsIn.length(); ++i) + { + upper[i] = toupper(orig[i]); + } + return temp; +} + +/* +-----------+ + | TOLOWER | + ANY_STRING--|IN OUT |--ANY_STRING | + +-----------+ + Changes all characters of an ANY_STRING to its upper case equivalent. + Example: + A := TOUPPER(IN1:='abcAB'); + is equivalent to A := 'abcab' ; + */ +template const T TOLOWER(const T& pa_rsIn){ + T temp; + temp.reserve(static_cast(pa_rsIn.length())); + const char* orig = pa_rsIn.getValue(); + char* upper = temp.getValue(); + for (unsigned int i = 0; i <=pa_rsIn.length(); ++i) + { + upper[i] = tolower(orig[i]); + } + return temp; +} +#endif /* IEC61131_FUNCTIONS_H_ */ diff --git a/src/core/if2indco.cpp b/src/core/if2indco.cpp new file mode 100644 index 000000000..2c4c60233 --- /dev/null +++ b/src/core/if2indco.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gunnar Grabmaier, Alois Zoitl, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "if2indco.h" + +CInterface2InternalDataConnection::CInterface2InternalDataConnection() : + CDataConnection(0, cg_unInvalidPortId, 0){ +} + +CInterface2InternalDataConnection::~CInterface2InternalDataConnection(){ + m_poValue = 0; // in interface data connections we are not allowed to delete the m_poValue +} + +void CInterface2InternalDataConnection::cloneInputInterfaceValue(void){ + for(TDestinationIdList::Iterator it = mDestinationIds.begin(); + it != mDestinationIds.end(); ++it){ + it->mFB->connectDI(it->mPortId, this); + } +} + +void CInterface2InternalDataConnection::setSource(CFunctionBlock *paSrcFB, TPortId paSrcPortId){ + CConnection::setSource(paSrcFB, paSrcPortId); + m_poValue = paSrcFB->getDIFromPortId(paSrcPortId); +} + diff --git a/src/core/if2indco.h b/src/core/if2indco.h new file mode 100644 index 000000000..0fae40595 --- /dev/null +++ b/src/core/if2indco.h @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gunnar Grabmaier, Alois Zoitl, Thomas Strasser, Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _IF2INDCO_H_ +#define _IF2INDCO_H_ + +#include "./datatypes/forte_any.h" +#include "dataconn.h" +#include "funcbloc.h" +#include "fortelist.h" + +/*! \ingroup CORE\brief class for handling a interface to internal data connection. + */ + +class CInterface2InternalDataConnection : public CDataConnection{ + public: + CInterface2InternalDataConnection(); + virtual ~CInterface2InternalDataConnection(); + + /*! \brief Clones interface data value (CFB data input) to internal FB data input. + */ + void cloneInputInterfaceValue(void); + + void setSource(CFunctionBlock *paSrcFB, TPortId paSrcPortId); + + protected: + + private: + +}; + +typedef CInterface2InternalDataConnection *TCInterface2InternalDataConnectionPtr; + +#endif /*IF2INDCO_H_*/ diff --git a/src/core/mgmcmd.h b/src/core/mgmcmd.h new file mode 100644 index 000000000..6758023b5 --- /dev/null +++ b/src/core/mgmcmd.h @@ -0,0 +1,241 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gunnar Grabmaier, Thomas Strasser, Gerhard Ebenhofer, + * Martin Melik Merkumians, Ingo Hegny, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _MGMCMD_H_ +#define _MGMCMD_H_ + +#include +#include "stringdict.h" +#include "../arch/datatype.h" + +/** \ingroup CORE \defgroup MGMCommands Management Commands Internal Representation + * \brief In this section the FORTE representation of the management commands is described. + */ +/*@{*/ + +/*!\brief Type for the management command (e.g. create, delete ...) + * + * The constants for the management commands are selected in the following way: + * - the lower 4 bit are the same as the corresponding command defined by the standard (see 61499-1: Table 6, p47). + * - the higher 4 bits are counted as they are listed in the Table 8, p48 in 61499-1. + * + */ +enum EMGMCommandType{ + cg_nMGM_CMD_Create_Group = 0x00, //!< Identifier for all create commands + + cg_nMGM_CMD_Create_DataType = 0x10, //!< Create a new data type definition in the FORTE. + cg_nMGM_CMD_Create_FBType = 0x20, //!< Create a new FB type definition in the FORTE. + + /*! \brief Create a new FB or resource instance. + * + * When creating a FB instance the parameters of the SManagementCMD are defined as: + * - m_sDestination = "" for creating within the device or "resname" for creating within a resource + * - m_sFistParam = FB Instance name + * - m_sSecondParam = FB Type + * - m_sAdditionalParams not used + */ + cg_nMGM_CMD_Create_FBInstance = 0x30, + + /*! \brief Create a new connection (can be event or data connection). + * + * When creating a connection the parameters of the SManagementCMD are defined as: + * - m_sDestination = "" for creating within the device or "resname" for creating within a resource + * - m_sFistParam = source of the connection given by: "fbname.output" + * - m_sSecondParam = destination of the connection given by: "fbname.intput" + * - m_sAdditionalParams not used + */ + cg_nMGM_CMD_Create_Connection = 0x40, + + cg_nMGM_CMD_Delete_Group = 0x01, //! +#include +#include + +namespace forte { + namespace core { + + /** \ingroup CORE \defgroup MGMCommands Management Command Exchange Representation + * \brief In this section the FORTE-internal data-exchange-structure for management command passing is described. + */ + /*@{*/ + + typedef util::CFixedCapazityVector TNameIdentifier; + + /*!\brief All the data necessary for processing a management command. + * + * The data of this structure is the internal FORTE representation of an IEC 61499 management command. + * e.g. create \ will result in the following data values: + * - m_nCMD = 0x30 + * - m_sDestination = "" + * - m_sFistParam = "START" + * - m_sSecondParam = "E_RESTART" + * - m_sAdditionalParams = "" + */ + struct SManagementCMD{ + /*!\brief An identification number for the requested command based on the definitons in the standard. + * + * See the constants in devadmin.h for the available commands + */ + EMGMCommandType mCMD; + + /*!\brief The destination of the command. + * + * if the destination is scm_nInvalidStringID device is the target. + * Otherwise a the TStringId of the resource's name the command + * should be exectued in is the target. + * FIXME if more than the resource should be supported (e.g. composite FBs) the type needs to be changed . + */ + CStringDictionary::TStringId mDestination; + + /*!\brief The first parameter of the command e.g. the FB name to create or the src of an connection. + * + * The data is stored as an array TStringIds for the hierarchical FB name identifier (e.g., SubApp1.FB, CFB.FB, FB.Port) + * Each level is stored as one entry in the vector. Top hierarchy is the first entry. + */ + TNameIdentifier mFirstParam; + + /*!\brief The second parameter of the command e.g. the FB name to create or the src of an connection. + * + * The data is stored as an array TStringIds for the hierarchical FB name identifier (e.g., SubApp1.FB, CFB.FB, FB.Port) + * Each level is stored as one entry in the vector. Top hierarchy is the first entry. + */ + TNameIdentifier mSecondParam; + + /*!\brief Additional params needed by a MGM command (e.g., to return results of query commands) + */ + CIEC_STRING mAdditionalParams; + + /*\brief pointer to the ID to generate the correct response */ + char *mID; + +#ifdef FORTE_SUPPORT_MONITORING + /*\brief pointer to the response to generate the correct response */ + CIEC_STRING mMonitorResponse; +#endif + + }; + + } // namespace core +} // namespace forte + +#endif /* MGMCMDSTRUCT_H_ */ diff --git a/src/core/monitor.cpp b/src/core/monitor.cpp new file mode 100644 index 000000000..71eeb08f3 --- /dev/null +++ b/src/core/monitor.cpp @@ -0,0 +1,381 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2014 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Hofmann, Gerhard Ebenhofer, Ingo Hegny, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "device.h" +#include "resource.h" +#include "monitor.h" +#include "class1objhand.h" +#include "mgmcmd.h" +#include "mgmcmdstruct.h" +#include "utils/criticalregion.h" + +T_DEVICE_MAP CMonitor::mDataWatches = T_DEVICE_MAP(); +CSyncObject CMonitor::mLockDataWatches = CSyncObject(); +TForteInt16 CMonitor::watchResponseSize = 0; +SEventEntry CMonitor::m_stTriggerEvent = SEventEntry(0,0); + +EMGMResponse CMonitor::executeMonitoringCommand(CDevice *pa_poDevice, SManagementCMD &pa_rstCommand){ + EMGMResponse eResp = e_RDY; + + switch(pa_rstCommand.m_nCMD){ + case cg_nMGM_CMD_Monitoring_Read_Watches: + if(!CMonitor::readWatches(pa_poDevice, pa_rstCommand.m_oMonitorResponse)){ + eResp = e_INVALID_OPERATION; + pa_rstCommand.m_oMonitorResponse.clear(); + } else { + DEVLOG_DEBUG("Response: %s \n", pa_rstCommand.m_oMonitorResponse.getValue()); + } + break; + case cg_nMGM_CMD_Monitoring_Get_Watches: + if(!CMonitor::getWatches(pa_poDevice, pa_rstCommand)){ + eResp = e_INVALID_OPERATION; + pa_rstCommand.m_oMonitorResponse.clear(); + } else { + DEVLOG_DEBUG("Response: %s \n", pa_rstCommand.m_oMonitorResponse.getValue()); + } + break; + default: + eResp = e_UNSUPPORTED_CMD; + break; + } + return eResp; +} + +CFunctionBlock * CMonitor::getFbPointer(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId){ + if(device == 0){ + return 0; + } + // Get functionblock + C61499Class1ObjectHandler &devObjHand = device->getObjectHandler(); + CResource *pres = (CResource*) devObjHand.getFB(resourceNameId); + if(pres == 0){ + return 0; + } + C61499Class1ObjectHandler &resObjHand = pres->getObjectHandler(); + CFunctionBlock *fb = resObjHand.getFB(fbNameId); + return fb; +} + + +bool CMonitor::wasTriggered(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId) { + CFunctionBlock *fb = CMonitor::getFbPointer(device, resourceNameId, fbNameId); + if (fb == 0){ + return false; + } + bool ret = fb->getUpdated(); + if(ret) { + fb->setUpdated(false); + } + return ret; +} + +CResource * CMonitor::getResPointer(CDevice *device, CStringDictionary::TStringId resourceID){ + if(device == 0){ + return 0; + } + // Get functionblock + C61499Class1ObjectHandler &devObjHand = device->getObjectHandler(); + CResource *pres = (CResource*) devObjHand.getFB(resourceID); + return pres; +} + + +bool CMonitor::isForced(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId){ + // Read Data from FB + + CFunctionBlock *fb = getFbPointer(device, resourceNameId, fbNameId); + if(fb == 0){ + return false; + } + + // get DataInput + return fb->isForced(portNameId); +} + +bool CMonitor::getWatches(CDevice *cDevice, SManagementCMD &pa_oCommand){ + // Go through DeviceMap and create a response-object for every watched fb + T_DEVICE_MAP_ITER rspResIter; + T_RESOURCE_CONTAINER_ITER rspFbIter; + T_FB_CONTAINER_ITER rspPortIter; + + T_DEVICE_MAP *dataWatches = CMonitor::getDeviceMap(); + + rspResIter = dataWatches->begin(); + pa_oCommand.m_oMonitorResponse.reserve(watchResponseSize); + while(rspResIter != dataWatches->end()){ + rspFbIter = rspResIter->second.begin(); + const char *fbRes = CStringDictionary::getInstance().get(rspResIter->first); + pa_oCommand.m_oMonitorResponse.append(""); + + while(rspFbIter != rspResIter->second.end()){ + const char *fbName = CStringDictionary::getInstance().get(rspFbIter->first); + pa_oCommand.m_oMonitorResponse.append(""); + //CFunctionBlock *fb = CMonitor::getFbPointer(this, fbRes, fbName); + //if (CMonitor::wasTriggered(this, fbRes, fbName)) { + // create containers for port/event-Data + + // Data Watch + rspPortIter = rspFbIter->second.addWatchList.begin(); + while(rspPortIter != rspFbIter->second.addWatchList.end()){ + if (pa_oCommand.m_oAdditionalParams.getValue()[0] == '*') { + pa_oCommand.m_oMonitorResponse.append("first, rspFbIter->first, *rspPortIter)){ + pa_oCommand.m_oMonitorResponse.append("true"); + } else { + pa_oCommand.m_oMonitorResponse.append("false"); + } + pa_oCommand.m_oMonitorResponse.append("\">"); + } else if (pa_oCommand.m_oAdditionalParams.getValue()[0] == 't' && CMonitor::isForced(cDevice, rspResIter->first, rspFbIter->first, *rspPortIter)) { + pa_oCommand.m_oMonitorResponse.append(""); + } else if (pa_oCommand.m_oAdditionalParams.getValue()[0] == 'f' && !CMonitor::isForced(cDevice, rspResIter->first, rspFbIter->first, *rspPortIter)) { + pa_oCommand.m_oMonitorResponse.append(""); + } + rspPortIter++; + pa_oCommand.m_oMonitorResponse.append(""); + } + rspFbIter++; + pa_oCommand.m_oMonitorResponse.append(""); + } + rspResIter++; + pa_oCommand.m_oMonitorResponse.append(""); + } + CMonitor::freeDeviceMap(); + dataWatches = 0; + return true; +} + +bool CMonitor::getEventCount(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventNameId, unsigned int & retValue){ + CFunctionBlock *fb = getFbPointer(device, resourceNameId, fbNameId); + if(fb == 0){ + return false; + } + + // get Event count + TEventID eventId = fb->getEIID(eventNameId); + if(eventId != cg_nInvalidEventID){ + retValue = fb->m_nEIMonitorCount[eventId].eventCount[fb->m_nEIMonitorCount[eventId].bufPos]; + return true; + } + + eventId = fb->getEOID(eventNameId); + if(eventId != cg_nInvalidEventID){ + retValue = fb->m_nEOMonitorCount[eventId].eventCount[fb->m_nEOMonitorCount[eventId].bufPos]; + return true; + } + // possibly No Event found + return false; +} + +bool CMonitor::writeData(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId, const char * Value){ + + CFunctionBlock *fb = getFbPointer(device, resourceNameId, fbNameId); + if(fb == 0){ + return false; + } + // get DataInput + unsigned int id = fb->getDIID(portNameId); + CIEC_ANY *pData = fb->getDataInput(id); + if(pData != 0){ + pData->fromString(Value); + return true; + } + + // get DataOutput + id = fb->getDIID(portNameId); + pData = fb->getDataOutput(id); + if(pData != 0){ + pData->fromString(Value); + return true; + } + return false; +} + +bool CMonitor::startBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId){ + + CFunctionBlock *fb = getFbPointer(device, resourceNameId, fbNameId); + if(fb == 0){ + return false; + } + + // start Event counting + TEventID eventId = fb->getEIID(portNameId); + if(eventId != cg_nInvalidEventID){ + fb->startEIBreakpoint(eventId); + return true; + } + + eventId = fb->getEOID(portNameId); + if(eventId != cg_nInvalidEventID){ + fb->startEOBreakpoint(eventId); + return true; + } + // possibly No Event found + return false; +} +bool CMonitor::stopBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId){ + + CFunctionBlock *fb = getFbPointer(device, resourceNameId, fbNameId); + if(fb == 0){ + return false; + } + + // start Event counting + TEventID eventId = fb->getEIID(portNameId); + if(eventId != cg_nInvalidEventID){ + fb->stopEIBreakpoint(eventId); + return true; + } + + eventId = fb->getEOID(portNameId); + if(eventId != cg_nInvalidEventID){ + fb->stopEOBreakpoint(eventId); + return true; + } + // possibly No Event found + return false; +} + +bool CMonitor::clearBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId){ + + CFunctionBlock *fb = getFbPointer(device, resourceNameId, fbNameId); + if(fb == 0){ + return false; + } + + // clear Breakpoint + TEventID eventId = fb->getEIID(portNameId); + if(eventId != cg_nInvalidEventID){ + fb->clearEIBreakpoint(eventId); + //TODO check why trigger an event on clearing a break point + //triggerEvent(device, resourceNameId, fbNameId, portNameId); + return true; + } + + eventId = fb->getEOID(portNameId); + if(eventId != cg_nInvalidEventID){ + fb->clearEOBreakpoint(eventId); + //TODO check why trigger an event on clearing a break point + //triggerEvent(device, resourceNameId, fbNameId, portNameId); + return true; + } + // possibly No Event found + return false; +} + + +bool CMonitor::addBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId){ + + + T_DEVICE_MAP::iterator resIter; + T_RESOURCE_CONTAINER::iterator fbIter; + T_FB_CONTAINER_ITER portIter; + + if(CMonitor::startBreakpoint(device, resourceNameId, fbNameId, portNameId) == false){ + return false; + } + + { + CCriticalRegion criticalRegion(mLockDataWatches); + + // Test if Resource is in device, otherwise add it + resIter = mDataWatches.find(resourceNameId); + if(resIter == mDataWatches.end()){ + T_RESOURCE_CONTAINER newResCont; + mDataWatches[resourceNameId] = newResCont; + resIter = mDataWatches.find(resourceNameId); + } + + // Test if FB is in Resource, otherwise add it + fbIter = resIter->second.find(fbNameId); + if(fbIter == resIter->second.end()){ + T_FB_CONTAINER newFbCont; + resIter->second[fbNameId] = newFbCont; + fbIter = resIter->second.find(fbNameId); + } + + // Test if Port is in FB, otherwise add it + portIter = std::find(fbIter->second.breakpointList.begin(), fbIter->second.breakpointList.end(),portNameId); + if(portIter == fbIter->second.breakpointList.end()){ + fbIter->second.breakpointList.push_back(portNameId); + }else{} // port already inserted + } //End Critical region + return true; +} +void CMonitor::removeBreakpoint(CStringDictionary::TStringId fbResId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId){ + + + T_DEVICE_MAP::iterator resIter; + T_RESOURCE_CONTAINER::iterator fbIter; + T_FB_CONTAINER_ITER portIter; + + CCriticalRegion criticalRegion(mLockDataWatches); + + // Test if Resource is in device, otherwise do nothing + resIter = mDataWatches.find(fbResId); + if(resIter != mDataWatches.end()){ + // Test if FB is in Resource, otherwise do nothing + fbIter = resIter->second.find(fbNameId); + if(fbIter != resIter->second.end()){ + // Test if Port is in FB, otherwise do nothing + portIter = std::find(fbIter->second.breakpointList.begin(), fbIter->second.breakpointList.end(),portNameId); + if(portIter != fbIter->second.breakpointList.end()){ + fbIter->second.breakpointList.erase(portIter); + } + + // clean up unused maps/lists + if(fbIter->second.addWatchList.size() == 0 && fbIter->second.breakpointList.size() == 0){ + resIter->second.erase(fbIter); + } + } + // clean up unused maps/lists + //if(resIter->second.size() == 0){ + // mDataWatches.erase(resIter); + //} + } +} + +bool CMonitor::GetBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventNameId, bool & enabled, int & set){ + // Read Data from FB + + CFunctionBlock *fb = getFbPointer(device, resourceNameId, fbNameId); + if(fb == 0){ + return false; + } + + // check events + TEventID eventId = fb->getEIID(eventNameId); + if(eventId != cg_nInvalidEventID){ + return fb->getEIBreakpoint(eventId, enabled, set); +// return true; + } + eventId = fb->getEOID(eventNameId); + if(eventId != cg_nInvalidEventID){ + return fb->getEOBreakpoint(eventId, enabled, set); + //return true; + } + return false; +} + diff --git a/src/core/monitor.h b/src/core/monitor.h new file mode 100644 index 000000000..df15259f8 --- /dev/null +++ b/src/core/monitor.h @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Hofmann, Gerhard Ebenhofer, Alois Zoitl, Ingo Hegny + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef MONITOR_H_ +#define MONITOR_H_ + +#ifdef min +#undef min +#endif + +#ifdef max +#undef max +#endif + +#include +#include +#include +#include + +#include "resource.h" +#include "stringdict.h" +#include "sync.h" + +typedef struct{ + std::string resource; + std::string fbName; + std::string portName; +} T_DATAWATCH; + +typedef CStringDictionary::TStringId T_PORT_ID; +typedef struct{ + std::list addWatchList; + std::list breakpointList; +} T_FB_CONTAINER; + +typedef std::map T_RESOURCE_CONTAINER; +typedef std::map T_DEVICE_MAP; +typedef T_DEVICE_MAP::iterator T_DEVICE_MAP_ITER; +typedef T_RESOURCE_CONTAINER::iterator T_RESOURCE_CONTAINER_ITER; +typedef std::list ::iterator T_FB_CONTAINER_ITER; + + +class CMonitor{ +public: + static T_DEVICE_MAP mDataWatches; + // Get Iterators + static T_DEVICE_MAP * getDeviceMap(){ + mLockDataWatches.lock(); + return &mDataWatches; + } + + // this function is for locks + static void freeDeviceMap(){ + mLockDataWatches.unlock(); + } + + static EMGMResponse executeMonitoringCommand(CDevice *pa_poDevice, SManagementCMD &pa_rstCommand); + + // Event Count + /*! \brief start counting of fired events + * + * Start the eventcounting of a specific port of a functionblock. + * \param device pointer to device + * \param resourceNameId StringID of the name of the resource in which the FB is located + * \param fbNameId StringID of the name of the functionblock + * \param eventID StringID of the name of the event + * \return returns true when the counter was successfully started + */ + static bool startEventCount(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventID); + /*! \brief stop counting of fired events + * + * Stop the eventcounting of a specific port of a functionblock. + * \param device pointer to device + * \param resourceName name of the resource in which the FB is located + * \param fbID StringID of the name of the functionblock + * \param eventID StringID of the name of the event + * \return returns true when the counter was successfully stopped + */ + static bool stopEventCount(CDevice *device, const char *resourceName, CStringDictionary::TStringId fbID, CStringDictionary::TStringId eventID); + /*! \brief get counted events from eventcounter + * + * Returns the current status of the eventcounter. + * \param device pointer to device + * \param resourceNameId StringID of the name of the resource in which the FB is located + * \param fbNameId StringID of the name of the functionblock + * \param eventID StringID of the name of the event + * \param retValue reference to returnvalue, counted events + * \return returns true when the counter was successfully read + */ + static bool getEventCount(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventID, unsigned int & retValue); + + // Get Data + /*! \brief get the value from a dataport of a functionblock + * + * Reads the current value of a dataport. + * \param device pointer to device + * \param resourceNameId StringID of the name of the resource in which the FB is located + * \param fbNameId StringID of the name of the functionblock + * \param portNameId StringID of the name of the event + * \param pa_acValue pointer to char-Array for return-value + * \param pa_nBufferSize size of the provided buffer + * \param forced reference for returning the forced-flag + * \return returns true when the counter was successfully read + */ + static bool GetData(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId, char* pa_acValue, unsigned int pa_nBufferSize, bool & forced); + + // Write Data + /*! \brief overwrite a value to a dataport + * + * Simply overwrites the current value of a port. this feature is only reasonable for output ports. Inputport are overwritten + * with the new value, so the written value is instantely overwritten. + * \param device pointer to device + * \param resourceNameId StringID of the name of the resource in which the FB is located + * \param fbNameId StringID of the name of the functionblock + * \param portNameId StringID of the name of the event + * \param Value value which will be written + * \return returns true when the counter was successfully read + */ + static bool writeData(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId, const char * Value); + + + + static bool startBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventID); + static bool stopBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventID); + static bool clearBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventID); + static bool GetBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId eventID, bool & enabled, int & set); + static bool addBreakpoint(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId); + + static bool readWatches(CDevice *cDevice, CIEC_STRING &pa_roResponse); + static bool getWatches(CDevice *cDevice, SManagementCMD &pa_oCommand); + /*! \brief internal function, get a pointer from the real functionblock + * + * This function helps getting a grip of the functionblock + * which will be modified. + * \param device pointer to device + * \param resourceNameId StringID of the name of the resource in which the FB is located + * \param fbNameId StringID of thee name of the functionblock + * \return pointer to the functionblock + */ + static CFunctionBlock * getFbPointer(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId); + static bool wasTriggered(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId); + static bool isForced(CDevice *device, CStringDictionary::TStringId resourceNameId, CStringDictionary::TStringId fbNameId, CStringDictionary::TStringId portNameId); + + +protected: + + static void removeBreakpoint(CStringDictionary::TStringId resourceID, CStringDictionary::TStringId fbID, CStringDictionary::TStringId portNameId); + + + static CResource * getResPointer(CDevice *device, CStringDictionary::TStringId resourceID); + + static CSyncObject mLockDataWatches; + static TForteInt16 watchResponseSize; + static SEventEntry m_stTriggerEvent; +}; + +#endif /* MONITOR_H_ */ diff --git a/src/core/monitoring.cpp b/src/core/monitoring.cpp new file mode 100644 index 000000000..9e723a231 --- /dev/null +++ b/src/core/monitoring.cpp @@ -0,0 +1,495 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "monitoring.h" +#include "resource.h" +#include "utils/criticalregion.h" + +using namespace forte::core; + +CMonitoringHandler::CMonitoringHandler(CResource &paResource) : + mTriggerEvent(0, 0), + mResource(paResource){ + +} + +EMGMResponse CMonitoringHandler::executeMonitoringCommand(SManagementCMD &paCommand){ + EMGMResponse retVal = e_UNSUPPORTED_CMD; + + switch (paCommand.mCMD){ + case cg_nMGM_CMD_Monitoring_Add_Watch: + retVal = addWatch(paCommand.mFirstParam); + break; + case cg_nMGM_CMD_Monitoring_Remove_Watch: + retVal = removeWatch(paCommand.mFirstParam); + break; + case cg_nMGM_CMD_Monitoring_Read_Watches: + retVal = readWatches(paCommand.mMonitorResponse); + break; + case cg_nMGM_CMD_Monitoring_Get_Watches: + retVal = + getWatches(paCommand.mMonitorResponse, paCommand.mAdditionalParams.getValue()[0]); + break; + case cg_nMGM_CMD_Monitoring_Force: + retVal = forceValue(paCommand.mFirstParam, paCommand.mAdditionalParams); + break; + case cg_nMGM_CMD_Monitoring_ClearForce: + retVal = clearForce(paCommand.mFirstParam); + break; + case cg_nMGM_CMD_Monitoring_Trigger_Event: + retVal = triggerEvent(paCommand.mFirstParam); + break; + case cg_nMGM_CMD_Monitoring_Reset_Event_Count: + retVal = resetEventCount(paCommand.mFirstParam); + break; + default: + break; + } + return retVal; +} + +CFunctionBlock* CMonitoringHandler::getFB(forte::core::TNameIdentifier &paNameList){ + forte::core::TNameIdentifier::CIterator runner(paNameList.begin()); + + CFunctionBlock *fb = mResource.getContainedFB(runner); + if((0 != fb) && (!runner.isLastEntry())){ + ++runner; + fb = fb->getFB(runner); + } + return fb; +} + +EMGMResponse CMonitoringHandler::addWatch(forte::core::TNameIdentifier &paNameList){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + + CStringDictionary::TStringId portName = paNameList.back(); + paNameList.popBack(); + CFunctionBlock *fB = getFB(paNameList); + + if(0 != fB){ + SFBMonitoringEntry &poFBMonitoringEntry(findOrCreateFBMonitoringEntry(fB)); + + CIEC_ANY *poDataVal = fB->getVar(&portName, 1); + if(0 != poDataVal){ + addDataWatch(poFBMonitoringEntry, portName, *poDataVal); + eRetVal = e_RDY; + } + else{ + TEventID unEventId = fB->getEIID(portName); + if(cg_nInvalidEventID != unEventId){ + addEventWatch(poFBMonitoringEntry, portName, fB->getEIMontiorData(unEventId)); + eRetVal = e_RDY; + } + else{ + unEventId = fB->getEOID(portName); + if(cg_nInvalidEventID != unEventId){ + addEventWatch(poFBMonitoringEntry, portName, fB->getEOMontiorData(unEventId)); + eRetVal = e_RDY; + } + } + } + } + + return eRetVal; +} + +EMGMResponse CMonitoringHandler::removeWatch(forte::core::TNameIdentifier &paNameList){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + + CStringDictionary::TStringId portName = paNameList.back(); + paNameList.popBack(); + CFunctionBlock *fB = getFB(paNameList); + if(0 != fB){ + TFBMonitoringList::Iterator itRefNode = mFBMonitoringList.end(); //needed for deleting the entry from the list + TFBMonitoringList::Iterator itRunner = mFBMonitoringList.begin(); + + while(itRunner != mFBMonitoringList.end()){ + if(itRunner->m_poFB == fB){ + SFBMonitoringEntry &poFBMonitoringEntry(*itRunner); + + if(!removeDataWatch(poFBMonitoringEntry, portName)){ + if(!removeEventWatch(poFBMonitoringEntry, portName)){ + //element is not watched end search and return error + break; + } + } + + if((poFBMonitoringEntry.m_lstWatchedDataPoints.isEmpty()) + && (poFBMonitoringEntry.m_lstWatchedEventPoints.isEmpty())){ + //no further values are monitored so remove the entry + if(itRefNode == mFBMonitoringList.end()){ + //we have the first entry in the list + mFBMonitoringList.pop_front(); + } + else{ + mFBMonitoringList.eraseAfter(itRefNode); + } + } + eRetVal = e_RDY; + break; + } + + itRefNode = itRunner; + ++itRunner; + } + } + return eRetVal; +} + +EMGMResponse CMonitoringHandler::readWatches(CIEC_STRING &paResponse){ + paResponse.clear(); + if(0 == mResource.getResourcePtr()){ + //we are in the device + for(CFBContainer::TFunctionBlockList::Iterator itRunner = mResource.getFBList().begin(); + itRunner != mResource.getFBList().end(); + ++itRunner){ + ((CResource*) (*itRunner))->getMonitoringHandler().readResourceWatches(paResponse); + } + } + else{ + //we are within a resource + readResourceWatches(paResponse); + } + + return e_RDY; +} + +EMGMResponse CMonitoringHandler::getWatches(CIEC_STRING &paResponse, char paQualifier){ + paResponse.clear(); + if(0 == mResource.getResourcePtr()){ + //we are in the device + for(CFBContainer::TFunctionBlockList::Iterator itRunner = mResource.getFBList().begin(); + itRunner != mResource.getFBList().end(); + ++itRunner){ + ((CResource*) (*itRunner))->getMonitoringHandler().getResourceWatches(paResponse, paQualifier); + } + } + else{ + //we are within a resource + getResourceWatches(paResponse, paQualifier); + } + + return e_RDY; +} + +EMGMResponse CMonitoringHandler::forceValue(forte::core::TNameIdentifier &paNameList, + CIEC_STRING &paValue){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + CStringDictionary::TStringId portName = paNameList.back(); + paNameList.popBack(); + CFunctionBlock *fB = getFB(paNameList); + + if(0 != fB){ + eRetVal = (fB->forceData(portName, paValue.getValue())) ? e_RDY : e_INVALID_DST; + } + return eRetVal; +} + +EMGMResponse CMonitoringHandler::clearForce(forte::core::TNameIdentifier &paNameList){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + CStringDictionary::TStringId portName = paNameList.back(); + paNameList.popBack(); + CFunctionBlock *fB = getFB(paNameList); + + if(0 != fB){ + CIEC_ANY *poDataVal = fB->getVar(&portName, 1); + if(0 != poDataVal){ + poDataVal->setForced(false); + eRetVal = e_RDY; + } + else{ + eRetVal = e_INVALID_DST; + } + } + return eRetVal; +} + +EMGMResponse CMonitoringHandler::triggerEvent(forte::core::TNameIdentifier &paNameList){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + CStringDictionary::TStringId portName = paNameList.back(); + paNameList.popBack(); + CFunctionBlock *fB = getFB(paNameList); + if(0 != fB){ + TEventID eventId = fB->getEIID(portName); + if(cg_nInvalidEventID != eventId){ + //only a single event can be triggered simultaneously (until it is executed by ecet!) + //otherwise the triggerEvent structure needs to be moved to another place! + mTriggerEvent.mFB = fB; + mTriggerEvent.mPortId = eventId; + mResource.getResourceEventExecution()->startEventChain(&mTriggerEvent); + eRetVal = e_RDY; + } + else{ + eventId = fB->getEOID(portName); + if(cg_nInvalidEventID != eventId){ + fB->m_poInvokingExecEnv = mResource.getResourceEventExecution(); + fB->sendOutputEvent(eventId); + mResource.getResourceEventExecution()->resumeSelfSuspend(); + eRetVal = e_RDY; + } + } + + } + return eRetVal; +} + +EMGMResponse CMonitoringHandler::resetEventCount(forte::core::TNameIdentifier &paNameList){ + EMGMResponse eRetVal = e_NO_SUCH_OBJECT; + CStringDictionary::TStringId portName = paNameList.back(); + paNameList.popBack(); + CFunctionBlock *fB = getFB(paNameList); + if(0 != fB){ + TEventID eventId = fB->getEIID(portName); + SMonitorEvent *pstEventMonitorData = 0; + + if(cg_nInvalidEventID != eventId){ + pstEventMonitorData = &fB->getEIMontiorData(eventId); + } + else{ + eventId = fB->getEOID(portName); + if(cg_nInvalidEventID != eventId){ + pstEventMonitorData = &fB->getEOMontiorData(eventId); + } + } + if(0 != pstEventMonitorData){ + CCriticalRegion criticalRegion(fB->getResource().m_oResDataConSync); + pstEventMonitorData->mMonitorEventData[pstEventMonitorData->mBufPos].mEventCount = 0; + eRetVal = e_RDY; + } + } + return eRetVal; +} + +CMonitoringHandler::SFBMonitoringEntry &CMonitoringHandler::findOrCreateFBMonitoringEntry( + CFunctionBlock *paFB){ + for(TFBMonitoringList::Iterator itRunner = mFBMonitoringList.begin(); + itRunner != mFBMonitoringList.end(); ++itRunner){ + if(itRunner->m_poFB->getInstanceNameId() == paFB->getInstanceNameId()){ + return *itRunner; + } + } + + mFBMonitoringList.push_back(SFBMonitoringEntry()); + TFBMonitoringList::Iterator itLastEntry(mFBMonitoringList.back()); + itLastEntry->m_poFB = paFB; + return *itLastEntry; +} + +void CMonitoringHandler::addDataWatch(SFBMonitoringEntry &paFBMonitoringEntry, + CStringDictionary::TStringId paPortId, CIEC_ANY &paDataVal){ + for(TDataWatchList::Iterator itRunner = paFBMonitoringEntry.m_lstWatchedDataPoints.begin(); + itRunner != paFBMonitoringEntry.m_lstWatchedDataPoints.end(); ++itRunner){ + if(itRunner->mPortId == paPortId){ + //the data point is already in the watch list + return; + } + } + paFBMonitoringEntry.m_lstWatchedDataPoints.push_back(SDataWatchEntry(paPortId, paDataVal)); +} + +bool CMonitoringHandler::removeDataWatch(SFBMonitoringEntry &paFBMonitoringEntry, + CStringDictionary::TStringId paPortId){ + bool bRetVal = false; + + TDataWatchList::Iterator itRunner = paFBMonitoringEntry.m_lstWatchedDataPoints.begin(); + TDataWatchList::Iterator itRefNode = paFBMonitoringEntry.m_lstWatchedDataPoints.end(); + + while(itRunner != paFBMonitoringEntry.m_lstWatchedDataPoints.end()){ + if(itRunner->mPortId == paPortId){ + if(itRefNode == paFBMonitoringEntry.m_lstWatchedDataPoints.end()){ + //we have the first entry in the list + paFBMonitoringEntry.m_lstWatchedDataPoints.pop_front(); + } + else{ + paFBMonitoringEntry.m_lstWatchedDataPoints.eraseAfter(itRefNode); + } + bRetVal = true; + break; + } + + itRefNode = itRunner; + ++itRunner; + } + + return bRetVal; +} + +void CMonitoringHandler::addEventWatch(SFBMonitoringEntry &paFBMonitoringEntry, + CStringDictionary::TStringId paPortId, SMonitorEvent &paEventData){ + for(TEventWatchList::Iterator itRunner = paFBMonitoringEntry.m_lstWatchedEventPoints.begin(); + itRunner != paFBMonitoringEntry.m_lstWatchedEventPoints.end(); ++itRunner){ + if(itRunner->m_unPortId == paPortId){ + //the event point is already in the watch list + return; + } + } + paFBMonitoringEntry.m_lstWatchedEventPoints.push_back(SEventWatchEntry(paPortId, paEventData)); +} + +bool CMonitoringHandler::removeEventWatch(SFBMonitoringEntry &paFBMonitoringEntry, + CStringDictionary::TStringId paPortId){ + bool bRetVal = false; + + TEventWatchList::Iterator itRunner = paFBMonitoringEntry.m_lstWatchedEventPoints.begin(); + TEventWatchList::Iterator itRefNode = paFBMonitoringEntry.m_lstWatchedEventPoints.end(); + + while(itRunner != paFBMonitoringEntry.m_lstWatchedEventPoints.end()){ + if(itRunner->m_unPortId == paPortId){ + if(itRefNode == paFBMonitoringEntry.m_lstWatchedEventPoints.end()){ + //we have the first entry in the list + paFBMonitoringEntry.m_lstWatchedEventPoints.pop_front(); + } + else{ + paFBMonitoringEntry.m_lstWatchedEventPoints.eraseAfter(itRefNode); + } + bRetVal = true; + break; + } + + itRefNode = itRunner; + ++itRunner; + } + + return bRetVal; +} + +void CMonitoringHandler::readResourceWatches(CIEC_STRING &paResponse){ + if(!mFBMonitoringList.isEmpty()){ + paResponse.append(""); + + { //begin critical region + CCriticalRegion criticalRegion(mResource.m_oResDataConSync); + + for(TFBMonitoringList::Iterator itRunner = mFBMonitoringList.begin(); + itRunner != mFBMonitoringList.end(); ++itRunner){ + paResponse.append("m_poFB); + paResponse.append("\">"); + + //add the data watches + for(TDataWatchList::Iterator itDataRunner = itRunner->m_lstWatchedDataPoints.begin(); + itDataRunner != itRunner->m_lstWatchedDataPoints.end(); ++itDataRunner){ + appendDataWatch(paResponse, *itDataRunner); + } + + //add the event watches + for(TEventWatchList::Iterator itEventRunner = itRunner->m_lstWatchedEventPoints.begin(); + itEventRunner != itRunner->m_lstWatchedEventPoints.end(); + ++itEventRunner){ + appendEventWatch(paResponse, *itEventRunner); + } + + paResponse.append(""); + } + } //end critical region + paResponse.append(""); + } +} + +void CMonitoringHandler::getResourceWatches(CIEC_STRING &paResponse, char paQualifier){ + if(!mFBMonitoringList.isEmpty()){ + paResponse.append(""); + + for(TFBMonitoringList::Iterator itRunner = mFBMonitoringList.begin(); + itRunner != mFBMonitoringList.end(); ++itRunner){ + paResponse.append("m_poFB); + paResponse.append("\">"); + + //FIXME implement the watches + + paResponse.append(""); + } + + paResponse.append(""); + } +} + +void CMonitoringHandler::appendDataWatch(CIEC_STRING &paResponse, + SDataWatchEntry &paDataWatchEntry){ + appendPortTag(paResponse, paDataWatchEntry.mPortId); + paResponse.append("(paDataWatchEntry.mDataValue).toUTF8(acDataValue, sizeof(acDataValue), false); + break; + default: + nConsumedBytes = paDataWatchEntry.mDataValue.toString(acDataValue, sizeof(acDataValue)); + break; + } + if(-1 != nConsumedBytes){ + acDataValue[nConsumedBytes] = '\0'; + } + + paResponse.append(acDataValue); + paResponse.append("\" forced=\""); + paResponse.append(((paDataWatchEntry.mDataValue.isForced()) ? "true" : "false")); + paResponse.append("\">"); + paResponse.append(""); + + paResponse.append(""); +} + +void CMonitoringHandler::appendPortTag(CIEC_STRING &paResponse, + CStringDictionary::TStringId paPortId){ + paResponse.append(""); +} + +void CMonitoringHandler::appendEventWatch(CIEC_STRING &paResponse, + SEventWatchEntry &paEventWatchEntry){ + appendPortTag(paResponse, paEventWatchEntry.m_unPortId); + + CIEC_UDINT udint; + CIEC_ULINT ulint; + + char acEventCount[10]; // the bigest number in an uint is 4294967296, TODO directly use pa_roResponse + char acTimeStamp[21]; // the bigest number in an ulint is 18446744073709551616, TODO directly use pa_roResponse + + for(TForteUInt16 i = 0; i <= paEventWatchEntry.m_roEventData.mBufPos; i++){ + SMonitorEvent::SMonitorEventData &monitorEventData(paEventWatchEntry.m_roEventData.mMonitorEventData[i]); + udint = monitorEventData.mEventCount; + ulint = ((((TForteUInt64) monitorEventData.mTimeStamp.m_nUpperValue) << 32) & 0xFFFFFFFF00000000ULL) + + (((TForteUInt64) monitorEventData.mTimeStamp.m_nLowerValue) & 0xFFFFFFFFULL); + + paResponse.append(""); + paResponse.append(""); + } + + paEventWatchEntry.m_roEventData.mBufPos = 0; + + paResponse.append(""); +} + +void CMonitoringHandler::appendFBName(CIEC_STRING &paResponse, CFunctionBlock *paFB){ + if(0 != paFB->getContainer()){ + appendFBName(paResponse, paFB->getContainer()); + paResponse.append("."); + } + paResponse.append(paFB->getInstanceName()); +} + diff --git a/src/core/monitoring.h b/src/core/monitoring.h new file mode 100644 index 000000000..e329e9756 --- /dev/null +++ b/src/core/monitoring.h @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef MONITORING_H_ +#define MONITORING_H_ + +#include "mgmcmdstruct.h" +#include "fortelist.h" +#include "event.h" +#include "conn.h" +#include "stringdict.h" +#include + +class CFunctionBlock; +class CResource; + +namespace forte { + namespace core { + + const TForteUInt32 cgMonitorBufferLength = 1; + + enum EBreakPointStatus{ + eActive = 0, // we are comparing in the main loop against this one therefore it gets zero to make it faster + eOnce, + eInactive + }; + + struct SMonitorEvent{ + TForteUInt16 mBufPos; + EBreakPointStatus mBreakpointSet; //!< eOnce if breakpoint is active and should continue once, eInactive - currently no breakpoint active, eActive - breakpoint currently active TODO change to enum + bool mBreakpointEnable; //!< breakpoint activated - a breackpoint is specified for this event + + struct SMonitorEventData{ + TForteUInt32 mEventCount; //!< Event count + SForteTime mTimeStamp; //!< Timestamp when the event occurred + + SMonitorEventData() : mEventCount(0) { + } + }; + + SMonitorEventData mMonitorEventData[cgMonitorBufferLength]; + + SMonitorEvent() : mBufPos(0), mBreakpointSet(eInactive), mBreakpointEnable(false){ + } + }; + + + /*!\brief class that handles all monitoring tasks + * + */ + class CMonitoringHandler{ + public: + CMonitoringHandler(CResource &paResource); + + EMGMResponse executeMonitoringCommand(SManagementCMD &paCommand); + + private: + struct SDataWatchEntry{ + SDataWatchEntry(CStringDictionary::TStringId paPortId, CIEC_ANY &paDataValue) : + mPortId(paPortId), mDataValue(paDataValue){ + } + + CStringDictionary::TStringId mPortId; + CIEC_ANY &mDataValue; + }; + + struct SEventWatchEntry{ + SEventWatchEntry(CStringDictionary::TStringId pa_unPortId, + SMonitorEvent &pa_roEventData) : + m_unPortId(pa_unPortId), m_roEventData(pa_roEventData){ + } + + CStringDictionary::TStringId m_unPortId; + SMonitorEvent &m_roEventData; + }; + + typedef CSinglyLinkedList TDataWatchList; + typedef CSinglyLinkedList TEventWatchList; + + struct SFBMonitoringEntry{ + CFunctionBlock *m_poFB; + TDataWatchList m_lstWatchedDataPoints; + TEventWatchList m_lstWatchedEventPoints; + }; + + typedef CSinglyLinkedList TFBMonitoringList; + + CFunctionBlock* getFB(forte::core::TNameIdentifier &paNameList); + + EMGMResponse addWatch(forte::core::TNameIdentifier &paNameList); + EMGMResponse removeWatch(forte::core::TNameIdentifier &paNameList); + EMGMResponse readWatches(CIEC_STRING &pa_roResponse); + EMGMResponse getWatches(CIEC_STRING &pa_roResponse, char pa_cQualifier); + EMGMResponse forceValue(forte::core::TNameIdentifier &paNameList, CIEC_STRING &paValue); + EMGMResponse clearForce(forte::core::TNameIdentifier &paNameList); + EMGMResponse triggerEvent(forte::core::TNameIdentifier &paNameList); + EMGMResponse resetEventCount(forte::core::TNameIdentifier &paNameList); + + SFBMonitoringEntry &findOrCreateFBMonitoringEntry(CFunctionBlock *pa_poFB); + void addDataWatch(SFBMonitoringEntry &pa_roFBMonitoringEntry, + CStringDictionary::TStringId pa_unPortId, CIEC_ANY &pa_poDataVal); + bool removeDataWatch(SFBMonitoringEntry &pa_roFBMonitoringEntry, + CStringDictionary::TStringId pa_unPortId); + void addEventWatch(SFBMonitoringEntry &pa_roFBMonitoringEntry, + CStringDictionary::TStringId pa_unPortId, SMonitorEvent &pa_rstEventData); + bool removeEventWatch(SFBMonitoringEntry &pa_roFBMonitoringEntry, + CStringDictionary::TStringId pa_unPortId); + void readResourceWatches(CIEC_STRING &pa_roResponse); + void getResourceWatches(CIEC_STRING &pa_roResponse, char pa_cQualifier); + + static void appendDataWatch(CIEC_STRING &pa_roResponse, + SDataWatchEntry &pa_roDataWatchEntry); + static void appendPortTag(CIEC_STRING &pa_roResponse, + CStringDictionary::TStringId pa_unPortId); + static void appendEventWatch(CIEC_STRING &pa_roResponse, + SEventWatchEntry &pa_roEventWatchEntry); + + static void appendFBName(CIEC_STRING &paResponse, CFunctionBlock *paFB); + + //!List storing all FBs which are currently monitored + TFBMonitoringList mFBMonitoringList; + + //!Event entry for triggering input events + SEventEntry mTriggerEvent; + + CResource &mResource; //!< The resource this monitoring handler manages + + //don't allow that CMonitoringHandler can be copy therefore making the copy constructor private and not implemented + CMonitoringHandler(const CMonitoringHandler&); + CMonitoringHandler& operator =(const CMonitoringHandler &); + }; + + } +} +#endif /* MONITORING_H_ */ diff --git a/src/core/resource.cpp b/src/core/resource.cpp new file mode 100644 index 000000000..a6f05ef90 --- /dev/null +++ b/src/core/resource.cpp @@ -0,0 +1,289 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Gerhard Ebenhofer, Thomas Strasser, + * Martin Melik Merkumians, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include +#include "resource.h" +#include "device.h" +#include "adapter.h" +#include "adapterconn.h" +#include "if2indco.h" +#include "utils/criticalregion.h" + +CResource::CResource(CResource* pa_poDevice, const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, + TForteByte *pa_acFBVarsData) : + CFunctionBlock(pa_poDevice, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData), + forte::core::CFBContainer(CStringDictionary::scm_nInvalidStringId, 0), // the fbcontainer of resources does not have a seperate name as it is stored in the resource + m_poResourceEventExecution(new CEventChainExecutionThread), + mResIf2InConnections(0) + #ifdef FORTE_SUPPORT_MONITORING + , mMonitoringHandler(*this) +#endif +{ + initializeResIf2InConnections(); +} + +CResource::CResource(const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, + TForteByte *pa_acFBVarsData) : + CFunctionBlock(0, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData), + forte::core::CFBContainer(CStringDictionary::scm_nInvalidStringId, 0), // the fbcontainer of resources does not have a seperate name as it is stored in the resource + m_poResourceEventExecution(0), + mResIf2InConnections(0) + #ifdef FORTE_SUPPORT_MONITORING + , mMonitoringHandler(*this) +#endif +{ + initializeResIf2InConnections(); +} + +CResource::~CResource(){ + delete m_poResourceEventExecution; + delete[] mResIf2InConnections; +} + + +EMGMResponse CResource::executeMGMCommand(forte::core::SManagementCMD &paCommand){ + EMGMResponse retVal = e_INVALID_DST; + + if(CStringDictionary::scm_nInvalidStringId == paCommand.mDestination){ + switch (paCommand.mCMD){ + case cg_nMGM_CMD_Create_FBInstance: { + forte::core::TNameIdentifier::CIterator itRunner(paCommand.mFirstParam.begin()); + retVal = createFB(itRunner, paCommand.mSecondParam.front(), this); + } + break; + case cg_nMGM_CMD_Delete_FBInstance: { + forte::core::TNameIdentifier::CIterator itRunner(paCommand.mFirstParam.begin()); + retVal = deleteFB(itRunner); + } + break; + case cg_nMGM_CMD_Create_Connection: + retVal = createConnection(paCommand.mFirstParam, paCommand.mSecondParam); + break; + case cg_nMGM_CMD_Delete_Connection: + retVal = deleteConnection(paCommand.mFirstParam, paCommand.mSecondParam); + break; + case cg_nMGM_CMD_Read: + retVal = readValue(paCommand.mFirstParam, paCommand.mAdditionalParams); + break; + case cg_nMGM_CMD_Write: + retVal = writeValue(paCommand.mFirstParam, paCommand.mAdditionalParams); + break; + case cg_nMGM_CMD_Start: + case cg_nMGM_CMD_Stop: + case cg_nMGM_CMD_Kill: + case cg_nMGM_CMD_Reset: + retVal = handleExecutionStateCmd(paCommand.mCMD, paCommand.mFirstParam); + break; + default: + #ifdef FORTE_SUPPORT_MONITORING + retVal = mMonitoringHandler.executeMonitoringCommand(paCommand); +#else + retVal = e_UNSUPPORTED_CMD; +#endif + break; + } + } + return retVal; +} + +EMGMResponse CResource::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse retVal = CFunctionBlock::changeFBExecutionState(pa_unCommand); + if(e_RDY == retVal){ + retVal = changeContainedFBsExecutionState(pa_unCommand); + if(e_RDY == retVal){ + if(cg_nMGM_CMD_Start == pa_unCommand){ + //on start sample inputs + if(0 != m_pstInterfaceSpec){ + for(int i = 0; i < m_pstInterfaceSpec->m_nNumDIs; ++i){ + if(0 != m_apoDIConns[i]){ + m_apoDIConns[i]->readData(getDI(i)); + } + } + } + } + if(0 != m_poResourceEventExecution){ + // if we have a m_poResourceEventExecution handle it + m_poResourceEventExecution->changeExecutionState(pa_unCommand); + } + } + } + return retVal; +} + +EMGMResponse CResource::handleExecutionStateCmd(EMGMCommandType paCMD, + forte::core::TNameIdentifier &paTarget){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + CFunctionBlock *fb = this; + + if(!paTarget.isEmpty()){ + forte::core::TNameIdentifier::CIterator itRunner(paTarget.begin()); + fb = getContainedFB(itRunner); + } + + if(0 != fb){ + retVal = fb->changeFBExecutionState(paCMD); + } + return retVal; +} + +EMGMResponse CResource::createConnection(forte::core::SManagementCMD &paCommand){ + return createConnection(paCommand.mFirstParam, paCommand.mSecondParam); +} + + +EMGMResponse CResource::createConnection(forte::core::TNameIdentifier &paSrcNameList, + forte::core::TNameIdentifier &paDstNameList){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + + CConnection *con = getConnection(paSrcNameList); + if(0 != con){ + CStringDictionary::TStringId portName = paDstNameList.back(); + paDstNameList.popBack(); + forte::core::TNameIdentifier::CIterator runner(paDstNameList.begin()); + CFunctionBlock *dstFB = getContainedFB(runner); + if((0 != dstFB) && (runner.isLastEntry())){ + retVal = con->connect(dstFB, portName); + } + } + + return retVal; +} + +EMGMResponse CResource::deleteConnection(forte::core::TNameIdentifier &paSrcNameList, + forte::core::TNameIdentifier &paDstNameList){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + + CConnection *con = getConnection(paSrcNameList); + if(0 != con){ + CStringDictionary::TStringId portName = paDstNameList.back(); + paSrcNameList.popBack(); + forte::core::TNameIdentifier::CIterator runner(paDstNameList.begin()); + CFunctionBlock *dstFB = getContainedFB(runner); + if((0 != dstFB) && (runner.isLastEntry())){ + retVal = con->disconnect(dstFB, portName); + } + } + + return retVal; +} + +EMGMResponse CResource::writeValue(forte::core::TNameIdentifier &paNameList, + const CIEC_STRING & paValue){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + + CIEC_ANY *var = getVariable(paNameList); + if(var != 0){ + if(paValue.length() > 0){ + if(paValue.length() == var->fromString(paValue.getValue())){ + //if we cannot parse the full value the value is not valid + retVal = e_RDY; + } + else{ + retVal = e_BAD_PARAMS; + } + } + else{ + retVal = e_BAD_PARAMS; // 0 is not supported in the fromString method + } + } + return retVal; +} + +EMGMResponse CResource::readValue(forte::core::TNameIdentifier &paNameList, CIEC_STRING & paValue){ + EMGMResponse retVal = e_NO_SUCH_OBJECT; + + CIEC_ANY *var = getVariable(paNameList); + if(0 != var){ + int nUsedChars = var->toString(paValue.getValue(), paValue.getCapacity()); + + if(-1 != nUsedChars){ + paValue.assign(paValue.getValue(), static_cast(nUsedChars)); + retVal = e_RDY; + } + else{ + retVal = e_INVALID_OBJECT; + } + } + return retVal; +} + +CIEC_ANY *CResource::getVariable(forte::core::TNameIdentifier &paNameList){ + CStringDictionary::TStringId portName = paNameList.back(); + paNameList.popBack(); + forte::core::TNameIdentifier::CIterator runner(paNameList.begin()); + + CFunctionBlock *fb = this; + if(paNameList.size() >= 1){ + //this is not an identifier for the resource interface + fb = getContainedFB(runner); // the last entry is the input name therefore reduce list here by one + } + + CIEC_ANY *var = 0; + if((0 != fb) && (runner.isLastEntry())){ + var = fb->getVar(&portName, 1); + } + return var; +} + +CConnection *CResource::getConnection(forte::core::TNameIdentifier &paSrcNameList){ + CConnection *con = 0; + if(1 == paSrcNameList.size()){ + con = getResIf2InConnection(paSrcNameList[0]); + } + else if(paSrcNameList.size() > 1){ + CStringDictionary::TStringId portName = paSrcNameList.back(); + paSrcNameList.popBack(); + forte::core::TNameIdentifier::CIterator runner(paSrcNameList.begin()); + + CFunctionBlock *srcFB = getContainedFB(runner); + if((0 != srcFB) && (runner.isLastEntry())){ + //only use the found result if we have really the last result in the list + con = srcFB->getEOConection(portName); + if(0 == con){ + //it is not an event connection try data connection next + con = srcFB->getDOConnection(portName); + if(0 == con){ + //it is not an data connection try data connection next + //TODO think if it would be better to move this to CFunctionBlock + CAdapter *adp = srcFB->getAdapter(portName); + if((0 != adp) && (adp->isPlug())){ + //only plugs hold the connection object + con = adp->getAdapterConnection(); + } + } + } + } + } + return con; +} + +CConnection *CResource::getResIf2InConnection(CStringDictionary::TStringId paResInput) const{ + CConnection *con = 0; + if(0 != m_pstInterfaceSpec){ + TPortId inPortId = getDIID(paResInput); + if(cg_unInvalidPortId != inPortId){ + con = mResIf2InConnections + inPortId; + } + } + return con; +} + +void CResource::initializeResIf2InConnections(){ + if(0 != m_pstInterfaceSpec){ + mResIf2InConnections = new CInterface2InternalDataConnection[m_pstInterfaceSpec->m_nNumDIs]; + for(TPortId i = 0; i < m_pstInterfaceSpec->m_nNumDIs; i++){ + (mResIf2InConnections + i)->setSource(this, i); + } + } +} diff --git a/src/core/resource.h b/src/core/resource.h new file mode 100644 index 000000000..68f2b1319 --- /dev/null +++ b/src/core/resource.h @@ -0,0 +1,169 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Thomas Strasser, Gerhard Ebenhofer, Ingo Hegny, + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _RESOURCE_H_ +#define _RESOURCE_H_ + +#include "ecet.h" +#include "funcbloc.h" +#include "fbcontainer.h" + +#ifdef FORTE_SUPPORT_MONITORING +#include +#endif + +class CDevice; + +/*! \ingroup CORE\brief Base class for all resources handling the reconfiguration management within this + * resource and the background execution of event chains. + * + * CResource is inherited from CFBContainer in order to make the implementation of getResource easier. Furthermore + * also the forwarding of management commands is less effort. + * TODO think if CFBContainer inheritance should be public or private + */ +class CResource : public CFunctionBlock, public forte::core::CFBContainer{ + + public: + CSyncObject m_oResDataConSync; + /*! \brief The main constructor for a resource. + * + * The resource can only be generated with a given device the resource is contained. A resource can not exist outside of an device. + * \param pa_poDevice the device the resource is contained in + * \param pa_pstInterfaceSpec interface-specification of resource + * \param pa_nInstanceNameId StringId of instance-name + * \param pa_roObjectHandler reference to object handler + * \param pa_acFBData Byte-array for resource-specific data + */ + CResource(CResource* pa_poDevice, const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, + TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData); + + virtual ~CResource(); + + /*!\brief Execute the given management command + * + * Evaluates the m_sDestination parameter of the command if empty the resource tries + * to execute the management command if not it tries to apply the mgm command to a + * contained FB if possible. + * \param paCommand internal representation of the management command + * \return response of the MGMCommand execution as defined in IEC 61499 + */ + virtual EMGMResponse executeMGMCommand(forte::core::SManagementCMD &paCommand); + + /*! \brief Get the device the resource is contained in + */ + CDevice &getDevice(void){ + return (CDevice &) getResource(); + } + ; + + CEventChainExecutionThread *getResourceEventExecution(void){ + return m_poResourceEventExecution; + } + ; + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); + +#ifdef FORTE_SUPPORT_MONITORING + forte::core::CMonitoringHandler &getMonitoringHandler(){ + return mMonitoringHandler; + } +#endif + + protected: + CResource(const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, + TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData); + + virtual void executeEvent(int){ + } + + /*!Wrapper for simplifying connection creation in resources + * + */ + EMGMResponse createConnection(forte::core::SManagementCMD &paCommand); + private: + /*!\brief Create a new connection between source and destination + * + * This function is protected so that devices and resource can utilize to setup their connections. + * @param paSrcNameList identifier name list for the source of the connection + * @param padstNameList identifier name list for the destination of the connection + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse createConnection(forte::core::TNameIdentifier &paSrcNameList, + forte::core::TNameIdentifier &paDstNameList); + + /*! Handle and perform the actions required for an execution state change + * command (i.e., START, STOP, KILL, RESET) + * + * @param paCMD the ecuctoin state change command to be performed + * @param paTarget identifier which is the target for this request if empty the target is the resource + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse handleExecutionStateCmd(EMGMCommandType paCMD, + forte::core::TNameIdentifier &paTarget); + + /*!\brief Create a new connection between source and destination + * + * @param paSrcNameList identifier name list for the source of the connection + * @param padstNameList identifier name list for the destination of the connection + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse deleteConnection(forte::core::TNameIdentifier &paSrcNameList, + forte::core::TNameIdentifier &paDstNameList); + + /*!\brief Write a parameter value to a given FB-input + * + * @param paNameList the identifier name list of the parameter to be written + * @param paValue the value to be writen + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse writeValue(forte::core::TNameIdentifier &paNameList, const CIEC_STRING & paValue); + + /*!\brief Read a parameter value from a given FB + * + * @param paNameList the identifier name list of the parameter to be read + * @param paValue the destination for the value to be read + * @return response of the command execution as defined in IEC 61499 + */ + EMGMResponse readValue(forte::core::TNameIdentifier &paNameList, CIEC_STRING & paValue); + + /*!\brief get the variable with the given name identifier + * + * @param paNameList the identifier name list of the variable to be retrieved + * @return the pointer to the variable or 0 if the variable with the given identifier name list does not exist + */ + CIEC_ANY *getVariable(forte::core::TNameIdentifier &paNameList); + + /*!\brief get the connection object for the given source identifier + * + * @param paSrcNameList array of the name hierarchy the requested connection source + * @return pointer to the requested connection, returns 0 if there is no such source + */ + CConnection *getConnection(forte::core::TNameIdentifier &paSrcNameList); + + CConnection *getResIf2InConnection(CStringDictionary::TStringId paResInput) const; + + void initializeResIf2InConnections(); + + /*!\brief The event chain execution of background (low priority) event chains started within this resource + */ + CEventChainExecutionThread *m_poResourceEventExecution; + + CInterface2InternalDataConnection *mResIf2InConnections; //!< List of all connections from the res interface to internal FBs + +#ifdef FORTE_SUPPORT_MONITORING + forte::core::CMonitoringHandler mMonitoringHandler; +#endif //#ifdef FORTE_SUPPORT_MONITORING + +}; + +#endif /*RESOURCE_H_*/ diff --git a/src/core/stringdict.cpp b/src/core/stringdict.cpp new file mode 100644 index 000000000..761fef94a --- /dev/null +++ b/src/core/stringdict.cpp @@ -0,0 +1,218 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 nxtControl GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl, Martin Melik Merkumians + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "stringdict.h" +#include +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "stringdict_gen.cpp" +#endif +#include +#include +#include + +DEFINE_SINGLETON(CStringDictionary) + +// ctor +CStringDictionary::CStringDictionary(){ +#ifdef FORTE_STRING_DICT_FIXED_MEMORY + m_paStringBufAddr = scm_acConstStringBuf; + m_pnStringIdBufAddr = scm_aunIdList; + + m_nStringBufSize = cg_unStringDictInitialStringBufSize; + m_nMaxNrOfStrings = cg_unStringDictInitialMaxNrOfStrings; + + m_nNrOfStrings = cg_nNumOfConstStrings; + m_nNextString = g_nStringIdNextFreeId; +#else + unsigned int nStringBufSize = cg_unStringDictInitialStringBufSize; + if(nStringBufSize < g_nStringIdNextFreeId){ + nStringBufSize = (g_nStringIdNextFreeId * 3) >> 1; + } + + unsigned int nMaxNrOfStrings = cg_unStringDictInitialMaxNrOfStrings; + if(nMaxNrOfStrings < cg_nNumOfConstStrings){ + nMaxNrOfStrings = (cg_nNumOfConstStrings * 3) >> 1; + } + + m_paStringBufAddr = (char *) forte_malloc(nStringBufSize * sizeof(char)); + if(0 != m_paStringBufAddr){ + m_pnStringIdBufAddr = (TStringId *) forte_malloc(nMaxNrOfStrings * sizeof(TStringId)); + if(0 != m_pnStringIdBufAddr){ + memcpy(m_paStringBufAddr, scm_acConstStringBuf, g_nStringIdNextFreeId); + memcpy(m_pnStringIdBufAddr, scm_aunIdList, (cg_nNumOfConstStrings * sizeof(TStringId))); + + m_nStringBufSize = nStringBufSize; + m_nMaxNrOfStrings = nMaxNrOfStrings; + + m_nNrOfStrings = cg_nNumOfConstStrings; + m_nNextString = g_nStringIdNextFreeId; + } + else{ + forte_free(m_paStringBufAddr); + m_paStringBufAddr = 0; + } + } +#endif +} + +CStringDictionary::~CStringDictionary(){ + clear(); +} + +// clear +void CStringDictionary::clear(){ +#ifndef FORTE_STRING_DICT_FIXED_MEMORY + forte_free(m_paStringBufAddr); + forte_free(m_pnStringIdBufAddr); +#endif + m_pnStringIdBufAddr = 0; + m_paStringBufAddr = 0; + m_nStringBufSize = 0; + m_nMaxNrOfStrings = 0; + m_nNrOfStrings = 0; + m_nNextString = 0; +} + +// get a string (0 if not found) +const char *CStringDictionary::get(TStringId pa_nId){ + if(pa_nId >= m_nNextString) + return 0; + + const char *adr = getStringAddress(pa_nId); + if(pa_nId > 0 && adr[-1] != '\0') + return 0; + + return adr; +} + +// insert a string and return a string id (InvalidTStringId for no memory or other error) +CStringDictionary::TStringId CStringDictionary::insert(const char *pa_sStr){ + TStringId nRetVal = scm_nInvalidStringId; + + if(0 != pa_sStr){ + if('\0' != *pa_sStr){ + unsigned int idx; + nRetVal = findEntry(pa_sStr, idx); + if(scm_nInvalidStringId == nRetVal){ + TStringId len = static_cast(strlen(pa_sStr)); + TStringId nRequiredSize = m_nNextString + len + 1; + + if(m_nNrOfStrings >= m_nMaxNrOfStrings){ +#ifdef FORTE_STRING_DICT_FIXED_MEMORY + return scm_nInvalidStringId; +#else + //grow exponentially by 1.5 according to Herb Sutter best strategy + if(!reallocateStringIdBuf((m_nMaxNrOfStrings * 3) >> 1)){ + return scm_nInvalidStringId; + } +#endif + + } + if(nRequiredSize > m_nStringBufSize){ +#ifdef FORTE_STRING_DICT_FIXED_MEMORY + return scm_nInvalidStringId; +#else + //grow exponentially by 1.5 according to Herb Sutter best strategy + if(!reallocateStringBuf((nRequiredSize * 3) >> 1)){ + return scm_nInvalidStringId; + } +#endif + } + nRetVal = insertAt(pa_sStr, idx, len); + } + } + else{ + //printf("string war länge null\n"); + } + } + return nRetVal; +} + +// Find an exact match or place to be the new index +CStringDictionary::TStringId CStringDictionary::findEntry(const char *pa_sStr, unsigned int &pa_rnIdx) const{ + pa_rnIdx = 0; + if(m_nNrOfStrings == 0) + return scm_nInvalidStringId; + + int r = 0; + + unsigned int low = 0, high = m_nNrOfStrings; + + while(low < high){ + pa_rnIdx = (low + high) / 2; + + r = strcmp(pa_sStr, getStringAddress(m_pnStringIdBufAddr[pa_rnIdx])); + + if(!r){ + return m_pnStringIdBufAddr[pa_rnIdx]; + } + + if(r > 0) + low = pa_rnIdx + 1; + else + high = pa_rnIdx; + } + + if(r > 0) + pa_rnIdx++; + + return scm_nInvalidStringId; +} + +// Reallocate the Id buffer +bool CStringDictionary::reallocateStringIdBuf(unsigned int pa_nNewMaxNrOfStrings){ + bool bRetval = true; + if(pa_nNewMaxNrOfStrings > m_nMaxNrOfStrings){ + TStringId *adr = (TStringId *) forte_realloc(m_pnStringIdBufAddr, pa_nNewMaxNrOfStrings * sizeof(TStringId)); + if(0 != adr){ + m_pnStringIdBufAddr = adr; + m_nMaxNrOfStrings = pa_nNewMaxNrOfStrings; + } + else{ + bRetval = false; + } + } + return bRetval; +} + +// Reallocate the string buffer +bool CStringDictionary::reallocateStringBuf(TForteUInt32 pa_nNewBufSize){ + bool bRetval = true; + if(pa_nNewBufSize > m_nStringBufSize){ + char *adr = (char *) forte_realloc(m_paStringBufAddr, pa_nNewBufSize * sizeof(char)); + if(0 != adr){ + m_paStringBufAddr = adr; + m_nStringBufSize = pa_nNewBufSize; + } + else{ + bRetval = false; + } + } + return bRetval; +} + +// Insert the string at the specified position +CStringDictionary::TStringId CStringDictionary::insertAt(const char *pa_sStr, unsigned int pa_nIdx, unsigned int pa_nLen){ + TStringId id = m_nNextString; + char *p = getStringAddress(m_nNextString); + + memcpy(p, pa_sStr, pa_nLen); + p[pa_nLen] = '\0'; + m_nNextString += pa_nLen + 1; + + if(pa_nIdx < m_nNrOfStrings) + memmove(m_pnStringIdBufAddr + pa_nIdx + 1, m_pnStringIdBufAddr + pa_nIdx, (m_nNrOfStrings - pa_nIdx) * sizeof(TStringId)); + + m_pnStringIdBufAddr[pa_nIdx] = id; + m_nNrOfStrings++; + + return id; +} diff --git a/src/core/stringdict.h b/src/core/stringdict.h new file mode 100644 index 000000000..11f27f029 --- /dev/null +++ b/src/core/stringdict.h @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2008 - 2015 nxtControl GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Alois Zoitl + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _CStringDictionary_H_ +#define _CStringDictionary_H_ + +#include +#include "singlet.h" +#include + +/**\ingroup CORE\brief Manages a dictionary of strings that can be referenced by ids + * + * Manages a dictionary of strings that can be referenced by ids + */ +class CStringDictionary{ + DECLARE_SINGLETON(CStringDictionary) +public: + typedef TForteUInt32 TStringId; + + //!\brief Invalid string id + static const TStringId scm_nInvalidStringId = 0xffffffff; + + + /*!\brief Get a string from the dictionary + * + * \param pa_nId String id + * \return true the found string or 0 if not found + */ + const char *get(TStringId pa_nId); + + /*!\brief Insert a string into the dictionary + * + * \param pa_sStr String to be inserted + * \return id of the inserted string (or the existing one if the dictionary already has it) + */ + TStringId insert(const char *pa_sStr); + + /*!\brief Retrieve the Id of a given string if it is already in the dictionary + * + * \param pa_sStr String to be searched for + * \return id of the string (or scm_nInvalidStringId if it is not in the dictionary) + */ + TStringId getId(const char *pa_sStr) const{ + unsigned int nIdx; + return findEntry(pa_sStr, nIdx); + } +private: + //!\brief Remove all dictionary entries + void clear(); + + // Find an exact match or place to be the new index + TStringId findEntry(const char *pa_sStr, unsigned int &pa_rnIdx) const; + + // Reallocate the buffer + bool reallocateStringIdBuf(unsigned int pa_nNewMaxNrOfStrings); + bool reallocateStringBuf(TForteUInt32 pa_nNewBufSize); + + // Insert the string at the specified position + TStringId insertAt(const char *pa_sStr, unsigned int pa_nIdx, unsigned int pa_nLen); + + // Get an address + const char *getStringAddress(TStringId pa_nId) const { + return m_paStringBufAddr + pa_nId; + }; + + char *getStringAddress(TStringId pa_nId) { + return m_paStringBufAddr + pa_nId; + }; + + //!Buffer for the String Ids. The Ids are sorted according to their values they are pointing at + TStringId *m_pnStringIdBufAddr; + + //! Buffer for the strings + char *m_paStringBufAddr; + + // Size of the allocated space + TForteUInt32 m_nStringBufSize; + + // Maximum number of strings we can hold (size of the StringIdBufer) + unsigned int m_nMaxNrOfStrings; + + // Number of strings we are actually holding + unsigned int m_nNrOfStrings; + + // Next string gets written here + TStringId m_nNextString; + +#ifdef FORTE_STRING_DICT_FIXED_MEMORY + static TStringId scm_aunIdList[cg_unStringDictInitialMaxNrOfStrings]; + static char scm_acConstStringBuf[cg_unStringDictInitialStringBufSize]; +#else + static const TStringId scm_aunIdList[]; + static const char scm_acConstStringBuf[]; +#endif +}; + + +#endif // _CStringDictionary_H_ + diff --git a/src/core/typelib.cpp b/src/core/typelib.cpp new file mode 100644 index 000000000..ebbd7aa29 --- /dev/null +++ b/src/core/typelib.cpp @@ -0,0 +1,228 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Smodic Rene, Gerhard Ebenhofer, + * Ingo Hegny, Monika Wenger + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#include "./datatypes/forte_any.h" +#include "typelib.h" +#include "eventconn.h" +#include "dataconn.h" +#include "adapterconn.h" +#include "resource.h" +#include "if2indco.h" +#include + +#ifndef FORTE_CLASS_0 +CTypeLib::CTypeEntry::CTypeEntry(CStringDictionary::TStringId pa_nTypeNameId) : + m_nTypeNameId(pa_nTypeNameId), + m_poNext(0){ + } + +CTypeLib::CTypeEntry::~CTypeEntry(void){ + +} + +CTypeLib::CFBTypeEntry::CFBTypeEntry(CStringDictionary::TStringId pa_nTypeNameId, TFunctionBlockCreateFunc pa_pfuncCreateFB): + CTypeEntry(pa_nTypeNameId), + m_pfuncFBCreationFunc(pa_pfuncCreateFB){ + CTypeLib::addFBType(this); + +} + + +CTypeLib::CFBTypeEntry::~CFBTypeEntry(void){ + +} + +CTypeLib::CAdapterTypeEntry::CAdapterTypeEntry(CStringDictionary::TStringId pa_nTypeNameId, TAdapterCreateFunc pa_pfuncCreateAdapter): + CTypeEntry(pa_nTypeNameId), + m_pfuncAdapterCreationFunc(pa_pfuncCreateAdapter){ +CTypeLib::addAdapterType(this); + +} + +CTypeLib::CAdapterTypeEntry::~CAdapterTypeEntry(void){ + +} + +CTypeLib::CDataTypeEntry::CDataTypeEntry(CStringDictionary::TStringId pa_nTypeNameId, TDataTypeCreateFunc pa_pfuncDTCreateFunc) : + CTypeEntry(pa_nTypeNameId){ + m_pfuncDTCreateFunc = pa_pfuncDTCreateFunc; + CTypeLib::addDataType(this); +} + +CTypeLib::CDataTypeEntry::~CDataTypeEntry(void){ + +} + + +EMGMResponse CTypeLib::m_eLastErrorMSG = e_RDY; + +CTypeLib::CFBTypeEntry *CTypeLib::m_poFBLibStart = 0; +CTypeLib::CFBTypeEntry *CTypeLib::m_poFBLibEnd = 0; + +CTypeLib::CAdapterTypeEntry *CTypeLib::m_poAdapterLibStart = 0; +CTypeLib::CAdapterTypeEntry *CTypeLib::m_poAdapterLibEnd = 0; + +CTypeLib::CDataTypeEntry *CTypeLib::m_poDTLibStart = 0; +CTypeLib::CDataTypeEntry *CTypeLib::m_poDTLibEnd = 0; + +//CTypeLib::~CTypeLib() { +// //TODO free memory of fblibrary (maybe not necessary as typelib is deleted at the end of the program) +// //TODO free memory of RESlibrary (maybe not necessary as typelib is deleted at the end of the program) +//} + +CTypeLib::CTypeEntry *CTypeLib::findType(CStringDictionary::TStringId pa_nTypeId, CTypeLib::CTypeEntry *pa_poListStart) { + CTypeEntry *retval = 0; + for (CTypeEntry *poRunner = pa_poListStart; poRunner != 0; poRunner + = poRunner->m_poNext){ + if (pa_nTypeId == poRunner->getTypeNameId()) { + retval = poRunner; + break; + } + } + return retval; +} + +CAdapter *CTypeLib::createAdapter(CStringDictionary::TStringId pa_nInstanceNameId, CStringDictionary::TStringId pa_nAdapterTypeId, CResource *pa_poRes, bool pa_bIsPlug) { + CAdapter *poNewAdapter = 0; + CTypeEntry *poToCreate = findType(pa_nAdapterTypeId, m_poAdapterLibStart); + if (0 != poToCreate) { + poNewAdapter = + ((CAdapterTypeEntry *)poToCreate)->createAdapterInstance(pa_nInstanceNameId,pa_poRes, pa_bIsPlug); + if (0 == poNewAdapter) + m_eLastErrorMSG = e_OVERFLOW; + } //no generic adapters supported + + return poNewAdapter; + +} + +CFunctionBlock *CTypeLib::createFB(CStringDictionary::TStringId pa_nInstanceNameId, CStringDictionary::TStringId pa_nFBTypeId, CResource *pa_poRes) { + CFunctionBlock *poNewFB = 0; + CTypeEntry *poToCreate = findType(pa_nFBTypeId, m_poFBLibStart); + //TODO: Avoid that the user can create generic blocks. + if (0 != poToCreate) { + poNewFB + = ((CFBTypeEntry *)poToCreate)->createFBInstance(pa_nInstanceNameId, pa_poRes); + if (0 == poNewFB) // we could not create the requested object + m_eLastErrorMSG = e_OVERFLOW; + } else { //check for parameterizable FBs (e.g. SERVER) + TIdentifier acGenFBName = { "GEN_" }; + const char *acTypeBuf = CStringDictionary::getInstance().get(pa_nFBTypeId); + const char *pcUnderScore = getFirstNonTypeNameUnderscorePos(acTypeBuf); + + if (0 != pcUnderScore) { // We found no underscore in the type name therefore it can not be a generic type + ptrdiff_t nCopyLen = pcUnderScore - acTypeBuf; + if (nCopyLen > cg_nIdentifierLength - 4) + nCopyLen = cg_nIdentifierLength - 4; + memcpy(&(acGenFBName[4]), acTypeBuf, nCopyLen); + acGenFBName[cg_nIdentifierLength] = '\0'; + poToCreate = findType(CStringDictionary::getInstance().getId(acGenFBName), m_poFBLibStart); + if (0 != poToCreate) { + poNewFB = ((CFBTypeEntry *)poToCreate)->createFBInstance(pa_nInstanceNameId, pa_poRes); + if (0 == poNewFB){ // we could not create the requested object + m_eLastErrorMSG = e_OVERFLOW; + } + else { // we got a configurable block + if (!poNewFB->configureFB(acTypeBuf)) { + //TODO: Handle an error, if the FB was not configured correctly!!!! + } + } + } + else{ + m_eLastErrorMSG = e_UNSUPPORTED_TYPE; + } + } + else{ + m_eLastErrorMSG = e_UNSUPPORTED_TYPE; + } + } + + if(0 != poNewFB){ + // perform reset to move it into idle state and set the initial values + poNewFB->changeFBExecutionState(cg_nMGM_CMD_Reset); + } + + return poNewFB; +} + +bool CTypeLib::deleteFB(CFunctionBlock *pa_poFBToDelete) { + delete pa_poFBToDelete; + return true; +} + +CIEC_ANY *CTypeLib::createDataTypeInstance(CStringDictionary::TStringId pa_nDTNameId, TForteByte *pa_acDataBuf) { + CIEC_ANY *poNewDT = 0; + CTypeEntry *poToCreate = findType(pa_nDTNameId, m_poDTLibStart); + if (0 != poToCreate) { + poNewDT = ((CDataTypeEntry *)poToCreate)->createDataTypeInstance(pa_acDataBuf); + if (0 == poNewDT) // we could not create the requested object + m_eLastErrorMSG = e_OVERFLOW; + } else + m_eLastErrorMSG = e_UNSUPPORTED_TYPE; + + return poNewDT; +} + +void CTypeLib::addFBType(CFBTypeEntry *pa_poFBTypeEntry) { + if (0 == findType(pa_poFBTypeEntry->getTypeNameId(), m_poFBLibStart)) { + if (m_poFBLibStart == 0) + m_poFBLibStart = pa_poFBTypeEntry; + else + m_poFBLibEnd->m_poNext = pa_poFBTypeEntry; + m_poFBLibEnd = pa_poFBTypeEntry; + } +} + +void CTypeLib::addAdapterType(CAdapterTypeEntry *pa_poAdapterTypeEntry) { + if (0 == findType(pa_poAdapterTypeEntry->getTypeNameId(), m_poAdapterLibStart)) { + if (m_poAdapterLibStart == 0) + m_poAdapterLibStart = pa_poAdapterTypeEntry; + else + m_poAdapterLibEnd->m_poNext = pa_poAdapterTypeEntry; + m_poAdapterLibEnd = pa_poAdapterTypeEntry; + } +} + + +void CTypeLib::addDataType(CDataTypeEntry *pa_poDTEntry) { + if (0 == findType(pa_poDTEntry->getTypeNameId(), m_poDTLibStart)) { + if (m_poDTLibStart == 0) + m_poDTLibStart = pa_poDTEntry; + else + m_poDTLibEnd->m_poNext = pa_poDTEntry; + m_poDTLibEnd = pa_poDTEntry; + } +} + + +const char *CTypeLib::getFirstNonTypeNameUnderscorePos(const char *pa_acTypeName){ + const char* acRetVal = pa_acTypeName; + + do{ + acRetVal = strchr(acRetVal, '_'); + if(0 != acRetVal){ + if(forte::core::util::isDigit(*(acRetVal + 1))){ + //only when the element after the underscore is a digit it is a correct type name + break; + } + acRetVal++; + } + } while(0 != acRetVal); + + return acRetVal; +} + + + +#endif + + diff --git a/src/core/typelib.h b/src/core/typelib.h new file mode 100644 index 000000000..0f5402efe --- /dev/null +++ b/src/core/typelib.h @@ -0,0 +1,268 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gunnar Grabmair, Rene Smodic, Gerhard Ebenhofer, + * Martin Melik Merkumians, Ingo Hegny, Micheal Hofmann + * - initial implementation and rework communication infrastructure + *******************************************************************************/ +#ifndef _TYPELIB_H_ +#define _TYPELIB_H_ + +#include +#include "mgmcmd.h" +#include +#include "./utils/staticassert.h" + +//forward declaration of a few classes to reduce include file dependencies +class CDevice; +class CFunctionBlock; +class CResource; +class CConnection; +class CEventConnection; +class CDataConnection; +class CAdapterConnection; +class CInterface2InternalDataConnection; +class CIEC_ANY; +class C61499Class0ObjectHandler; +class CAdapter; + +//!\ingroup CORE Type for a function pointer which allows to create a functionblock instance + typedef CFunctionBlock *(*TFunctionBlockCreateFunc)(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + +//!\ingroup CORE Type for a function pointer which allows to create an adapter instance + typedef CAdapter *(*TAdapterCreateFunc)(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes, bool pa_bIsPlug); + + +//!\ingroup CORE Type for a function pointer which allows to create a data type instance + typedef CIEC_ANY *(*TDataTypeCreateFunc)(TForteByte *pa_acDataBuf); + + #ifdef FORTE_STATIC_LIB + #define FORTE_DUMMY_INIT_DEF(fbclass) int fbclass::dummyInit() {return 0; } + #define FORTE_DUMMY_INIT_DEC static int dummyInit(); +#else + #define FORTE_DUMMY_INIT_DEF(fbclass) + #define FORTE_DUMMY_INIT_DEC +#endif + + +//!\ingroup CORE This define is used to create the definition necessary for generic FirmwareFunction blocks in order to get them automatically added to the FirmwareType list. +#define DECLARE_GENERIC_FIRMWARE_FB(fbclass) \ + private: \ + const static CTypeLib::CFBTypeEntry csm_oFirmwareFBEntry_##fbclass; \ + public: \ + static CFunctionBlock *createFB(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes){ \ + return new fbclass( pa_nInstanceNameId, pa_poSrcRes);\ + }; \ + FORTE_DUMMY_INIT_DEC \ + private: + + +//!\ingroup CORE This define is used to create the definition necessary for FirmwareFunction blocks in order to get them automatically added to the FirmwareType list. +#define DECLARE_FIRMWARE_FB(fbclass) \ + DECLARE_GENERIC_FIRMWARE_FB(fbclass) \ + public: \ + virtual CStringDictionary::TStringId getFBTypeId(void) const;\ + private: + + +#define DEFINE_GENERIC_FIRMWARE_FB(fbclass, fbTypeNameId)\ + extern const CStringDictionary::TStringId g_nStringId##fbclass; \ + const CTypeLib::CFBTypeEntry fbclass::csm_oFirmwareFBEntry_##fbclass((fbTypeNameId), fbclass::createFB); \ + FORTE_DUMMY_INIT_DEF(fbclass) + +/*!\ingroup CORE This define is used to create the implementation for the above definition. The second parameter is needed for the + * prebuild script that generates the constant string list. + */ +#define DEFINE_FIRMWARE_FB(fbclass, fbTypeNameId) \ + DEFINE_GENERIC_FIRMWARE_FB(fbclass, fbTypeNameId) \ + CStringDictionary::TStringId fbclass::getFBTypeId(void) const {return (fbTypeNameId); } + +//!\ingroup CORE This define is used to create the definition necessary for Adapter types. +#define DECLARE_ADAPTER_TYPE(adapterclass) \ + private: \ + const static CTypeLib::CAdapterTypeEntry csm_oAdapterTypeEntry_##adapterclass; \ + public: \ + static CAdapter *createAdapter(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes, bool pa_bIsPlug){\ + return new adapterclass(pa_nInstanceNameId, pa_poSrcRes, pa_bIsPlug);\ + }; \ + virtual CStringDictionary::TStringId getFBTypeId(void) const {return (csm_oAdapterTypeEntry_##adapterclass.getTypeNameId()); };\ + private: + + /* static CFunctionBlock *createFB(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes){ \*/ + +//!\ingroup CORE This define is used to create the implementation for the above definition. +#define DEFINE_ADAPTER_TYPE(adapterclass, adapterTypeNameId)\ + const CTypeLib::CAdapterTypeEntry adapterclass::csm_oAdapterTypeEntry_##adapterclass((adapterTypeNameId), adapterclass::createAdapter); + +//!\ingroup CORE This define is used to create the definition necessary for Firmware datatype in order to get them automatically added to the FirmwareType list. +#define DECLARE_FIRMWARE_DATATYPE(datatypename) \ + public: \ + static CIEC_ANY *createDataType(TForteByte *pa_acDataBuf){ \ + return (0 != pa_acDataBuf) ? new(pa_acDataBuf)CIEC_##datatypename() : new CIEC_##datatypename;\ + }; \ + const static CTypeLib::CDataTypeEntry csm_oFirmwareDataTypeEntry_##datatypename; \ + virtual CIEC_ANY* clone(TForteByte *pa_acDataBuf) const { \ + FORTE_STATIC_ASSERT((sizeof(CIEC_ANY) == sizeof(CIEC_##datatypename)), DataTypeNotTheSameSizeAsANY); \ + return (0 != pa_acDataBuf) ? new(pa_acDataBuf)CIEC_##datatypename(*this) : new CIEC_##datatypename(*this); } \ + FORTE_DUMMY_INIT_DEC \ + private: + +//!\ingroup CORE This define is used to create the implementation for the above definition. +#define DEFINE_FIRMWARE_DATATYPE(datatypename, datatypenameid)\ + extern const CStringDictionary::TStringId g_nStringId##datatypename; \ + const CTypeLib::CDataTypeEntry CIEC_##datatypename::csm_oFirmwareDataTypeEntry_##datatypename((datatypenameid), CIEC_##datatypename::createDataType);\ + FORTE_DUMMY_INIT_DEF(CIEC_##datatypename) + + +/*!\ingroup CORE \brief Class for storing the functionblock libraries. + */ +class CTypeLib{ +// public: +// static CTypeLib &getInstance(void); +// private: +// CTypeLib(); +// CTypeLib(const CTypeLib&); +// CTypeLib& operator = (const CTypeLib &); + +public: +//! The base class for all type entries in the type lib. + class CTypeEntry{ + private: + CStringDictionary::TStringId m_nTypeNameId; + public: + CTypeEntry *m_poNext; //!< a pointer to the next element in the list. Will be used to build single linked list of type entries. + + CTypeEntry(CStringDictionary::TStringId pa_nTypeNameId); + ~CTypeEntry(void); + + CStringDictionary::TStringId getTypeNameId(void) const { return m_nTypeNameId; }; + + }; + +//! The base class for all function block types entries in the type lib. + class CFBTypeEntry : public CTypeEntry{ + public: + CFBTypeEntry(CStringDictionary::TStringId pa_nTypeNameId, TFunctionBlockCreateFunc pa_pfuncCreateFB); + ~CFBTypeEntry(void); + CFunctionBlock *createFBInstance(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes){ + return m_pfuncFBCreationFunc( pa_nInstanceNameId, pa_poSrcRes); + } + private: + TFunctionBlockCreateFunc m_pfuncFBCreationFunc; + }; + +/*!\brief Class for adapter type entries in the type lib. + */ + class CAdapterTypeEntry : public CTypeEntry{ + public: + CAdapterTypeEntry(CStringDictionary::TStringId pa_nTypeNameId, TAdapterCreateFunc pa_pfuncCreateAdapter); + ~CAdapterTypeEntry(void); + CAdapter *createAdapterInstance(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes, bool pa_bIsPlug){ + return m_pfuncAdapterCreationFunc( pa_nInstanceNameId, pa_poSrcRes, pa_bIsPlug); + } + private: + TAdapterCreateFunc m_pfuncAdapterCreationFunc; + }; + +//! The base class for all data type entries in the type lib. + class CDataTypeEntry : public CTypeEntry{ + public: + CDataTypeEntry(CStringDictionary::TStringId pa_nTypeNameId, TDataTypeCreateFunc pa_pfuncDTCreateFunc); + ~CDataTypeEntry(void); + CIEC_ANY *createDataTypeInstance(TForteByte *pa_acDataBuf){ + return m_pfuncDTCreateFunc(pa_acDataBuf); + }; + protected: + TDataTypeCreateFunc m_pfuncDTCreateFunc; + + }; + +public: + //~CTypeLib(); +/*!\brief Create a new FB instance of given type and given instance name. + * + * \param pa_nInstanceNameId StringId of instance name as this information can be stored within the resource + * \param pa_nFBTypeId Type of the FB to create. + * \param pa_poRes Resource the FB is contained in. + * \return On success a pointer to the new FB is returned, else the return value is 0 use getLastError for getting more information on the problem. + * possible error codes are: + * - e_UNSUPPORTED_TYPE The requested FB type is not known to the typelib + * - e_INVALID_OPERATION The requested FB can not be created (e.g. out of memory) + */ + static CFunctionBlock *createFB(CStringDictionary::TStringId pa_nInstanceNameId, CStringDictionary::TStringId pa_nFBTypeId, CResource *pa_poRes); + + +/*\brief Delete the given FB + */ + static bool deleteFB(CFunctionBlock *pa_poFBToDelete); + + static CAdapter *createAdapter(CStringDictionary::TStringId pa_nInstanceNameId, CStringDictionary::TStringId pa_nFBTypeId, CResource *pa_poRes, bool pa_bIsPlug); + + /*!\brief Create an instance of an data type. + * + * @param pa_nDTNameId string id of the datatype to create + * @param pa_acDataBuf buffer that the datatype should use. Has to be at least the size of CIEC_ANY + * @return pointer to the create data type. + */ + static CIEC_ANY *createDataTypeInstance(CStringDictionary::TStringId pa_nDTNameId, TForteByte *pa_acDataBuf); + + +/*!\brief Return a description of the last error that occured within the CTypeLib. + * + * e.g. Out of memory + * \return Reference to the error string. + */ + static EMGMResponse getLastError(void) { return m_eLastErrorMSG; }; + +/*!\brief add a Firmware FB type to the type lib (is mainly used by the corresponding entry class). + */ + static void addFBType(CFBTypeEntry *pa_poFBTypeEntry); + + /*!\brief add a Firmware Adapter type to the type lib (is mainly used by the corresponding entry class). + */ + static void addAdapterType(CAdapterTypeEntry *pa_poAdapterTypeEntry); + +/*!\brief add a Firmware data type to the type lib (is mainly used by the corresponding entry class). + */ + static void addDataType(CDataTypeEntry *pa_poDTEntry); +/*!\brief Get a pointer to the begin of the FB library list + */ + static CTypeEntry *getFBLibStart() { return m_poFBLibStart; } + + /*!\brief Get a pointer to the begin of the FB library list + */ + static CTypeEntry *getAdapterLibStart() { return m_poAdapterLibStart; } + + /*!\brief Get a pointer to the begin of the datatype library list + */ + static CTypeEntry *getDTLibStart() { return m_poDTLibStart; } + +protected: +private: + +/*!\brief Buffer for the last error that occurred. + */ + static EMGMResponse m_eLastErrorMSG; + + static CFBTypeEntry *m_poFBLibStart, //!< pointer to the begin of the firmware fb library list + *m_poFBLibEnd; //! +#include +#include +#include + +template +void anyBitFBHelper(CIEC_ANY::EDataTypeID pa_eDataTypeId, T &pa_roFB){ + switch (pa_eDataTypeId){ + case CIEC_ANY::e_BOOL: + pa_roFB.template calculateValue(); + break; + case CIEC_ANY::e_BYTE: + pa_roFB.template calculateValue(); + break; + case CIEC_ANY::e_WORD: + pa_roFB.template calculateValue(); + break; + #ifdef FORTE_USE_64BIT_DATATYPES + case CIEC_ANY::e_LWORD: + pa_roFB.template calculateValue(); + break; + #endif + default: + pa_roFB.template calculateValue(); + break; + } +} + +template +void anyMagnitudeFBHelper(CIEC_ANY::EDataTypeID pa_eDataTypeId, T &pa_roFB){ + switch (pa_eDataTypeId){ + case CIEC_ANY::e_REAL: + #ifdef FORTE_USE_REAL_DATATYPE + pa_roFB.template calculateValue(); + #endif + break; + case CIEC_ANY::e_LREAL: + #ifdef FORTE_USE_REAL_DATATYPE + #ifdef FORTE_USE_64BIT_DATATYPES + pa_roFB.template calculateValue(); + #endif + #endif + break; + default: + if(pa_eDataTypeId <= CIEC_ANY::e_TIME){ + #ifdef FORTE_USE_64BIT_DATATYPES + pa_roFB.template calculateValue(); + #else + pa_roFB.template calculateValue(); + #endif + } + break; + } +} + +template +void anyIntFBHelper(CIEC_ANY::EDataTypeID pa_eDataTypeId, T &pa_roFB){ + switch (pa_eDataTypeId){ + case CIEC_ANY::e_SINT: + pa_roFB.template calculateValue(); + break; + case CIEC_ANY::e_DINT: + pa_roFB.template calculateValue(); + break; + #ifdef FORTE_USE_64BIT_DATATYPES + case CIEC_ANY::e_LINT: + pa_roFB.template calculateValue(); + break; + case CIEC_ANY::e_ULINT: + pa_roFB.template calculateValue(); + break; + #endif + case CIEC_ANY::e_UINT: + pa_roFB.template calculateValue(); + break; + case CIEC_ANY::e_USINT: + pa_roFB.template calculateValue(); + break; + case CIEC_ANY::e_UDINT: + pa_roFB.template calculateValue(); + break; + default: + pa_roFB.template calculateValue(); + break; + } +} + +template +void anyRealFBHelper(CIEC_ANY::EDataTypeID pa_eDataTypeId, T &pa_roFB){ + switch (pa_eDataTypeId){ + case CIEC_ANY::e_REAL: + #ifdef FORTE_USE_REAL_DATATYPE + pa_roFB.template calculateValue(); + #endif + break; + case CIEC_ANY::e_LREAL: + #ifdef FORTE_USE_LREAL_DATATYPE + pa_roFB.template calculateValue(); + #endif + break; + default: + break; + } +} + +template +void anyNumFBHelper(CIEC_ANY::EDataTypeID pa_eDataTypeId, T &pa_roFB){ + if(CIEC_ANY::e_LREAL == pa_eDataTypeId || CIEC_ANY::e_REAL == pa_eDataTypeId){ + anyRealFBHelper(pa_eDataTypeId, pa_roFB); + }else{ + anyIntFBHelper(pa_eDataTypeId, pa_roFB); + } +} + +template +void anyElementaryFBHelper(CIEC_ANY::EDataTypeID pa_eDataTypeId, T &pa_roFB){ + if(CIEC_STRING::e_STRING == pa_eDataTypeId){ + pa_roFB.template calculateValueString(); + } +#ifdef FORTE_USE_WSTRING_DATATYPE + else if(CIEC_WSTRING::e_WSTRING == pa_eDataTypeId){ + pa_roFB.template calculateValueString(); + } +#endif + else{ + anyMagnitudeFBHelper(pa_eDataTypeId, pa_roFB); + } +} + +template +void anyStringFBHelper(CIEC_ANY::EDataTypeID pa_eDataTypeId, T &pa_roFB){ + if(CIEC_STRING::e_STRING == pa_eDataTypeId){ + pa_roFB.template calculateValueString(); + } +#ifdef FORTE_USE_WSTRING_DATATYPE + else if(CIEC_WSTRING::e_WSTRING == pa_eDataTypeId){ + pa_roFB.template calculateValueString(); + } +#endif +} + +#endif /* ANYELEMHELPER_H_ */ diff --git a/src/core/utils/criticalregion.h b/src/core/utils/criticalregion.h new file mode 100644 index 000000000..a3f28c8a1 --- /dev/null +++ b/src/core/utils/criticalregion.h @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef CRITICALREGION_H_ +#define CRITICALREGION_H_ + +#include + +class CCriticalRegion{ + public: + CCriticalRegion(CSyncObject &paSyncObject) : mSyncObject(paSyncObject){ + mSyncObject.lock(); + } + + ~CCriticalRegion(){ + mSyncObject.unlock(); + } + + private: + CSyncObject &mSyncObject; + +}; + + + +#endif /* CRITICALREGION_H_ */ diff --git a/src/core/utils/fixedcapvector.h b/src/core/utils/fixedcapvector.h new file mode 100644 index 000000000..e35dd05f6 --- /dev/null +++ b/src/core/utils/fixedcapvector.h @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FIXEDCAPVECTOR_H_ +#define FIXEDCAPVECTOR_H_ + +#include "fortearray.h" + +namespace forte { + namespace core { + namespace util { + + /*!\brief A vector having a fixed size array as data storage. + * + * Allows to push_back items, pop items, access the items, iterate over, and clear them. + */ + template > + class CFixedCapazityVector{ + public: + CFixedCapazityVector() : + mNumElements(0){ + } + + void clear(){ + mNumElements = 0; + } + + bool pushBack(const T & paVal){ + bool retVal = false; + if(mNumElements < Capacity){ + mDataStorage[mNumElements] = paVal; + mNumElements++; + retVal = true; + } + return retVal; + } + + void popBack(){ + if(0 < mNumElements){ + mNumElements--; + } + } + + T& front(){ + return mDataStorage[0]; + } + + T& back(){ + return mDataStorage[mNumElements - 1]; + } + + T& operator [](size_t paIndex){ + assert(paIndex < Capacity); + return mDataStorage[paIndex]; + } + + bool isEmpty() const{ + return (0 == mNumElements); + } + + size_t size(){ + return mNumElements; + } + + class CIterator{ + public: + CIterator(CFixedCapazityVector &paVector, size_t paPos) : mVector(paVector), mPos(paPos){ + } + + CIterator& operator++(){ + if(mPos < mVector.size()){ + mPos++; + } + return *this; + } + + T& operator*(){ + return mVector[mPos]; + } + + bool operator==(CIterator const& rhs) const{ + return mPos == rhs.mPos; + } + + bool operator!=(CIterator const& rhs) const{ + return !(*this == rhs); + } + + bool isLastEntry(){ + return (mPos == (mVector.size() -1)); + } + + private: + + CFixedCapazityVector &mVector; + size_t mPos; + + }; + + const CIterator begin(){ + return CIterator(*this, 0); + } + + const CIterator end(){ + return CIterator(*this, mNumElements); + } + + private: + TDataStorage mDataStorage; + size_t mNumElements; //!< number of all elements currently in this container + }; + + } // namespace util + } // namespace core +} // namespace forte + +#endif // FIXEDCAPVECTOR_H_ diff --git a/src/core/utils/fortearray.h b/src/core/utils/fortearray.h new file mode 100644 index 000000000..4b059ff56 --- /dev/null +++ b/src/core/utils/fortearray.h @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FORTEARRAY_H_ +#define FORTEARRAY_H_ + +#include +#include + +namespace forte { + namespace core { + namespace util { + + + /*!\brief Simple array class allowing to implement more save arrays. + * + * This class is aligned to the std::array. + * Consider to use std:array when stl support gets better on all supported platforms. + */ + template + class CArray{ + public: + T& operator [](size_t paIndex){ + assert(paIndex < Capacity); + return mData[paIndex]; + } + + size_t getSize(){ + return Capacity; + } + + private: + T mData[Capacity]; + }; + + } // namespace util + } // namespace core +} // namespace forte + +#endif /* FORTEARRAY_H_ */ diff --git a/src/core/utils/singlet.h b/src/core/utils/singlet.h new file mode 100644 index 000000000..4923ea6cf --- /dev/null +++ b/src/core/utils/singlet.h @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2010 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SINGLET_H_ +#define _SINGLET_H_ + +/*!\ingroup CORE \brief Macro for providing singleton functionality. + * + * Classes derived from this template have only one single instance. + * Usage: in the class declaration: + * class CMyNewClass{ + * SINGLETON(TypeName) + * + * As the macro already defines a default constructor you have to implement it + * in the cpp file. + */ +#define DECLARE_SINGLETON(TypeName) \ + public: \ + static TypeName &getInstance(void); \ + private: \ + TypeName(); \ + TypeName(const TypeName&); \ + TypeName& operator = (const TypeName &); \ + ~TypeName(); + +#define DEFINE_SINGLETON(TypeName) \ + TypeName& TypeName::getInstance(void){ \ + static TypeName oInstance; \ + return oInstance; \ + }; + +#endif /*SINGLET_H_*/ diff --git a/src/core/utils/staticassert.h b/src/core/utils/staticassert.h new file mode 100644 index 000000000..c6c339f91 --- /dev/null +++ b/src/core/utils/staticassert.h @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SATICASSERT_H_ +#define _SATICASSERT_H_ + +#ifdef __GNUC__ + //The latest GCC is rather picky about unused typedefs. We need this for our static assert and its ok there that it is unused there. + #define FORTE_ATTRIBUTE_UNUSED __attribute__((unused)) +#else + #define FORTE_ATTRIBUTE_UNUSED +#endif + +/*! A simple compile time assert which is based on the books: + * - Modern C++ Design, Andrei Alexandrescu + * - Imperfect C++, Matthew Wilson + * It tries to combine the simplicity of Wilson's solution with the + * better compiler message generation of Alexandrescu's solution. + */ +#define FORTE_STATIC_ASSERT(paExpr, paMsg) \ + { typedef int ERROR_##paMsg[(paExpr) ? 1 : -1] FORTE_ATTRIBUTE_UNUSED; } + +//(void)sizeof(ERROR_##paMsg);} + +#endif diff --git a/src/core/utils/string_utils.cpp b/src/core/utils/string_utils.cpp new file mode 100644 index 000000000..39ae1e800 --- /dev/null +++ b/src/core/utils/string_utils.cpp @@ -0,0 +1,207 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "string_utils.h" +#include +#include +#include +#include +#include +#include + +bool forte::core::util::isAtoFChar(char pa_cValue){ + pa_cValue = static_cast(toupper(pa_cValue)); + return ((pa_cValue >= 'A') && (pa_cValue <= 'F')); +} + +TForteInt8 forte::core::util::charAtoFToInt(char pa_cValue){ + return static_cast((toupper(pa_cValue) - 'A') + 10); +} + +long int forte::core::util::strtol(const char *nptr, char **endptr, int base) { + long int nRetVal = 0; + bool bNegativeNumber = false; + errno = 0; + + //in difference to IEC 611313-3 literals base 16 literals may have a leading - + if((*nptr) == '-'){ + bNegativeNumber = true; + ++nptr; + } + + if(16 == base){ + if(('0' == (*nptr)) && ('x' == nptr[1])){ + //we have a preceding 0x step over it + nptr += 2; + } + } + + long nLimit1 = (bNegativeNumber ? -(CIEC_DINT::scm_nMinVal / base) : (CIEC_DINT::scm_nMaxVal / base)); + long nLimit2 = (bNegativeNumber ? -(CIEC_DINT::scm_nMinVal % base) : (CIEC_DINT::scm_nMaxVal % base)); + if (nLimit2 < 0) // Rounding direction for negative numbers is implementation defined + { + nLimit1--; + nLimit2 = base-nLimit2; + } + + for(; *nptr; ++nptr){ //Do until '/0' + if((!isDigit(*nptr)) && (!((16 == base) && isAtoFChar(*nptr)))){ + //we have an invalid character + break; + } + TForteInt8 nCharVal = charHexDigitToInt(*nptr); + if(nRetVal > nLimit1 || (nRetVal == nLimit1 && nCharVal > nLimit2)) { + nRetVal = (bNegativeNumber) ? CIEC_DINT::scm_nMinVal : CIEC_DINT::scm_nMaxVal; + errno = ERANGE; + break; + } + nRetVal = base * nRetVal + nCharVal; + } + + if((bNegativeNumber) && (ERANGE != errno)){ + nRetVal = -nRetVal; + } + + if(0 != endptr){ + *endptr = const_cast(nptr); + } + return nRetVal; +} + +unsigned long int forte::core::util::strtoul(const char *nptr, char **endptr, int base){ + unsigned long int unRetVal = 0; + unsigned long int unLimit1 = (CIEC_UDINT::scm_nMaxVal / base); + unsigned long int unLimit2 = (CIEC_UDINT::scm_nMaxVal % base); + errno = 0; + + if((16 == base) && ('0' == (*nptr)) && ('x' == nptr[1])){ + //we have a preceding 0x step over it + nptr += 2; + } + + for(; *nptr; ++nptr){ //Do until '/0' + if((!isDigit(*nptr)) && (!((16 == base) && isAtoFChar(*nptr)))){ + //we have an invalid character + break; + } + TForteInt8 nCharVal = charHexDigitToInt(*nptr); + + if(unRetVal > unLimit1 || (unRetVal == unLimit1 && (unsigned long int) nCharVal > unLimit2)){ + //in this round we would exceed the limit of the data type + unRetVal = CIEC_UDINT::scm_nMaxVal; + errno = ERANGE; + break; + } + unRetVal = base * unRetVal + nCharVal; + } + if(0 != endptr){ + *endptr = const_cast(nptr); + } + return unRetVal; +} + +#ifdef FORTE_USE_64BIT_DATATYPES +long long int forte::core::util::strtoll(const char *nptr, char **endptr, int base) { + long long int nRetVal = 0; + bool bNegativeNumber = false; + errno = 0; + + //in difference to IEC 611313-3 literals base 16 literals may have a leading - + if((*nptr) == '-'){ + bNegativeNumber = true; + ++nptr; + } + + if(16 == base){ + if(('0' == (*nptr)) && ('x' == nptr[1])){ + //we have a preceding 0x step over it + nptr += 2; + } + } + +// The volatile magic works around an apparent optimizer bug on Visual Studio 2008. Looks like this one: +// http://connect.microsoft.com/VisualStudio/feedback/details/267232/sign-error-in-long-integer-arithmetic +// "The Visual C++ team has evaluated the bug and determined it does not meet the guidelines necessary to warrant a fix." + volatile long long nLimit1, nLimit2; + + if (bNegativeNumber){ + volatile long long nLimMinDiv = CIEC_LINT::scm_nMinVal / base; + volatile long long nLimMinMod = CIEC_LINT::scm_nMinVal % base; + + nLimit1 = -nLimMinDiv; + nLimit2 = -nLimMinMod; + + if (nLimit2 < 0) // Rounding direction for negative numbers is implementation defined + { + nLimit1--; + nLimit2 = base-nLimit2; + } + } + else{ + nLimit1 = CIEC_LINT::scm_nMaxVal / base; + nLimit2 = CIEC_LINT::scm_nMaxVal % base; + } + + for(; *nptr; ++nptr){ //Do until '/0' + if((!isDigit(*nptr)) && (!((16 == base) && isAtoFChar(*nptr)))){ + //we have an invalid character + break; + } + TForteInt8 nCharVal = charHexDigitToInt(*nptr); + if(nRetVal > nLimit1 || (nRetVal == nLimit1 && nCharVal > nLimit2)){ + nRetVal = (bNegativeNumber) ? CIEC_LINT::scm_nMinVal : CIEC_LINT::scm_nMaxVal; + errno = ERANGE; + break; + } + nRetVal = base * nRetVal + nCharVal; + } + + if((bNegativeNumber) && (ERANGE != errno)){ + nRetVal = -nRetVal; + } + if(0 != endptr){ + *endptr = const_cast(nptr); + } + return nRetVal; +} + +unsigned long long int forte::core::util::strtoull(const char *nptr, char **endptr, int base){ + unsigned long long int unRetVal = 0; + unsigned long long int unLimit1 = (CIEC_ULINT::scm_nMaxVal / base); + unsigned long long int unLimit2 = (CIEC_ULINT::scm_nMaxVal % base); + errno = 0; + + if((16 == base) && ('0' == (*nptr)) && ('x' == nptr[1])){ + //we have a preceding 0x step over it + nptr += 2; + } + + for(; *nptr; ++nptr){ //Do until '/0' + if((!isDigit(*nptr)) && (!((16 == base) && isAtoFChar(*nptr)))){ + //we have an invalid character + break; + } + TForteInt8 nCharVal = charHexDigitToInt(*nptr); + if(unRetVal > unLimit1 || (unRetVal == unLimit1 && (unsigned long long int) nCharVal > unLimit2)){ + //in this round we would exceed the limit of the data type + unRetVal = CIEC_ULINT::scm_nMaxVal; + errno = ERANGE; + break; + } + unRetVal = base * unRetVal + nCharVal; + } + if(0 != endptr){ + *endptr = const_cast(nptr); + } + return unRetVal; +} + +#endif diff --git a/src/core/utils/string_utils.h b/src/core/utils/string_utils.h new file mode 100644 index 000000000..46eb7d916 --- /dev/null +++ b/src/core/utils/string_utils.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _STRING_UTILS_H_ +#define _STRING_UTILS_H_ + +#include + +namespace forte { + namespace core { + namespace util { + + inline bool isDigit(char pa_cValue){ + return ((pa_cValue >= '0') && (pa_cValue <= '9')); + } + + bool isAtoFChar(char pa_cValue); + + inline bool isHexDigit(char pa_cValue){ + return isDigit(pa_cValue) || isAtoFChar(pa_cValue); + } + + inline TForteInt8 charDigitToInt(char pa_cValue){ + return static_cast(pa_cValue - '0'); + } + + TForteInt8 charAtoFToInt(char pa_cValue); + + inline TForteInt8 charHexDigitToInt(char pa_cValue){ + return isDigit(pa_cValue) ? charDigitToInt(pa_cValue) : charAtoFToInt(pa_cValue); + } + + long int strtol(const char *nptr, char **endptr, int base); + + unsigned long int strtoul(const char *nptr, char **endptr, int base); + +#ifdef FORTE_USE_64BIT_DATATYPES + long long int strtoll(const char *nptr, char **endptr, int base); + + unsigned long long int strtoull(const char *nptr, char **endptr, int base); +#endif + + } + } +} + +#endif diff --git a/src/forteinit.cpp.in b/src/forteinit.cpp.in new file mode 100644 index 000000000..f2fee9b51 --- /dev/null +++ b/src/forteinit.cpp.in @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2011, 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerhard Ebenhofer, Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +//!!!autogenerated code - DO NOT EDIT!!! + + +#include "forteinit.h" + +#include <${FORTE_SOURCE_DIR}/src/core/datatypes/forte_any.h> + +${DATATYPE_INCLUDE_STRING} + +${FB_INCLUDE_STRING} + +void forteInit::initForte() +{ + CIEC_ANY::dummyInit(); + ${DATATYPE_FUNCTION_STRING} + + ${FB_FUNCTION_STRING} + + return; +} + + diff --git a/src/forteinit.h.in b/src/forteinit.h.in new file mode 100644 index 000000000..f49828ae5 --- /dev/null +++ b/src/forteinit.h.in @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2011 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +//!!!autogenerated code - DO NOT EDIT!!! +#ifndef FORTEINIT_H_ +#define FORTEINIT_H_ + + +class forteInit +{ +public: + static void initForte(); +}; + +#endif /*FORTEINIT_H_*/ diff --git a/src/gen_include.cpp.in b/src/gen_include.cpp.in new file mode 100644 index 000000000..e52be0ce4 --- /dev/null +++ b/src/gen_include.cpp.in @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2012 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Hofmann + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +//!!!autogenerated code - DO NOT EDIT!!! +${${FBLIB_FILE}_externals} diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt new file mode 100644 index 000000000..666baf6dd --- /dev/null +++ b/src/modules/CMakeLists.txt @@ -0,0 +1 @@ +INCLUDE(${CMAKE_BINARY_DIR}/src/modules/CMakeLists.txt) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Arithmetic/CMakeLists.txt b/src/modules/IEC61131-3/Arithmetic/CMakeLists.txt new file mode 100644 index 000000000..a19307615 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/CMakeLists.txt @@ -0,0 +1,38 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2014 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Arithmetic +############################################################################# +forte_add_sourcefile_hcpp(F_ADD) +forte_add_sourcefile_hcpp(F_SUB) +forte_add_sourcefile_hcpp(F_MUL) +forte_add_sourcefile_hcpp(F_DIV) +forte_add_sourcefile_hcpp(F_MOD) +forte_add_sourcefile_hcpp(F_EXPT) +forte_add_sourcefile_hcpp(F_MOVE) +forte_add_sourcefile_hcpp(F_MULTIME) +forte_add_sourcefile_hcpp(F_DIVTIME) +forte_add_sourcefile_hcpp(GEN_ADD) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_TRUNC) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_ADD_DT_TIME) + forte_add_sourcefile_hcpp(F_ADD_TOD_TIME) + forte_add_sourcefile_hcpp(F_SUB_DT_TIME) + forte_add_sourcefile_hcpp(F_SUB_TOD_TIME) + forte_add_sourcefile_hcpp(F_SUB_DT_DT) + forte_add_sourcefile_hcpp(F_SUB_DATE_DATE) + forte_add_sourcefile_hcpp(F_SUB_TOD_TOD) +endif(FORTE_USE_64BIT_DATATYPES) diff --git a/src/modules/IEC61131-3/Arithmetic/F_ADD.cpp b/src/modules/IEC61131-3/Arithmetic/F_ADD.cpp new file mode 100644 index 000000000..3d9373735 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_ADD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ADD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ADD_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_ADD, g_nStringIdF_ADD) + +const CStringDictionary::TStringId FORTE_F_ADD::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_ADD::scm_anDataInputTypeIds[] = {g_nStringIdANY_MAGNITUDE, g_nStringIdANY_MAGNITUDE}; + +const CStringDictionary::TStringId FORTE_F_ADD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ADD::scm_anDataOutputTypeIds[] = {g_nStringIdANY_MAGNITUDE}; + +const TForteInt16 FORTE_F_ADD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ADD::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_ADD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ADD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ADD::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_ADD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ADD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ADD::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyMagnitudeFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Arithmetic/F_ADD.h b/src/modules/IEC61131-3/Arithmetic/F_ADD.h new file mode 100644 index 000000000..5174e4667 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_ADD.h @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ADD_H_ +#define _F_ADD_H_ + +#include +#include + +class FORTE_F_ADD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ADD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_MAGNITUDE &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_MAGNITUDE &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_MAGNITUDE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ADD){ + }; + + template void calculateValue(){ + T &roIn1(static_cast(IN1())); + T oIn2; + oIn2.saveAssign(IN2()); + OUT().saveAssign(ADD(roIn1,oIn2)); + } + + virtual ~FORTE_F_ADD(){}; +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_ADD_DT_TIME.cpp b/src/modules/IEC61131-3/Arithmetic/F_ADD_DT_TIME.cpp new file mode 100644 index 000000000..022c7711f --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_ADD_DT_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ADD_DT_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ADD_DT_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ADD_DT_TIME, g_nStringIdF_ADD_DT_TIME) + +const CStringDictionary::TStringId FORTE_F_ADD_DT_TIME::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_ADD_DT_TIME::scm_anDataInputTypeIds[] = {g_nStringIdDATE_AND_TIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_ADD_DT_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ADD_DT_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdDATE_AND_TIME}; + +const TForteInt16 FORTE_F_ADD_DT_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ADD_DT_TIME::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_ADD_DT_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ADD_DT_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ADD_DT_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ADD_DT_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ADD_DT_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ADD_DT_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ADD_DT_TIME(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_ADD_DT_TIME.h b/src/modules/IEC61131-3/Arithmetic/F_ADD_DT_TIME.h new file mode 100644 index 000000000..88ec22145 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_ADD_DT_TIME.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ADD_DT_TIME_H_ +#define _F_ADD_DT_TIME_H_ + +#include +#include +#include + +class FORTE_F_ADD_DT_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ADD_DT_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DATE_AND_TIME &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DATE_AND_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ADD_DT_TIME){ + }; + + virtual ~FORTE_F_ADD_DT_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_ADD_TOD_TIME.cpp b/src/modules/IEC61131-3/Arithmetic/F_ADD_TOD_TIME.cpp new file mode 100644 index 000000000..77c4f5f87 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_ADD_TOD_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ADD_TOD_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ADD_TOD_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ADD_TOD_TIME, g_nStringIdF_ADD_TOD_TIME) + +const CStringDictionary::TStringId FORTE_F_ADD_TOD_TIME::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_ADD_TOD_TIME::scm_anDataInputTypeIds[] = {g_nStringIdTIME_OF_DAY, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_ADD_TOD_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ADD_TOD_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME_OF_DAY}; + +const TForteInt16 FORTE_F_ADD_TOD_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ADD_TOD_TIME::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_ADD_TOD_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ADD_TOD_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ADD_TOD_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ADD_TOD_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ADD_TOD_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ADD_TOD_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ADD_TOD_TIME(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_ADD_TOD_TIME.h b/src/modules/IEC61131-3/Arithmetic/F_ADD_TOD_TIME.h new file mode 100644 index 000000000..df6e8cd39 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_ADD_TOD_TIME.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ADD_TOD_TIME_H_ +#define _F_ADD_TOD_TIME_H_ + +#include +#include +#include + +class FORTE_F_ADD_TOD_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ADD_TOD_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME_OF_DAY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME_OF_DAY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ADD_TOD_TIME){ + }; + + virtual ~FORTE_F_ADD_TOD_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_DIV.cpp b/src/modules/IEC61131-3/Arithmetic/F_DIV.cpp new file mode 100644 index 000000000..8fa6c5cef --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_DIV.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_DIV.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DIV_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_DIV, g_nStringIdF_DIV) + +const CStringDictionary::TStringId FORTE_F_DIV::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_DIV::scm_anDataInputTypeIds[] = {g_nStringIdANY_NUM, g_nStringIdANY_NUM}; + +const CStringDictionary::TStringId FORTE_F_DIV::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DIV::scm_anDataOutputTypeIds[] = {g_nStringIdANY_NUM}; + +const TForteInt16 FORTE_F_DIV::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DIV::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_DIV::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DIV::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DIV::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_DIV::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DIV::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DIV::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyMagnitudeFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Arithmetic/F_DIV.h b/src/modules/IEC61131-3/Arithmetic/F_DIV.h new file mode 100644 index 000000000..a129fe9e0 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_DIV.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_DIV_H_ +#define _F_DIV_H_ + +#include +#include + +class FORTE_F_DIV: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DIV) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_NUM &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_NUM &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_NUM &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DIV){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + + OUT().saveAssign(DIV(oIn1,oIn2)); + +// char strbuf1[100]; +// char strbuf2[100]; +// char strbuf3[100]; +// IN1().toString(strbuf1, sizeof(strbuf1)); +// IN2().toString(strbuf2, sizeof(strbuf2)); +// OUT().toString(strbuf3, sizeof(strbuf3)); +// DEVLOG_INFO_4(cg_nID_CDeviceLog, 0x10, " %s / %s = %s", strbuf1, strbuf2, strbuf3); + } + + virtual ~FORTE_F_DIV(){}; +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_DIVTIME.cpp b/src/modules/IEC61131-3/Arithmetic/F_DIVTIME.cpp new file mode 100644 index 000000000..caeb2542c --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_DIVTIME.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DIVTIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DIVTIME_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_DIVTIME, g_nStringIdF_DIVTIME) + +const CStringDictionary::TStringId FORTE_F_DIVTIME::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_DIVTIME::scm_anDataInputTypeIds[] = {g_nStringIdTIME, g_nStringIdANY_NUM}; + +const CStringDictionary::TStringId FORTE_F_DIVTIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DIVTIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_DIVTIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DIVTIME::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_DIVTIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DIVTIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DIVTIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DIVTIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DIVTIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DIVTIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + anyIntFBHelper(IN2().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_DIVTIME.h b/src/modules/IEC61131-3/Arithmetic/F_DIVTIME.h new file mode 100644 index 000000000..095a9272c --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_DIVTIME.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DIVTIME_H_ +#define _F_DIVTIME_H_ + +#include +#include +#include + +class FORTE_F_DIVTIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DIVTIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_NUM &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DIVTIME){ + }; + + template void calculateValue(){ + T &roIn2(static_cast(IN2())); + OUT().saveAssign(DIVTIME(IN1(), roIn2)); + } + + virtual ~FORTE_F_DIVTIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_EXPT.cpp b/src/modules/IEC61131-3/Arithmetic/F_EXPT.cpp new file mode 100644 index 000000000..db8ae5062 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_EXPT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_EXPT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_EXPT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_EXPT, g_nStringIdF_EXPT) + +const CStringDictionary::TStringId FORTE_F_EXPT::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_EXPT::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL, g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_EXPT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_EXPT::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_EXPT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_EXPT::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_EXPT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_EXPT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_EXPT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_EXPT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_EXPT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_EXPT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/Arithmetic/F_EXPT.h b/src/modules/IEC61131-3/Arithmetic/F_EXPT.h new file mode 100644 index 000000000..b519d4df5 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_EXPT.h @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_EXPT_H_ +#define _F_EXPT_H_ + +#include +#include +#include + +class FORTE_F_EXPT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_EXPT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_REAL &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_EXPT){ + }; + + template void calculateValue(){ + T &roIn1(static_cast(IN1())); + T oIn2; + oIn2.saveAssign(IN2()); + OUT().saveAssign(EXPT(roIn1,oIn2)); + } + + virtual ~FORTE_F_EXPT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_MOD.cpp b/src/modules/IEC61131-3/Arithmetic/F_MOD.cpp new file mode 100644 index 000000000..536021f85 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MOD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_MOD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MOD_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_MOD, g_nStringIdF_MOD) + +const CStringDictionary::TStringId FORTE_F_MOD::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_MOD::scm_anDataInputTypeIds[] = {g_nStringIdANY_INT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_MOD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MOD::scm_anDataOutputTypeIds[] = {g_nStringIdANY_NUM}; + +const TForteInt16 FORTE_F_MOD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MOD::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_MOD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MOD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MOD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_MOD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MOD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MOD::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyIntFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/Arithmetic/F_MOD.h b/src/modules/IEC61131-3/Arithmetic/F_MOD.h new file mode 100644 index 000000000..738aa79d3 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MOD.h @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_MOD_H_ +#define _F_MOD_H_ + +#include +#include +#include + +class FORTE_F_MOD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MOD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_INT &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_NUM &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MOD){ + }; + + template void calculateValue(){ + T &roIn1(static_cast(IN1())); + T oIn2; + oIn2.saveAssign(IN2()); + OUT().saveAssign(MOD(roIn1,oIn2)); + } + + virtual ~FORTE_F_MOD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_MOVE.cpp b/src/modules/IEC61131-3/Arithmetic/F_MOVE.cpp new file mode 100644 index 000000000..6c1751fbe --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MOVE.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_MOVE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MOVE_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_MOVE, g_nStringIdF_MOVE) + +const CStringDictionary::TStringId FORTE_F_MOVE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_MOVE::scm_anDataInputTypeIds[] = {g_nStringIdANY}; + +const CStringDictionary::TStringId FORTE_F_MOVE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MOVE::scm_anDataOutputTypeIds[] = {g_nStringIdANY}; + +const TForteInt16 FORTE_F_MOVE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MOVE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_MOVE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MOVE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MOVE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_MOVE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MOVE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MOVE::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyMagnitudeFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/Arithmetic/F_MOVE.h b/src/modules/IEC61131-3/Arithmetic/F_MOVE.h new file mode 100644 index 000000000..618a60340 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MOVE.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_MOVE_H_ +#define _F_MOVE_H_ + +#include +#include + +class FORTE_F_MOVE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MOVE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MOVE){ + }; + + template void calculateValue(){ + T &roIn(static_cast(IN())); + OUT().saveAssign(MOVE(roIn)); + } + + virtual ~FORTE_F_MOVE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_MUL.cpp b/src/modules/IEC61131-3/Arithmetic/F_MUL.cpp new file mode 100644 index 000000000..270d991f9 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MUL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_MUL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MUL_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_MUL, g_nStringIdF_MUL) + +const CStringDictionary::TStringId FORTE_F_MUL::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_MUL::scm_anDataInputTypeIds[] = {g_nStringIdANY_NUM, g_nStringIdANY_NUM}; + +const CStringDictionary::TStringId FORTE_F_MUL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MUL::scm_anDataOutputTypeIds[] = {g_nStringIdANY_NUM}; + +const TForteInt16 FORTE_F_MUL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MUL::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_MUL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MUL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MUL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_MUL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MUL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MUL::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyMagnitudeFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Arithmetic/F_MUL.h b/src/modules/IEC61131-3/Arithmetic/F_MUL.h new file mode 100644 index 000000000..06e0fde4c --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MUL.h @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_MUL_H_ +#define _F_MUL_H_ + +#include +#include + +class FORTE_F_MUL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MUL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_NUM &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_NUM &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_NUM &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MUL){ + }; + + template void calculateValue(){ + T &roIn1(static_cast(IN1())); + T oIn2; + oIn2.saveAssign(IN2()); + OUT().saveAssign(MUL(roIn1,oIn2)); + } + + virtual ~FORTE_F_MUL(){}; +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_MULTIME.cpp b/src/modules/IEC61131-3/Arithmetic/F_MULTIME.cpp new file mode 100644 index 000000000..6e62a6ca3 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MULTIME.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_MULTIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MULTIME_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_MULTIME, g_nStringIdF_MULTIME) + +const CStringDictionary::TStringId FORTE_F_MULTIME::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_MULTIME::scm_anDataInputTypeIds[] = {g_nStringIdTIME, g_nStringIdANY_NUM}; + +const CStringDictionary::TStringId FORTE_F_MULTIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MULTIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_MULTIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MULTIME::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_MULTIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MULTIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MULTIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_MULTIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MULTIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MULTIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + anyIntFBHelper(IN2().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_MULTIME.h b/src/modules/IEC61131-3/Arithmetic/F_MULTIME.h new file mode 100644 index 000000000..4e0841ecc --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_MULTIME.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_MULTIME_H_ +#define _F_MULTIME_H_ + +#include +#include +#include + +class FORTE_F_MULTIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MULTIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_NUM &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MULTIME){ + }; + + template void calculateValue(){ + T &roIn2(static_cast(IN2())); + OUT().saveAssign(MULTIME(IN1(), roIn2)); + } + + virtual ~FORTE_F_MULTIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB.cpp b/src/modules/IEC61131-3/Arithmetic/F_SUB.cpp new file mode 100644 index 000000000..9baf77210 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB.cpp @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_SUB.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SUB_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_SUB, g_nStringIdF_SUB) + +const CStringDictionary::TStringId FORTE_F_SUB::scm_anDataInputNames[] = { g_nStringIdIN1, g_nStringIdIN2 }; + +const CStringDictionary::TStringId FORTE_F_SUB::scm_anDataInputTypeIds[] = { g_nStringIdANY_MAGNITUDE, g_nStringIdANY_MAGNITUDE }; + +const CStringDictionary::TStringId FORTE_F_SUB::scm_anDataOutputNames[] = { g_nStringIdOUT }; + +const CStringDictionary::TStringId FORTE_F_SUB::scm_anDataOutputTypeIds[] = { g_nStringIdANY_MAGNITUDE }; + +const TForteInt16 FORTE_F_SUB::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FORTE_F_SUB::scm_anEIWith[] = { 0, 1, 255 }; +const CStringDictionary::TStringId FORTE_F_SUB::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const TDataIOID FORTE_F_SUB::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 FORTE_F_SUB::scm_anEOWithIndexes[] = { 0 }; +const CStringDictionary::TStringId FORTE_F_SUB::scm_anEventOutputNames[] = { g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_F_SUB::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_F_SUB::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + anyMagnitudeFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB.h b/src/modules/IEC61131-3/Arithmetic/F_SUB.h new file mode 100644 index 000000000..c4ee1de92 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB.h @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_SUB_H_ +#define _F_SUB_H_ + +#include +#include + +class FORTE_F_SUB: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SUB) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_MAGNITUDE &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_MAGNITUDE &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_MAGNITUDE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SUB){ + }; + + template void calculateValue(){ + T &roIn1(static_cast(IN1())); + T oIn2; + oIn2.saveAssign(IN2()); + OUT().saveAssign(SUB(roIn1,oIn2)); + } + + virtual ~FORTE_F_SUB(){}; +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_DATE_DATE.cpp b/src/modules/IEC61131-3/Arithmetic/F_SUB_DATE_DATE.cpp new file mode 100644 index 000000000..fdb794239 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_DATE_DATE.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SUB_DATE_DATE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SUB_DATE_DATE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SUB_DATE_DATE, g_nStringIdF_SUB_DATE_DATE) + +const CStringDictionary::TStringId FORTE_F_SUB_DATE_DATE::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_SUB_DATE_DATE::scm_anDataInputTypeIds[] = {g_nStringIdDATE, g_nStringIdDATE}; + +const CStringDictionary::TStringId FORTE_F_SUB_DATE_DATE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SUB_DATE_DATE::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_SUB_DATE_DATE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SUB_DATE_DATE::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SUB_DATE_DATE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SUB_DATE_DATE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SUB_DATE_DATE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SUB_DATE_DATE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SUB_DATE_DATE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SUB_DATE_DATE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SUB_DATE_DATE(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_DATE_DATE.h b/src/modules/IEC61131-3/Arithmetic/F_SUB_DATE_DATE.h new file mode 100644 index 000000000..159df18e1 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_DATE_DATE.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SUB_DATE_DATE_H_ +#define _F_SUB_DATE_DATE_H_ + +#include +#include +#include + +class FORTE_F_SUB_DATE_DATE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SUB_DATE_DATE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DATE &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_DATE &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SUB_DATE_DATE){ + }; + + virtual ~FORTE_F_SUB_DATE_DATE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_DT.cpp b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_DT.cpp new file mode 100644 index 000000000..9c8fd01ab --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_DT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SUB_DT_DT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SUB_DT_DT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SUB_DT_DT, g_nStringIdF_SUB_DT_DT) + +const CStringDictionary::TStringId FORTE_F_SUB_DT_DT::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_SUB_DT_DT::scm_anDataInputTypeIds[] = {g_nStringIdDATE_AND_TIME, g_nStringIdDATE_AND_TIME}; + +const CStringDictionary::TStringId FORTE_F_SUB_DT_DT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SUB_DT_DT::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_SUB_DT_DT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SUB_DT_DT::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SUB_DT_DT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SUB_DT_DT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SUB_DT_DT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SUB_DT_DT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SUB_DT_DT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SUB_DT_DT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SUB_DT_DT(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_DT.h b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_DT.h new file mode 100644 index 000000000..1aa0f43e0 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_DT.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SUB_DT_DT_H_ +#define _F_SUB_DT_DT_H_ + +#include +#include +#include + +class FORTE_F_SUB_DT_DT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SUB_DT_DT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DATE_AND_TIME &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_DATE_AND_TIME &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SUB_DT_DT){ + }; + + virtual ~FORTE_F_SUB_DT_DT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_TIME.cpp b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_TIME.cpp new file mode 100644 index 000000000..d761a9a62 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SUB_DT_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SUB_DT_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SUB_DT_TIME, g_nStringIdF_SUB_DT_TIME) + +const CStringDictionary::TStringId FORTE_F_SUB_DT_TIME::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_SUB_DT_TIME::scm_anDataInputTypeIds[] = {g_nStringIdDATE_AND_TIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_SUB_DT_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SUB_DT_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdDATE_AND_TIME}; + +const TForteInt16 FORTE_F_SUB_DT_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SUB_DT_TIME::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SUB_DT_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SUB_DT_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SUB_DT_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SUB_DT_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SUB_DT_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SUB_DT_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SUB_DT_TIME(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_TIME.h b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_TIME.h new file mode 100644 index 000000000..7f1cd4703 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_DT_TIME.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SUB_DT_TIME_H_ +#define _F_SUB_DT_TIME_H_ + +#include +#include +#include + +class FORTE_F_SUB_DT_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SUB_DT_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DATE_AND_TIME &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DATE_AND_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SUB_DT_TIME){ + }; + + virtual ~FORTE_F_SUB_DT_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TIME.cpp b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TIME.cpp new file mode 100644 index 000000000..a4e5ec66b --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SUB_TOD_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SUB_TOD_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SUB_TOD_TIME, g_nStringIdF_SUB_TOD_TIME) + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TIME::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TIME::scm_anDataInputTypeIds[] = {g_nStringIdTIME_OF_DAY, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME_OF_DAY}; + +const TForteInt16 FORTE_F_SUB_TOD_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SUB_TOD_TIME::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SUB_TOD_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SUB_TOD_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SUB_TOD_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SUB_TOD_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SUB_TOD_TIME(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TIME.h b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TIME.h new file mode 100644 index 000000000..6108d8b89 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TIME.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SUB_TOD_TIME_H_ +#define _F_SUB_TOD_TIME_H_ + +#include +#include +#include + +class FORTE_F_SUB_TOD_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SUB_TOD_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME_OF_DAY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME_OF_DAY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SUB_TOD_TIME){ + }; + + virtual ~FORTE_F_SUB_TOD_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TOD.cpp b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TOD.cpp new file mode 100644 index 000000000..b2da95210 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TOD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SUB_TOD_TOD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SUB_TOD_TOD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SUB_TOD_TOD, g_nStringIdF_SUB_TOD_TOD) + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TOD::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TOD::scm_anDataInputTypeIds[] = {g_nStringIdTIME_OF_DAY, g_nStringIdTIME_OF_DAY}; + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TOD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TOD::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_SUB_TOD_TOD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SUB_TOD_TOD::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TOD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SUB_TOD_TOD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SUB_TOD_TOD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SUB_TOD_TOD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SUB_TOD_TOD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SUB_TOD_TOD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SUB_TOD_TOD(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TOD.h b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TOD.h new file mode 100644 index 000000000..38f828762 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_SUB_TOD_TOD.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SUB_TOD_TOD_H_ +#define _F_SUB_TOD_TOD_H_ + +#include +#include +#include + +class FORTE_F_SUB_TOD_TOD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SUB_TOD_TOD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME_OF_DAY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME_OF_DAY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SUB_TOD_TOD){ + }; + + virtual ~FORTE_F_SUB_TOD_TOD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/F_TRUNC.cpp b/src/modules/IEC61131-3/Arithmetic/F_TRUNC.cpp new file mode 100644 index 000000000..6b4cb88ce --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_TRUNC.cpp @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TRUNC.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TRUNC_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TRUNC, g_nStringIdF_TRUNC) + +const CStringDictionary::TStringId FORTE_F_TRUNC::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TRUNC::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_TRUNC::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TRUNC::scm_anDataOutputTypeIds[] = {g_nStringIdANY_INT}; + +const TForteInt16 FORTE_F_TRUNC::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TRUNC::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TRUNC::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TRUNC::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TRUNC::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TRUNC::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TRUNC::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TRUNC::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + switch(IN().getDataTypeID()){ + case CIEC_ANY::e_REAL: + OUT().setSignedValue(TRUNC(static_cast(IN()))); + break; + default: + OUT().setSignedValue(TRUNC(static_cast(IN()))); + break; + } + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/Arithmetic/F_TRUNC.h b/src/modules/IEC61131-3/Arithmetic/F_TRUNC.h new file mode 100644 index 000000000..d689f83b2 --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/F_TRUNC.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TRUNC_H_ +#define _F_TRUNC_H_ + +#include +#include +#include + +class FORTE_F_TRUNC: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TRUNC) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TRUNC){ + }; + + virtual ~FORTE_F_TRUNC(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Arithmetic/GEN_ADD.cpp b/src/modules/IEC61131-3/Arithmetic/GEN_ADD.cpp new file mode 100644 index 000000000..1a9bb75ae --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/GEN_ADD.cpp @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "GEN_ADD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_ADD_gen.cpp" +#endif + +#include +#include +#include +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_ADD, g_nStringIdGEN_ADD) + +const CStringDictionary::TStringId GEN_ADD::scm_anDataOutputNames[] = { + g_nStringIdOUT }; + +const CStringDictionary::TStringId GEN_ADD::scm_anDataOutputTypeIds[] = { + g_nStringIdANY_MAGNITUDE }; + +const TForteInt16 GEN_ADD::scm_anEIWithIndexes[] = { 0 }; +const CStringDictionary::TStringId GEN_ADD::scm_anEventInputNames[] = { + g_nStringIdREQ }; + +const TDataIOID GEN_ADD::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 GEN_ADD::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId GEN_ADD::scm_anEventOutputNames[] = { + g_nStringIdCNF }; + +GEN_ADD::GEN_ADD(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0) { +} + +GEN_ADD::~GEN_ADD() { + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anEIWith; +} + +void GEN_ADD::executeEvent(int pa_nEIID) { + switch (pa_nEIID) { + case scm_nEventREQID: + + anyMagnitudeFBHelper(OUT().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + +bool GEN_ADD::configureFB(const char *pa_acConfigString) { + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert( + pa_acConfigString); + + const char *pcPos = strrchr(pa_acConfigString, '_'); + + if (0 != pcPos) { + pcPos++; + //we have an underscore and it is the first underscore after AND + m_nDInputs = static_cast(forte::core::util::strtoul(pcPos, 0, 10)); + DEVLOG_DEBUG("DIs: %d;\n", m_nDInputs); + } else { + return false; + } + + if (m_nDInputs < 2) { + + return false; + } + + //now the number of needed eventInputs and dataOutputs are available in the integer array + //create the eventInputs + if (m_nDInputs < CFunctionBlock::scm_nMaxInterfaceEvents) { + + //create the data inputs + m_anDataInputNames = new CStringDictionary::TStringId[m_nDInputs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[m_nDInputs]; + + char diNames[cg_nIdentifierLength] = { "IN" }; + + for (int di = 0; di < m_nDInputs; di = di + 1) { + +#ifdef WIN32 + _snprintf(&(diNames[2]), 5 - 2, "%i", di+1); +#else + snprintf(&(diNames[2]), 5 - 2, "%i", di + 1); +#endif + m_anDataInputNames[di] = CStringDictionary::getInstance().insert(diNames); + m_anDataInputTypeIds[di] = g_nStringIdANY_MAGNITUDE; + } + + //now create the WITH constructs... + //the With-Indexes for the data variables + m_anEIWith = new TDataIOID[m_nDInputs + 1]; //for inputs + '255' separators at the list end + + //in-withs + for (int in_with = 0; in_with < m_nDInputs + 1; in_with = in_with + 1) { + if (in_with == m_nDInputs) { + //set end separator of with + m_anEIWith[in_with] = 255; + } else { + m_anEIWith[in_with] = static_cast(in_with); + } + } + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = + new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, m_anEIWith, + scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, + scm_anEOWithIndexes, static_cast(m_nDInputs), m_anDataInputNames, + m_anDataInputTypeIds, 1, scm_anDataOutputNames, + scm_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize( + pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, + pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize( + pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + return bRetVal; +} diff --git a/src/modules/IEC61131-3/Arithmetic/GEN_ADD.h b/src/modules/IEC61131-3/Arithmetic/GEN_ADD.h new file mode 100644 index 000000000..86032b2ce --- /dev/null +++ b/src/modules/IEC61131-3/Arithmetic/GEN_ADD.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _GEN_ADD_H_ +#define _GEN_ADD_H_ + +#include +#include + +class GEN_ADD: public CFunctionBlock { +DECLARE_GENERIC_FIRMWARE_FB(GEN_ADD) + +private: + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_MAGNITUDE &OUT() { + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + TDataIOID *m_anEIWith; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + //self-defined members + int m_nDInputs; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void executeEvent(int pa_nEIID); + + GEN_ADD(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes); + virtual ~GEN_ADD(); + +public: + + CStringDictionary::TStringId getFBTypeId(void) const { + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); + + template void calculateValue() { + T oIn, oOut; + + for (int nInputIndex = 0; nInputIndex < m_nDInputs; nInputIndex++) { + + oIn.saveAssign(*static_cast(getDI(nInputIndex))); + + if (0 == nInputIndex) { + OUT().saveAssign(oIn); + } else { + oOut.saveAssign(OUT()); + OUT().saveAssign(ADD(oOut, oIn)); + } + } + } +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BistableElements/CMakeLists.txt b/src/modules/IEC61131-3/BistableElements/CMakeLists.txt new file mode 100644 index 000000000..0cd2ddfe5 --- /dev/null +++ b/src/modules/IEC61131-3/BistableElements/CMakeLists.txt @@ -0,0 +1,16 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2012 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# BistableElements +############################################################################# +forte_add_sourcefile_hcpp(FB_RS) +forte_add_sourcefile_hcpp(FB_SR) \ No newline at end of file diff --git a/src/modules/IEC61131-3/BistableElements/FB_RS.cpp b/src/modules/IEC61131-3/BistableElements/FB_RS.cpp new file mode 100644 index 000000000..f9fb6f247 --- /dev/null +++ b/src/modules/IEC61131-3/BistableElements/FB_RS.cpp @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_RS.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_RS_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_RS, g_nStringIdFB_RS) + +const CStringDictionary::TStringId FB_RS::scm_anDataInputNames[] = {g_nStringIdS, g_nStringIdR1}; + +const CStringDictionary::TStringId FB_RS::scm_anDataOutputNames[] = {g_nStringIdQ1}; +const CStringDictionary::TStringId FB_RS::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL}; +const CStringDictionary::TStringId FB_RS::scm_aunDODataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FB_RS::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_RS::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FB_RS::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_RS::scm_anEOWith[] = {0, 255}; +const TForteInt16 FB_RS::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_RS::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_RS::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 2, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_RS::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + Q1() = !R1() && (S() || Q1()); + sendOutputEvent(scm_nEventCNFID); + break; + } +} diff --git a/src/modules/IEC61131-3/BistableElements/FB_RS.h b/src/modules/IEC61131-3/BistableElements/FB_RS.h new file mode 100644 index 000000000..9982833a0 --- /dev/null +++ b/src/modules/IEC61131-3/BistableElements/FB_RS.h @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_RS_H_ +#define _FB_RS_H_ + +#include +#include +#include + +class FB_RS: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_RS) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,2,1, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& S() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& R1() { + return *static_cast(getDI(1)); + } + + CIEC_BOOL& Q1() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_RS){}; + virtual ~FB_RS(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BistableElements/FB_SR.cpp b/src/modules/IEC61131-3/BistableElements/FB_SR.cpp new file mode 100644 index 000000000..8232676fb --- /dev/null +++ b/src/modules/IEC61131-3/BistableElements/FB_SR.cpp @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_SR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_SR_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_SR, g_nStringIdFB_SR) + +const CStringDictionary::TStringId FB_SR::scm_anDataInputNames[] = {g_nStringIdS1, g_nStringIdR}; + +const CStringDictionary::TStringId FB_SR::scm_anDataOutputNames[] = {g_nStringIdQ1}; +const CStringDictionary::TStringId FB_SR::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL}; +const CStringDictionary::TStringId FB_SR::scm_aunDODataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FB_SR::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_SR::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FB_SR::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_SR::scm_anEOWith[] = {0, 255}; +const TForteInt16 FB_SR::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_SR::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_SR::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 2, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_SR::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + Q1() = S1() || (!R() && Q1()); + sendOutputEvent(scm_nEventCNFID); + break; + } +} diff --git a/src/modules/IEC61131-3/BistableElements/FB_SR.h b/src/modules/IEC61131-3/BistableElements/FB_SR.h new file mode 100644 index 000000000..2ed4ff9ca --- /dev/null +++ b/src/modules/IEC61131-3/BistableElements/FB_SR.h @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_SR_H_ +#define _FB_SR_H_ + +#include +#include +#include + +class FB_SR: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_SR) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,2,1, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& S1() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(1)); + } + + CIEC_BOOL& Q1() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_SR){}; + virtual ~FB_SR(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/CMakeLists.txt b/src/modules/IEC61131-3/BitwiseOperators/CMakeLists.txt new file mode 100644 index 000000000..f03aafc76 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/CMakeLists.txt @@ -0,0 +1,24 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2014 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# BitwiseOperators +############################################################################# +forte_add_sourcefile_hcpp(F_AND) +forte_add_sourcefile_hcpp(F_NOT) +forte_add_sourcefile_hcpp(F_OR) +forte_add_sourcefile_hcpp(F_XOR) +forte_add_sourcefile_hcpp(GEN_AND GEN_OR GEN_XOR) + +forte_add_sourcefile_hcpp(F_SHL) +forte_add_sourcefile_hcpp(F_SHR) +forte_add_sourcefile_hcpp(F_ROR) +forte_add_sourcefile_hcpp(F_ROL) diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_AND.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_AND.cpp new file mode 100644 index 000000000..f711cf1b3 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_AND.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_AND.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_AND_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_AND, g_nStringIdF_AND) + +const CStringDictionary::TStringId FORTE_F_AND::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_AND::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT, g_nStringIdANY_BIT}; + +const CStringDictionary::TStringId FORTE_F_AND::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_AND::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_AND::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_AND::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_AND::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_AND::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_AND::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_AND::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_AND::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_AND::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_AND.h b/src/modules/IEC61131-3/BitwiseOperators/F_AND.h new file mode 100644 index 000000000..5fbc3c706 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_AND.h @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_AND_H_ +#define _F_AND_H_ + +#include +#include + +class FORTE_F_AND: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_AND) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_BIT &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_AND){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(AND(oIn1, oIn2)); + } + + virtual ~FORTE_F_AND(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_NOT.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_NOT.cpp new file mode 100644 index 000000000..4f7594445 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_NOT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_NOT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_NOT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_NOT, g_nStringIdF_NOT) + +const CStringDictionary::TStringId FORTE_F_NOT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_NOT::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT}; + +const CStringDictionary::TStringId FORTE_F_NOT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_NOT::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_NOT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_NOT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_NOT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_NOT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_NOT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_NOT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_NOT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_NOT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_NOT.h b/src/modules/IEC61131-3/BitwiseOperators/F_NOT.h new file mode 100644 index 000000000..5db601470 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_NOT.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_NOT_H_ +#define _F_NOT_H_ + +#include +#include + +class FORTE_F_NOT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_NOT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_NOT){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(NOT(oIn)); + } + + virtual ~FORTE_F_NOT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_OR.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_OR.cpp new file mode 100644 index 000000000..2c3c024a0 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_OR.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_OR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_OR_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_OR, g_nStringIdF_OR) + +const CStringDictionary::TStringId FORTE_F_OR::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_OR::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT, g_nStringIdANY_BIT}; + +const CStringDictionary::TStringId FORTE_F_OR::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_OR::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_OR::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_OR::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_OR::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_OR::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_OR::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_OR::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_OR::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_OR::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_OR.h b/src/modules/IEC61131-3/BitwiseOperators/F_OR.h new file mode 100644 index 000000000..b4ad9841a --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_OR.h @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_OR_H_ +#define _F_OR_H_ + +#include +#include + +class FORTE_F_OR: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_OR) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_BIT &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_OR){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(OR(oIn1, oIn2)); + } + + virtual ~FORTE_F_OR(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_ROL.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_ROL.cpp new file mode 100644 index 000000000..ac3216bee --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_ROL.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ROL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ROL_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_ROL, g_nStringIdF_ROL) + +const CStringDictionary::TStringId FORTE_F_ROL::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdN}; + +const CStringDictionary::TStringId FORTE_F_ROL::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_ROL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ROL::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_ROL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ROL::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_ROL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ROL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ROL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ROL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ROL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ROL::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_ROL.h b/src/modules/IEC61131-3/BitwiseOperators/F_ROL.h new file mode 100644 index 000000000..781a6a4e1 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_ROL.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ROL_H_ +#define _F_ROL_H_ + +#include +#include +#include + +class FORTE_F_ROL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ROL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &N() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ROL){ + }; + + template void calculateValue(){ + T oIn; + #ifdef FORTE_USE_64BIT_DATATYPES + CIEC_ULINT oN; + #else + CIEC_UDINT oN; + #endif //#ifdef FORTE_USE_64BIT_DATATYPES + + + oIn.saveAssign(IN()); + oN.saveAssign(N()); + OUT().saveAssign(ROL(oIn, oN)); + } + + virtual ~FORTE_F_ROL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_ROR.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_ROR.cpp new file mode 100644 index 000000000..fcd704b8d --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_ROR.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ROR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ROR_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_ROR, g_nStringIdF_ROR) + +const CStringDictionary::TStringId FORTE_F_ROR::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdN}; + +const CStringDictionary::TStringId FORTE_F_ROR::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_ROR::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ROR::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_ROR::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ROR::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_ROR::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ROR::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ROR::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ROR::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ROR::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ROR::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_ROR.h b/src/modules/IEC61131-3/BitwiseOperators/F_ROR.h new file mode 100644 index 000000000..3ba51f550 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_ROR.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ROR_H_ +#define _F_ROR_H_ + +#include +#include +#include + +class FORTE_F_ROR: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ROR) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &N() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ROR){ + }; + + template void calculateValue(){ + T oIn; + #ifdef FORTE_USE_64BIT_DATATYPES + CIEC_ULINT oN; + #else + CIEC_UDINT oN; + #endif //#ifdef FORTE_USE_64BIT_DATATYPES + oIn.saveAssign(IN()); + oN.saveAssign(N()); + OUT().saveAssign(ROR(oIn, oN)); + } + + virtual ~FORTE_F_ROR(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_SHL.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_SHL.cpp new file mode 100644 index 000000000..954614024 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_SHL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_SHL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SHL_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_SHL, g_nStringIdF_SHL) + +const CStringDictionary::TStringId FORTE_F_SHL::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdN}; + +const CStringDictionary::TStringId FORTE_F_SHL::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_SHL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SHL::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_SHL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SHL::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SHL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SHL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SHL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_SHL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SHL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + void FORTE_F_SHL::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_SHL.h b/src/modules/IEC61131-3/BitwiseOperators/F_SHL.h new file mode 100644 index 000000000..8f29248db --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_SHL.h @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2011 -2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_SHL_H_ +#define _F_SHL_H_ + +#include +#include +#include + +class FORTE_F_SHL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SHL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &N() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SHL){ + }; + + template void calculateValue(){ + T oIn; + #ifdef FORTE_USE_64BIT_DATATYPES + CIEC_ULINT oN; + #else + CIEC_UDINT oN; + #endif //#ifdef FORTE_USE_64BIT_DATATYPES + oIn.saveAssign(IN()); + oN.saveAssign(N()); + OUT().saveAssign(SHL(oIn, oN)); + } + + virtual ~FORTE_F_SHL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_SHR.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_SHR.cpp new file mode 100644 index 000000000..89f77de33 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_SHR.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SHR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SHR_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_SHR, g_nStringIdF_SHR) + +const CStringDictionary::TStringId FORTE_F_SHR::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdN}; + +const CStringDictionary::TStringId FORTE_F_SHR::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_SHR::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SHR::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_SHR::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SHR::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SHR::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SHR::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SHR::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SHR::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SHR::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SHR::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_SHR.h b/src/modules/IEC61131-3/BitwiseOperators/F_SHR.h new file mode 100644 index 000000000..0bacf85d7 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_SHR.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SHR_H_ +#define _F_SHR_H_ + +#include +#include +#include + +class FORTE_F_SHR: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SHR) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &N() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SHR){ + }; + + template void calculateValue(){ + T oIn; + #ifdef FORTE_USE_64BIT_DATATYPES + CIEC_ULINT oN; + #else + CIEC_UDINT oN; + #endif //#ifdef FORTE_USE_64BIT_DATATYPES + oIn.saveAssign(IN()); + oN.saveAssign(N()); + OUT().saveAssign(SHR(oIn, oN)); + } + + virtual ~FORTE_F_SHR(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_XOR.cpp b/src/modules/IEC61131-3/BitwiseOperators/F_XOR.cpp new file mode 100644 index 000000000..0a03c6e01 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_XOR.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_XOR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_XOR_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_XOR, g_nStringIdF_XOR) + +const CStringDictionary::TStringId FORTE_F_XOR::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_XOR::scm_anDataInputTypeIds[] = {g_nStringIdANY_BIT, g_nStringIdANY_BIT}; + +const CStringDictionary::TStringId FORTE_F_XOR::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_XOR::scm_anDataOutputTypeIds[] = {g_nStringIdANY_BIT}; + +const TForteInt16 FORTE_F_XOR::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_XOR::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_XOR::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_XOR::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_XOR::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_XOR::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_XOR::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_XOR::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyBitFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/BitwiseOperators/F_XOR.h b/src/modules/IEC61131-3/BitwiseOperators/F_XOR.h new file mode 100644 index 000000000..20d829860 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/F_XOR.h @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_XOR_H_ +#define _F_XOR_H_ + +#include +#include + +class FORTE_F_XOR: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_XOR) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_BIT &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_BIT &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_XOR){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(XOR(oIn1, oIn2)); + } + + virtual ~FORTE_F_XOR(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/GEN_AND.cpp b/src/modules/IEC61131-3/BitwiseOperators/GEN_AND.cpp new file mode 100644 index 000000000..c9e8ecdd9 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/GEN_AND.cpp @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "GEN_AND.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_AND_gen.cpp" +#endif + +#include +#include +#include +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_AND, g_nStringIdGEN_AND) + +const CStringDictionary::TStringId GEN_AND::scm_anDataOutputNames[] = { + g_nStringIdOUT }; + +const CStringDictionary::TStringId GEN_AND::scm_anDataOutputTypeIds[] = { + g_nStringIdANY_BIT }; + +const TForteInt16 GEN_AND::scm_anEIWithIndexes[] = { 0 }; +const CStringDictionary::TStringId GEN_AND::scm_anEventInputNames[] = { + g_nStringIdREQ }; + +const TDataIOID GEN_AND::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 GEN_AND::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId GEN_AND::scm_anEventOutputNames[] = { + g_nStringIdCNF }; + +GEN_AND::GEN_AND(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0) { +} + +GEN_AND::~GEN_AND() { + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anEIWith; +} + +void GEN_AND::executeEvent(int pa_nEIID) { + switch (pa_nEIID) { + case scm_nEventREQID: + + anyBitFBHelper(OUT().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + +bool GEN_AND::configureFB(const char *pa_acConfigString) { + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert( + pa_acConfigString); + + const char *pcPos = strrchr(pa_acConfigString, '_'); + + if (0 != pcPos) { + pcPos++; + //we have an underscore and it is the first underscore after AND + m_nDInputs = static_cast(forte::core::util::strtoul(pcPos, 0, 10)); + DEVLOG_DEBUG("DIs: %d;\n", m_nDInputs); + } else { + return false; + } + + if (m_nDInputs < 2) { + + return false; + } + + //now the number of needed eventInputs and dataOutputs are available in the integer array + //create the eventInputs + if (m_nDInputs < CFunctionBlock::scm_nMaxInterfaceEvents) { + + //create the data inputs + m_anDataInputNames = new CStringDictionary::TStringId[m_nDInputs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[m_nDInputs]; + + char diNames[cg_nIdentifierLength] = { "IN" }; + + for (int di = 0; di < m_nDInputs; di = di + 1) { + +#ifdef WIN32 + _snprintf(&(diNames[2]), 5 - 2, "%i", di+1); +#else + snprintf(&(diNames[2]), 5 - 2, "%i", di + 1); +#endif + m_anDataInputNames[di] = CStringDictionary::getInstance().insert(diNames); + m_anDataInputTypeIds[di] = g_nStringIdANY_BIT; + } + + //now create the WITH constructs... + //the With-Indexes for the data variables + m_anEIWith = new TDataIOID[m_nDInputs + 1]; //for inputs + '255' separators at the list end + + //in-withs + for (int in_with = 0; in_with < m_nDInputs + 1; in_with = in_with + 1) { + if (in_with == m_nDInputs) { + //set end separator of with + m_anEIWith[in_with] = 255; + } else { + m_anEIWith[in_with] = static_cast(in_with); + } + } + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = + new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, m_anEIWith, + scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, + scm_anEOWithIndexes, static_cast(m_nDInputs), m_anDataInputNames, + m_anDataInputTypeIds, 1, scm_anDataOutputNames, + scm_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize( + pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, + pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize( + pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + return bRetVal; +} diff --git a/src/modules/IEC61131-3/BitwiseOperators/GEN_AND.h b/src/modules/IEC61131-3/BitwiseOperators/GEN_AND.h new file mode 100644 index 000000000..86efc0479 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/GEN_AND.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _GEN_AND_H_ +#define _GEN_AND_H_ + +#include +#include + +class GEN_AND: public CFunctionBlock { +DECLARE_GENERIC_FIRMWARE_FB(GEN_AND) + +private: + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + TDataIOID *m_anEIWith; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + //self-defined members + int m_nDInputs; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void executeEvent(int pa_nEIID); + + GEN_AND(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes); + virtual ~GEN_AND(); + +public: + + CStringDictionary::TStringId getFBTypeId(void) const { + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); + + template void calculateValue() { + T oIn, oOut; + + for (int nInputIndex = 0; nInputIndex < m_nDInputs; nInputIndex++) { + + oIn.saveAssign(*static_cast(getDI(nInputIndex))); + + if (0 == nInputIndex) { + OUT().saveAssign(oIn); + } else { + oOut.saveAssign(OUT()); + OUT().saveAssign(AND(oOut, oIn)); + } + } + } +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/GEN_OR.cpp b/src/modules/IEC61131-3/BitwiseOperators/GEN_OR.cpp new file mode 100644 index 000000000..5e1e78bee --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/GEN_OR.cpp @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "GEN_OR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_OR_gen.cpp" +#endif + +#include +#include +#include +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_OR, g_nStringIdGEN_OR) + +const CStringDictionary::TStringId GEN_OR::scm_anDataOutputNames[] = { + g_nStringIdOUT }; + +const CStringDictionary::TStringId GEN_OR::scm_anDataOutputTypeIds[] = { + g_nStringIdANY_BIT }; + +const TForteInt16 GEN_OR::scm_anEIWithIndexes[] = { 0 }; +const CStringDictionary::TStringId GEN_OR::scm_anEventInputNames[] = { + g_nStringIdREQ }; + +const TDataIOID GEN_OR::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 GEN_OR::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId GEN_OR::scm_anEventOutputNames[] = { + g_nStringIdCNF }; + +GEN_OR::GEN_OR(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0) { +} + +GEN_OR::~GEN_OR() { + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anEIWith; +} + +void GEN_OR::executeEvent(int pa_nEIID) { + switch (pa_nEIID) { + case scm_nEventREQID: + + anyBitFBHelper(OUT().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + +bool GEN_OR::configureFB(const char *pa_acConfigString) { + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert( + pa_acConfigString); + + const char *pcPos = strrchr(pa_acConfigString, '_'); + + if (0 != pcPos) { + pcPos++; + //we have an underscore and it is the first underscore after AND + m_nDInputs = static_cast(forte::core::util::strtoul(pcPos, 0, 10)); + DEVLOG_DEBUG("DIs: %d;\n", m_nDInputs); + } else { + return false; + } + + if (m_nDInputs < 2) { + + return false; + } + + //now the number of needed eventInputs and dataOutputs are available in the integer array + //create the eventInputs + if (m_nDInputs < CFunctionBlock::scm_nMaxInterfaceEvents) { + + //create the data inputs + m_anDataInputNames = new CStringDictionary::TStringId[m_nDInputs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[m_nDInputs]; + + char diNames[cg_nIdentifierLength] = { "IN" }; + + for (unsigned int di = 0; di < m_nDInputs; di = di + 1) { + +#ifdef WIN32 + _snprintf(&(diNames[2]), 5 - 2, "%i", di+1); +#else + snprintf(&(diNames[2]), 5 - 2, "%i", di + 1); +#endif + m_anDataInputNames[di] = CStringDictionary::getInstance().insert(diNames); + m_anDataInputTypeIds[di] = g_nStringIdANY_BIT; + } + + //now create the WITH constructs... + //the With-Indexes for the data variables + m_anEIWith = new TDataIOID[m_nDInputs + 1]; //for inputs + '255' separators at the list end + + //in-withs + for (unsigned int in_with = 0; in_with < m_nDInputs + 1; in_with = in_with + 1) { + if (in_with == m_nDInputs) { + //set end separator of with + m_anEIWith[in_with] = 255; + } else { + m_anEIWith[in_with] = static_cast(in_with); + } + } + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = + new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, m_anEIWith, + scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, + scm_anEOWithIndexes, static_cast(m_nDInputs), m_anDataInputNames, + m_anDataInputTypeIds, 1, scm_anDataOutputNames, + scm_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize( + pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, + pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize( + pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + return bRetVal; +} diff --git a/src/modules/IEC61131-3/BitwiseOperators/GEN_OR.h b/src/modules/IEC61131-3/BitwiseOperators/GEN_OR.h new file mode 100644 index 000000000..c29a1e8c0 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/GEN_OR.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _GEN_OR_H_ +#define _GEN_OR_H_ + +#include +#include + +class GEN_OR: public CFunctionBlock { +DECLARE_GENERIC_FIRMWARE_FB(GEN_OR) + +private: + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT &OUT() { + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + TDataIOID *m_anEIWith; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + //self-defined members + unsigned int m_nDInputs; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void executeEvent(int pa_nEIID); + + GEN_OR(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes); + virtual ~GEN_OR(); + +public: + + CStringDictionary::TStringId getFBTypeId(void) const { + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); + + template void calculateValue() { + T oIn, oOut; + + for (unsigned int nInputIndex = 0; nInputIndex < m_nDInputs; nInputIndex++) { + + oIn.saveAssign(*static_cast(getDI(nInputIndex))); + + if (0 == nInputIndex) { + OUT().saveAssign(oIn); + } else { + oOut.saveAssign(OUT()); + OUT().saveAssign(OR(oOut, oIn)); + } + } + } +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/BitwiseOperators/GEN_XOR.cpp b/src/modules/IEC61131-3/BitwiseOperators/GEN_XOR.cpp new file mode 100644 index 000000000..d949bdaa6 --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/GEN_XOR.cpp @@ -0,0 +1,137 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "GEN_XOR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_XOR_gen.cpp" +#endif + +#include +#include +#include +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_XOR, g_nStringIdGEN_XOR) + +const CStringDictionary::TStringId GEN_XOR::scm_anDataOutputNames[] = { + g_nStringIdOUT }; + +const CStringDictionary::TStringId GEN_XOR::scm_anDataOutputTypeIds[] = { + g_nStringIdANY_BIT }; + +const TForteInt16 GEN_XOR::scm_anEIWithIndexes[] = { 0 }; +const CStringDictionary::TStringId GEN_XOR::scm_anEventInputNames[] = { + g_nStringIdREQ }; + +const TDataIOID GEN_XOR::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 GEN_XOR::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId GEN_XOR::scm_anEventOutputNames[] = { + g_nStringIdCNF }; + +GEN_XOR::GEN_XOR(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0) { +} + +GEN_XOR::~GEN_XOR() { + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anEIWith; +} + +void GEN_XOR::executeEvent(int pa_nEIID) { + switch (pa_nEIID) { + case scm_nEventREQID: + + anyBitFBHelper(OUT().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + +bool GEN_XOR::configureFB(const char *pa_acConfigString) { + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert( + pa_acConfigString); + + const char *pcPos = strrchr(pa_acConfigString, '_'); + + if (0 != pcPos) { + pcPos++; + //we have an underscore and it is the first underscore after AND + m_nDInputs = static_cast(forte::core::util::strtoul(pcPos, 0, 10)); + DEVLOG_DEBUG("DIs: %d;\n", m_nDInputs); + } else { + return false; + } + + if (m_nDInputs < 2) { + + return false; + } + + //now the number of needed eventInputs and dataOutputs are available in the integer array + //create the eventInputs + if (m_nDInputs < CFunctionBlock::scm_nMaxInterfaceEvents) { + + //create the data inputs + m_anDataInputNames = new CStringDictionary::TStringId[m_nDInputs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[m_nDInputs]; + + char diNames[cg_nIdentifierLength] = { "IN" }; + + for (int di = 0; di < m_nDInputs; di = di + 1) { + +#ifdef WIN32 + _snprintf(&(diNames[2]), 5 - 2, "%i", di+1); +#else + snprintf(&(diNames[2]), 5 - 2, "%i", di + 1); +#endif + m_anDataInputNames[di] = CStringDictionary::getInstance().insert(diNames); + m_anDataInputTypeIds[di] = g_nStringIdANY_BIT; + } + + //now create the WITH constructs... + //the With-Indexes for the data variables + m_anEIWith = new TDataIOID[m_nDInputs + 1]; //for inputs + '255' separators at the list end + + //in-withs + for (int in_with = 0; in_with < m_nDInputs + 1; in_with = in_with + 1) { + if (in_with == m_nDInputs) { + //set end separator of with + m_anEIWith[in_with] = 255; + } else { + m_anEIWith[in_with] = static_cast(in_with); + } + } + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = + new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, m_anEIWith, + scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, + scm_anEOWithIndexes, static_cast(m_nDInputs), m_anDataInputNames, + m_anDataInputTypeIds, 1, scm_anDataOutputNames, + scm_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize( + pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, + pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize( + pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + return bRetVal; +} diff --git a/src/modules/IEC61131-3/BitwiseOperators/GEN_XOR.h b/src/modules/IEC61131-3/BitwiseOperators/GEN_XOR.h new file mode 100644 index 000000000..89643b49b --- /dev/null +++ b/src/modules/IEC61131-3/BitwiseOperators/GEN_XOR.h @@ -0,0 +1,114 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _GEN_XOR_H_ +#define _GEN_XOR_H_ + +#include +#include + +class GEN_XOR: public CFunctionBlock { +DECLARE_GENERIC_FIRMWARE_FB(GEN_XOR) + +private: + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_BIT & + OUT() { + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + TDataIOID *m_anEIWith; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + //self-defined members + int m_nDInputs; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void + executeEvent(int pa_nEIID); + + GEN_XOR(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes); + virtual + ~GEN_XOR(); + +public: + + CStringDictionary::TStringId getFBTypeId(void) const { + return m_nConfiguredFBTypeNameId; + } + + bool + configureFB(const char *pa_acConfigString); + + template + void calculateValue() { + T oIn; + + /* + * Implementation of XOR for BOOL data type + * ---------------------------------------- + * Classical interpretation of Exclusive OR: + * The output value of the gate is 'true' + * iff (if and only if) one of the boolean + * inputs is set to 'true'. + */ + if (CIEC_ANY::e_BOOL == OUT().getDataTypeID()) { + unsigned int nInputSet = 0; + for (int nInputIndex = 0; nInputIndex < m_nDInputs; nInputIndex++) { + oIn.saveAssign(*static_cast(getDI(nInputIndex))); + + nInputSet = oIn ? nInputSet + 1 : nInputSet; + } + + OUT().saveAssign(static_cast(nInputSet == 1)); + } + + /* + * Implementation of XOR for BYTE and WORD data types + * -------------------------------------------------- + * The function is Interpreted as a cascade of + * 2-Input XOR gates. This leads to a behaviour of an + * odd-parity checker. + */ + else { + T oOut; + + for (int nInputIndex = 0; nInputIndex < m_nDInputs; nInputIndex++) { + oIn.saveAssign(*static_cast(getDI(nInputIndex))); + + if (0 == nInputIndex) { + OUT().saveAssign(oIn); + } else { + oOut.saveAssign(OUT()); + OUT().saveAssign(XOR(oOut, oIn)); + } + } + } + } +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CMakeLists.txt b/src/modules/IEC61131-3/CMakeLists.txt new file mode 100644 index 000000000..c80857723 --- /dev/null +++ b/src/modules/IEC61131-3/CMakeLists.txt @@ -0,0 +1,28 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Alois Zoitl +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ + + +forte_add_module(IEC61131 "IEC61131-3 Function blocks") +############################################################################# +# IEC61131-3 FB +############################################################################# +forte_add_subdirectory(BistableElements) +forte_add_subdirectory(Counters) +forte_add_subdirectory(EdgeDetection) +forte_add_subdirectory(Timers) +forte_add_subdirectory(Conversion) +forte_add_subdirectory(Numerical) +forte_add_subdirectory(BitwiseOperators) +forte_add_subdirectory(Selection) +forte_add_subdirectory(Comparison) +forte_add_subdirectory(Arithmetic) +forte_add_subdirectory(CharacterString) \ No newline at end of file diff --git a/src/modules/IEC61131-3/CharacterString/CMakeLists.txt b/src/modules/IEC61131-3/CharacterString/CMakeLists.txt new file mode 100644 index 000000000..8dffe5771 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/CMakeLists.txt @@ -0,0 +1,25 @@ +#******************************************************************************* +# * Copyright (c) 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# CharacterString +############################################################################# +forte_add_sourcefile_hcpp(F_LEN) +forte_add_sourcefile_hcpp(F_LEFT) +forte_add_sourcefile_hcpp(F_RIGHT) +forte_add_sourcefile_hcpp(F_MID) +forte_add_sourcefile_hcpp(F_CONCAT) +forte_add_sourcefile_hcpp(F_INSERT) +forte_add_sourcefile_hcpp(F_DELETE) +forte_add_sourcefile_hcpp(F_REPLACE) +forte_add_sourcefile_hcpp(F_FIND) + +forte_add_sourcefile_hcpp(F_CONCAT_DATE_TOD) \ No newline at end of file diff --git a/src/modules/IEC61131-3/CharacterString/F_CONCAT.cpp b/src/modules/IEC61131-3/CharacterString/F_CONCAT.cpp new file mode 100644 index 000000000..4fc245ab1 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_CONCAT.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_CONCAT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_CONCAT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_CONCAT, g_nStringIdF_CONCAT) + +const CStringDictionary::TStringId FORTE_F_CONCAT::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_CONCAT::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_STRING}; + +const CStringDictionary::TStringId FORTE_F_CONCAT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_CONCAT::scm_anDataOutputTypeIds[] = {g_nStringIdANY_STRING}; + +const TForteInt16 FORTE_F_CONCAT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_CONCAT::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_CONCAT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_CONCAT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_CONCAT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_CONCAT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_CONCAT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_CONCAT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/CharacterString/F_CONCAT.h b/src/modules/IEC61131-3/CharacterString/F_CONCAT.h new file mode 100644 index 000000000..00d22bd87 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_CONCAT.h @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_CONCAT_H_ +#define _F_CONCAT_H_ + +#include +#include + +class FORTE_F_CONCAT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_CONCAT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_STRING &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_CONCAT){ + }; + + template void calculateValueString(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(CONCAT(oIn1,oIn2)); + } + + virtual ~FORTE_F_CONCAT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_CONCAT_DATE_TOD.cpp b/src/modules/IEC61131-3/CharacterString/F_CONCAT_DATE_TOD.cpp new file mode 100644 index 000000000..0e8e49d52 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_CONCAT_DATE_TOD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_CONCAT_DATE_TOD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_CONCAT_DATE_TOD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_CONCAT_DATE_TOD, g_nStringIdF_CONCAT_DATE_TOD) + +const CStringDictionary::TStringId FORTE_F_CONCAT_DATE_TOD::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_CONCAT_DATE_TOD::scm_anDataInputTypeIds[] = {g_nStringIdDATE, g_nStringIdTIME_OF_DAY}; + +const CStringDictionary::TStringId FORTE_F_CONCAT_DATE_TOD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_CONCAT_DATE_TOD::scm_anDataOutputTypeIds[] = {g_nStringIdDATE_AND_TIME}; + +const TForteInt16 FORTE_F_CONCAT_DATE_TOD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_CONCAT_DATE_TOD::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_CONCAT_DATE_TOD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_CONCAT_DATE_TOD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_CONCAT_DATE_TOD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_CONCAT_DATE_TOD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_CONCAT_DATE_TOD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_CONCAT_DATE_TOD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = CONCAT_DATE_TOD(IN1(), IN2()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/CharacterString/F_CONCAT_DATE_TOD.h b/src/modules/IEC61131-3/CharacterString/F_CONCAT_DATE_TOD.h new file mode 100644 index 000000000..868e5a77d --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_CONCAT_DATE_TOD.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_CONCAT_DATE_TOD_H_ +#define _F_CONCAT_DATE_TOD_H_ + +#include +#include +#include +#include + +class FORTE_F_CONCAT_DATE_TOD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_CONCAT_DATE_TOD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DATE &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME_OF_DAY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DATE_AND_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_CONCAT_DATE_TOD){ + }; + + virtual ~FORTE_F_CONCAT_DATE_TOD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_DELETE.cpp b/src/modules/IEC61131-3/CharacterString/F_DELETE.cpp new file mode 100644 index 000000000..bf53bfc2d --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_DELETE.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DELETE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DELETE_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_DELETE, g_nStringIdF_DELETE) + +const CStringDictionary::TStringId FORTE_F_DELETE::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdL, g_nStringIdP}; + +const CStringDictionary::TStringId FORTE_F_DELETE::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_INT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_DELETE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DELETE::scm_anDataOutputTypeIds[] = {g_nStringIdANY_STRING}; + +const TForteInt16 FORTE_F_DELETE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DELETE::scm_anEIWith[] = {0, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_F_DELETE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DELETE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DELETE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DELETE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DELETE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DELETE::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/CharacterString/F_DELETE.h b/src/modules/IEC61131-3/CharacterString/F_DELETE.h new file mode 100644 index 000000000..22336cb33 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_DELETE.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DELETE_H_ +#define _F_DELETE_H_ + +#include +#include +#include + +class FORTE_F_DELETE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DELETE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &L() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY_INT &P() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DELETE){ + }; + + template void calculateValueString(){ + T oIn1; + oIn1.saveAssign(IN()); + OUT().saveAssign(DELETE(oIn1,L(),P())); + } + + virtual ~FORTE_F_DELETE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_FIND.cpp b/src/modules/IEC61131-3/CharacterString/F_FIND.cpp new file mode 100644 index 000000000..fde8dbdbe --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_FIND.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_FIND.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_FIND_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_FIND, g_nStringIdF_FIND) + +const CStringDictionary::TStringId FORTE_F_FIND::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_FIND::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_STRING}; + +const CStringDictionary::TStringId FORTE_F_FIND::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_FIND::scm_anDataOutputTypeIds[] = {g_nStringIdANY_INT}; + +const TForteInt16 FORTE_F_FIND::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_FIND::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_FIND::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_FIND::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_FIND::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_FIND::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_FIND::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_FIND::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/CharacterString/F_FIND.h b/src/modules/IEC61131-3/CharacterString/F_FIND.h new file mode 100644 index 000000000..34af1cf73 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_FIND.h @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_FIND_H_ +#define _F_FIND_H_ + +#include +#include +#include + +class FORTE_F_FIND: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_FIND) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_STRING &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_FIND){ + }; + + template void calculateValueString(){ + T oIn1; + oIn1.saveAssign(IN1()); + T oIn2; + oIn2.saveAssign(IN2()); + OUT().saveAssign(FIND(oIn1,oIn2)); + } + + virtual ~FORTE_F_FIND(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_INSERT.cpp b/src/modules/IEC61131-3/CharacterString/F_INSERT.cpp new file mode 100644 index 000000000..b375f865d --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_INSERT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INSERT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INSERT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_INSERT, g_nStringIdF_INSERT) + +const CStringDictionary::TStringId FORTE_F_INSERT::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2, g_nStringIdP}; + +const CStringDictionary::TStringId FORTE_F_INSERT::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_STRING, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_INSERT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INSERT::scm_anDataOutputTypeIds[] = {g_nStringIdANY_STRING}; + +const TForteInt16 FORTE_F_INSERT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INSERT::scm_anEIWith[] = {0, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_F_INSERT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INSERT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INSERT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INSERT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INSERT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INSERT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + diff --git a/src/modules/IEC61131-3/CharacterString/F_INSERT.h b/src/modules/IEC61131-3/CharacterString/F_INSERT.h new file mode 100644 index 000000000..1e31f4064 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_INSERT.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INSERT_H_ +#define _F_INSERT_H_ + +#include +#include +#include + +class FORTE_F_INSERT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INSERT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_STRING &IN2() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY_INT &P() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INSERT){ + }; + + template void calculateValueString(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(INSERT(oIn1,oIn2,P())); + } + + virtual ~FORTE_F_INSERT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_LEFT.cpp b/src/modules/IEC61131-3/CharacterString/F_LEFT.cpp new file mode 100644 index 000000000..3ce5ff4bc --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_LEFT.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LEFT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LEFT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_LEFT, g_nStringIdF_LEFT) + +const CStringDictionary::TStringId FORTE_F_LEFT::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdL}; + +const CStringDictionary::TStringId FORTE_F_LEFT::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_LEFT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LEFT::scm_anDataOutputTypeIds[] = {g_nStringIdANY_STRING}; + +const TForteInt16 FORTE_F_LEFT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LEFT::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_LEFT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LEFT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LEFT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LEFT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LEFT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LEFT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/CharacterString/F_LEFT.h b/src/modules/IEC61131-3/CharacterString/F_LEFT.h new file mode 100644 index 000000000..70f40c2db --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_LEFT.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LEFT_H_ +#define _F_LEFT_H_ + +#include +#include +#include + +class FORTE_F_LEFT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LEFT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &L() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LEFT){ + }; + + template void calculateValueString(){ + T &roIn(static_cast(IN())); + OUT().saveAssign(LEFT(roIn,L())); + } + + virtual ~FORTE_F_LEFT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_LEN.cpp b/src/modules/IEC61131-3/CharacterString/F_LEN.cpp new file mode 100644 index 000000000..7a582fb80 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_LEN.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LEN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LEN_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_LEN, g_nStringIdF_LEN) + +const CStringDictionary::TStringId FORTE_F_LEN::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LEN::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING}; + +const CStringDictionary::TStringId FORTE_F_LEN::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LEN::scm_anDataOutputTypeIds[] = {g_nStringIdANY_INT}; + +const TForteInt16 FORTE_F_LEN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LEN::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LEN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LEN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LEN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LEN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LEN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LEN::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/CharacterString/F_LEN.h b/src/modules/IEC61131-3/CharacterString/F_LEN.h new file mode 100644 index 000000000..5ae1daa93 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_LEN.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LEN_H_ +#define _F_LEN_H_ + +#include +#include +#include + +class FORTE_F_LEN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LEN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LEN){ + }; + + template void calculateValue(){ + OUT().saveAssign(CIEC_UDINT(0)); + } + + template void calculateValueString(){ + T &roIn(static_cast(IN())); + OUT().saveAssign(LEN(roIn)); + } + + virtual ~FORTE_F_LEN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_MID.cpp b/src/modules/IEC61131-3/CharacterString/F_MID.cpp new file mode 100644 index 000000000..5627bcbb6 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_MID.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_MID.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MID_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_MID, g_nStringIdF_MID) + +const CStringDictionary::TStringId FORTE_F_MID::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdL, g_nStringIdP}; + +const CStringDictionary::TStringId FORTE_F_MID::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_INT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_MID::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MID::scm_anDataOutputTypeIds[] = {g_nStringIdANY_STRING}; + +const TForteInt16 FORTE_F_MID::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MID::scm_anEIWith[] = {0, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_F_MID::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MID::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MID::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_MID::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MID::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MID::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/CharacterString/F_MID.h b/src/modules/IEC61131-3/CharacterString/F_MID.h new file mode 100644 index 000000000..b6dbc7716 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_MID.h @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_MID_H_ +#define _F_MID_H_ + +#include +#include +#include + +class FORTE_F_MID: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MID) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &L() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY_INT &P() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MID){ + }; + + template void calculateValueString(){ + T &roIn(static_cast(IN())); + OUT().saveAssign(MID(roIn,L(),P())); + } + + virtual ~FORTE_F_MID(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_REPLACE.cpp b/src/modules/IEC61131-3/CharacterString/F_REPLACE.cpp new file mode 100644 index 000000000..e4e72ab0a --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_REPLACE.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REPLACE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REPLACE_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_REPLACE, g_nStringIdF_REPLACE) + +const CStringDictionary::TStringId FORTE_F_REPLACE::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2, g_nStringIdL, g_nStringIdP}; + +const CStringDictionary::TStringId FORTE_F_REPLACE::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_STRING, g_nStringIdANY_INT, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_REPLACE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REPLACE::scm_anDataOutputTypeIds[] = {g_nStringIdANY_STRING}; + +const TForteInt16 FORTE_F_REPLACE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REPLACE::scm_anEIWith[] = {0, 1, 2, 3, 255}; +const CStringDictionary::TStringId FORTE_F_REPLACE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REPLACE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REPLACE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REPLACE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REPLACE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REPLACE::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/CharacterString/F_REPLACE.h b/src/modules/IEC61131-3/CharacterString/F_REPLACE.h new file mode 100644 index 000000000..4d2d0f8c7 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_REPLACE.h @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REPLACE_H_ +#define _F_REPLACE_H_ + +#include +#include +#include + +class FORTE_F_REPLACE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REPLACE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_STRING &IN2() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY_INT &L() { + return *static_cast(getDI(2)); + }; + + CIEC_ANY_INT &P() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 4, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REPLACE){ + }; + + template void calculateValueString(){ + T oIn1; + oIn1.saveAssign(IN1()); + T oIn2; + oIn2.saveAssign(IN2()); + OUT().saveAssign(REPLACE(oIn1,oIn2,L(),P())); + } + + virtual ~FORTE_F_REPLACE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/CharacterString/F_RIGHT.cpp b/src/modules/IEC61131-3/CharacterString/F_RIGHT.cpp new file mode 100644 index 000000000..03e2becf2 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_RIGHT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_RIGHT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_RIGHT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_RIGHT, g_nStringIdF_RIGHT) + +const CStringDictionary::TStringId FORTE_F_RIGHT::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdL}; + +const CStringDictionary::TStringId FORTE_F_RIGHT::scm_anDataInputTypeIds[] = {g_nStringIdANY_STRING, g_nStringIdANY_INT}; + +const CStringDictionary::TStringId FORTE_F_RIGHT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_RIGHT::scm_anDataOutputTypeIds[] = {g_nStringIdANY_STRING}; + +const TForteInt16 FORTE_F_RIGHT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_RIGHT::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_RIGHT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_RIGHT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_RIGHT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_RIGHT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_RIGHT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_RIGHT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyStringFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + diff --git a/src/modules/IEC61131-3/CharacterString/F_RIGHT.h b/src/modules/IEC61131-3/CharacterString/F_RIGHT.h new file mode 100644 index 000000000..685b5a2d6 --- /dev/null +++ b/src/modules/IEC61131-3/CharacterString/F_RIGHT.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_RIGHT_H_ +#define _F_RIGHT_H_ + +#include +#include +#include + +class FORTE_F_RIGHT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_RIGHT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_STRING &IN() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_INT &L() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_RIGHT){ + }; + + template void calculateValueString(){ + T &roIn(static_cast(IN())); + OUT().saveAssign(RIGHT(roIn,L())); + } + + virtual ~FORTE_F_RIGHT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Comparison/CMakeLists.txt b/src/modules/IEC61131-3/Comparison/CMakeLists.txt new file mode 100644 index 000000000..76261d1cc --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/CMakeLists.txt @@ -0,0 +1,23 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Alois Zoitl +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Comparison +############################################################################# +forte_add_sourcefile_hcpp(F_GT) +forte_add_sourcefile_hcpp(F_EQ) +forte_add_sourcefile_hcpp(F_GE) +forte_add_sourcefile_hcpp(F_LE) +forte_add_sourcefile_hcpp(F_LT) +forte_add_sourcefile_hcpp(F_NE) + + +#add_subdirectory(tests) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Comparison/F_EQ.cpp b/src/modules/IEC61131-3/Comparison/F_EQ.cpp new file mode 100644 index 000000000..a60837d91 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_EQ.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_EQ.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_EQ_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_EQ, g_nStringIdF_EQ) + +const CStringDictionary::TStringId FORTE_F_EQ::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_EQ::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_EQ::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_EQ::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_EQ::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_EQ::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_EQ::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_EQ::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_EQ::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_EQ::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_EQ::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_EQ::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Comparison/F_EQ.h b/src/modules/IEC61131-3/Comparison/F_EQ.h new file mode 100644 index 000000000..d0b76c1be --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_EQ.h @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_EQ_H_ +#define _F_EQ_H_ + +#include +#include +#include + +class FORTE_F_EQ : public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_EQ) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_ANY_ELEMENTARY &IN2(){ + return *static_cast(getDI(1)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT(){ + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0) + ; + + void executeEvent(int pa_nEIID); + + public: + FUNCTION_BLOCK_CTOR(FORTE_F_EQ){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + + OUT().saveAssign(EQ(oIn1, oIn2)); + } + + template void calculateValueString() { + calculateValue(); + } + + virtual ~FORTE_F_EQ(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/IEC61131-3/Comparison/F_GE.cpp b/src/modules/IEC61131-3/Comparison/F_GE.cpp new file mode 100644 index 000000000..73f009cb3 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_GE.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_GE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_GE_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_GE, g_nStringIdF_GE) + +const CStringDictionary::TStringId FORTE_F_GE::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_GE::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_GE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_GE::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_GE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_GE::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_GE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_GE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_GE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_GE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_GE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_GE::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Comparison/F_GE.h b/src/modules/IEC61131-3/Comparison/F_GE.h new file mode 100644 index 000000000..0e0833a53 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_GE.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_GE_H_ +#define _F_GE_H_ + +#include +#include +#include + +class FORTE_F_GE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_GE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_ELEMENTARY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_GE){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(GE(oIn1, oIn2)); + } + + template void calculateValueString() { + //TODO fill this function + DEVLOG_WARNING("STRING and WSTRING currently not supported"); + } + + virtual ~FORTE_F_GE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Comparison/F_GT.cpp b/src/modules/IEC61131-3/Comparison/F_GT.cpp new file mode 100644 index 000000000..35561972c --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_GT.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_GT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_GT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_GT, g_nStringIdF_GT) + +const CStringDictionary::TStringId FORTE_F_GT::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_GT::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_GT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_GT::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_GT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_GT::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_GT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_GT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_GT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_GT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_GT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_GT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + +template<> +void FORTE_F_GT::calculateValue(){ + //TODO fill this function +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +template<> +void FORTE_F_GT::calculateValue(){ + //TODO fill this function +} +#endif + diff --git a/src/modules/IEC61131-3/Comparison/F_GT.h b/src/modules/IEC61131-3/Comparison/F_GT.h new file mode 100644 index 000000000..5e4d792e1 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_GT.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Matthias Plasch, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_GT_H_ +#define _F_GT_H_ + +#include +#include +#include + +class FORTE_F_GT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_GT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_ELEMENTARY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + + + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_GT){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + + OUT().saveAssign(GT(oIn1, oIn2)); + } + + template void calculateValueString(){ + //TODO fill this function + DEVLOG_WARNING("STRING and WSTRING currently not supported"); + } + + virtual ~FORTE_F_GT(){}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Comparison/F_LE.cpp b/src/modules/IEC61131-3/Comparison/F_LE.cpp new file mode 100644 index 000000000..e5b7ec648 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_LE.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LE_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_LE, g_nStringIdF_LE) + +const CStringDictionary::TStringId FORTE_F_LE::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_LE::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_LE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LE::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_LE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LE::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_LE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LE::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Comparison/F_LE.h b/src/modules/IEC61131-3/Comparison/F_LE.h new file mode 100644 index 000000000..e9356876b --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_LE.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LE_H_ +#define _F_LE_H_ + +#include +#include +#include + +class FORTE_F_LE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_ELEMENTARY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LE){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(LE(oIn1, oIn2)); + } + + template void calculateValueString() { + //TODO fill this function + DEVLOG_WARNING("STRING and WSTRING currently not supported"); + } + virtual ~FORTE_F_LE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Comparison/F_LT.cpp b/src/modules/IEC61131-3/Comparison/F_LT.cpp new file mode 100644 index 000000000..a4d6a5dcf --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_LT.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_LT, g_nStringIdF_LT) + +const CStringDictionary::TStringId FORTE_F_LT::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_LT::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_LT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LT::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_LT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LT::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_LT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Comparison/F_LT.h b/src/modules/IEC61131-3/Comparison/F_LT.h new file mode 100644 index 000000000..558c09913 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_LT.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LT_H_ +#define _F_LT_H_ + +#include +#include +#include + +class FORTE_F_LT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_ELEMENTARY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LT){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(LT(oIn1, oIn2)); + } + + template void calculateValueString() { + //TODO fill this function + DEVLOG_WARNING("STRING and WSTRING currently not supported"); + } + + virtual ~FORTE_F_LT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Comparison/F_NE.cpp b/src/modules/IEC61131-3/Comparison/F_NE.cpp new file mode 100644 index 000000000..18a453278 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_NE.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_NE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_NE_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_NE, g_nStringIdF_NE) + +const CStringDictionary::TStringId FORTE_F_NE::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_NE::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_NE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_NE::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_NE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_NE::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_NE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_NE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_NE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_NE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_NE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_NE::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Comparison/F_NE.h b/src/modules/IEC61131-3/Comparison/F_NE.h new file mode 100644 index 000000000..602c14235 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/F_NE.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_NE_H_ +#define _F_NE_H_ + +#include +#include +#include + +class FORTE_F_NE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_NE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_ELEMENTARY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_NE){ + }; + + template void calculateValue(){ + T oIn1; + T oIn2; + oIn1.saveAssign(IN1()); + oIn2.saveAssign(IN2()); + OUT().saveAssign(NE(oIn1, oIn2)); + } + + template void calculateValueString() { + calculateValue();//TODO fill this function + } + + virtual ~FORTE_F_NE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Comparison/tests/CMakeLists.txt b/src/modules/IEC61131-3/Comparison/tests/CMakeLists.txt new file mode 100644 index 000000000..297032c5d --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/tests/CMakeLists.txt @@ -0,0 +1,23 @@ +#******************************************************************************* +# * Copyright (c) 2013 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Tests for the standard Event FBs +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +SET(SOURCE_GROUP ${SOURCE_GROUP}\\events) + + +if(FORTE_FUNCTIONBLOCK_TESTS) + +forte_add_sourcefile_hcpp(F_EQ_TIME_tester F_GT_TIME_tester) + +endif(FORTE_FUNCTIONBLOCK_TESTS) diff --git a/src/modules/IEC61131-3/Comparison/tests/F_EQ_TIME_tester.cpp b/src/modules/IEC61131-3/Comparison/tests/F_EQ_TIME_tester.cpp new file mode 100644 index 000000000..997352424 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/tests/F_EQ_TIME_tester.cpp @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2013 - 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_EQ_TIME_gen.cpp" +#endif + +DEFINE_FB_TESTER(F_EQ_TIME_tester, g_nStringIdF_GT) + +F_EQ_TIME_tester::F_EQ_TIME_tester(CResource *m_poTestResource) : + CFBTester(m_oTestee, m_poTestResource), + m_oTestee(0, m_poTestResource), + m_poOut_EO_Conn(m_oTestee, g_nStringIdCNF), + m_oIn_IN1_Conn(m_oTestee, g_nStringIdIN1, &m_oIN1), + m_oIn_IN2_Conn(m_oTestee, g_nStringIdIN2, &m_oIN2), + m_oOut_OUT_Conn(m_oTestee, g_nStringIdOUT, &m_oOut_OUT){ + m_oTestee.changeFBExecutionState(cg_nMGM_CMD_Start); +} + +void F_EQ_TIME_tester::executeAllTests(){ + evaluateTestResult(testCase_Equal(), "Equal"); + evaluateTestResult(testCase_Larger(), "Larger"); + evaluateTestResult(testCase_Smaller(), "Smaller"); +} + +bool F_EQ_TIME_tester::testCase_Equal(){ + bool bResult = true; + + //Send event + triggerEvent(0); + + //Test correct order of outgoing events + if(pullFirstChainEventID() != 0) + bResult = false; + + //Test if event chain is empty + if(!eventChainEmpty()) + bResult = false; + + //verify data output as both are zero the value value should be true + if(m_oOut_OUT != true) + bResult = false; + + m_oIN1.fromString("T#500ms"); + m_oIN2.fromString("T#500ms"); + + triggerEvent(0); + + if(m_oOut_OUT != true) + bResult = false; + + return bResult; +} + +bool F_EQ_TIME_tester::testCase_Larger(){ + bool bResult = true; + + m_oIN1.fromString("T#800ms"); + m_oIN2.fromString("T#300ms"); + + triggerEvent(0); + + if(m_oOut_OUT != false) + bResult = false; + + return bResult; +} + +bool F_EQ_TIME_tester::testCase_Smaller(){ + bool bResult = true; + + m_oIN1.fromString("T#150ms"); + m_oIN2.fromString("T#1s"); + + triggerEvent(0); + + if(m_oOut_OUT != false) + bResult = false; + + return bResult; +} diff --git a/src/modules/IEC61131-3/Comparison/tests/F_EQ_TIME_tester.h b/src/modules/IEC61131-3/Comparison/tests/F_EQ_TIME_tester.h new file mode 100644 index 000000000..228bb8d2a --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/tests/F_EQ_TIME_tester.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SR_TESTER_H_ +#define _E_SR_TESTER_H_ + +#include "fbtester.h" +#include +#include "../F_EQ.h" + +/***********************************************************************************/ +/***********************************************************************************/ + +class F_EQ_TIME_tester : public CFBTester{ + DECLARE_FB_TESTER(F_EQ_TIME_tester); + + public: + F_EQ_TIME_tester(CResource *m_poTestResource); + + private: + virtual void executeAllTests(); + + bool testCase_Equal(); + bool testCase_Larger(); + bool testCase_Smaller(); + + FORTE_F_EQ m_oTestee; + + CFBTestEOConn m_poOut_EO_Conn; + + CIEC_TIME m_oIN1; + CFBTestDIConn m_oIn_IN1_Conn; + CIEC_TIME m_oIN2; + CFBTestDIConn m_oIn_IN2_Conn; + CIEC_BOOL m_oOut_OUT; //DATA OUTPUT + CFBTestDOConn m_oOut_OUT_Conn; //DATA OUTPUT + +}; + +/***********************************************************************************/ +/***********************************************************************************/ + +#endif /* _E_SR_TESTER_H_ */ diff --git a/src/modules/IEC61131-3/Comparison/tests/F_GT_TIME_tester.cpp b/src/modules/IEC61131-3/Comparison/tests/F_GT_TIME_tester.cpp new file mode 100644 index 000000000..168980af1 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/tests/F_GT_TIME_tester.cpp @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2013 - 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_GT_TIME_gen.cpp" +#endif + +DEFINE_FB_TESTER(F_GT_TIME_tester, g_nStringIdF_GT) + +F_GT_TIME_tester::F_GT_TIME_tester(CResource *m_poTestResource) : + CFBTester(m_oTestee, m_poTestResource), + m_oTestee(0, m_poTestResource), + m_poOut_EO_Conn(m_oTestee, g_nStringIdCNF), + m_oIn_IN1_Conn(m_oTestee, g_nStringIdIN1, &m_oIN1), + m_oIn_IN2_Conn(m_oTestee, g_nStringIdIN2, &m_oIN2), + m_oOut_OUT_Conn(m_oTestee, g_nStringIdOUT, &m_oOut_OUT){ + m_oTestee.changeFBExecutionState(cg_nMGM_CMD_Start); +} + +void F_GT_TIME_tester::executeAllTests(){ + evaluateTestResult(testCase_GTual(), "Equal"); + evaluateTestResult(testCase_Larger(), "Larger"); + evaluateTestResult(testCase_Smaller(), "Smaller"); +} + +bool F_GT_TIME_tester::testCase_GTual(){ + bool bResult = true; + + //Send event + triggerEvent(0); + + //Test correct order of outgoing events + if(pullFirstChainEventID() != 0) + bResult = false; + + //Test if event chain is empty + if(!eventChainEmpty()) + bResult = false; + + //verify data output as both are zero the value value should be true + if(m_oOut_OUT != false) + bResult = false; + + m_oIN1.fromString("T#500ms"); + m_oIN2.fromString("T#500ms"); + + triggerEvent(0); + + if(m_oOut_OUT != false) + bResult = false; + + return bResult; +} + +bool F_GT_TIME_tester::testCase_Larger(){ + bool bResult = true; + + m_oIN1.fromString("T#800ms"); + m_oIN2.fromString("T#300ms"); + + triggerEvent(0); + + if(m_oOut_OUT != true) + bResult = false; + + return bResult; +} + +bool F_GT_TIME_tester::testCase_Smaller(){ + bool bResult = true; + + m_oIN1.fromString("T#150ms"); + m_oIN2.fromString("T#1s"); + + triggerEvent(0); + + if(m_oOut_OUT != false) + bResult = false; + + return bResult; +} diff --git a/src/modules/IEC61131-3/Comparison/tests/F_GT_TIME_tester.h b/src/modules/IEC61131-3/Comparison/tests/F_GT_TIME_tester.h new file mode 100644 index 000000000..ae80a5074 --- /dev/null +++ b/src/modules/IEC61131-3/Comparison/tests/F_GT_TIME_tester.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SR_TESTER_H_ +#define _E_SR_TESTER_H_ + +#include "fbtester.h" +#include +#include "../F_GT.h" + +/***********************************************************************************/ +/***********************************************************************************/ + +class F_GT_TIME_tester : public CFBTester{ + DECLARE_FB_TESTER(F_GT_TIME_tester); + + public: + F_GT_TIME_tester(CResource *m_poTestResource); + + private: + virtual void executeAllTests(); + + bool testCase_GTual(); + bool testCase_Larger(); + bool testCase_Smaller(); + + FORTE_F_GT m_oTestee; + + CFBTestEOConn m_poOut_EO_Conn; + + CIEC_TIME m_oIN1; + CFBTestDIConn m_oIn_IN1_Conn; + CIEC_TIME m_oIN2; + CFBTestDIConn m_oIn_IN2_Conn; + CIEC_BOOL m_oOut_OUT; //DATA OUTPUT + CFBTestDOConn m_oOut_OUT_Conn; //DATA OUTPUT + +}; + +/***********************************************************************************/ +/***********************************************************************************/ + +#endif /* _E_SR_TESTER_H_ */ diff --git a/src/modules/IEC61131-3/Conversion/BCD/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/BCD/CMakeLists.txt new file mode 100644 index 000000000..4f4e0fd5e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/CMakeLists.txt @@ -0,0 +1,28 @@ +#******************************************************************************* +# * Copyright (c) 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Conversion when bit-string variable contains data encoded in BCD +# x_BCD_TO_xx +# xx_TO_BCD_x +############################################################################# +forte_add_sourcefile_hcpp(F_BYTE_BCD_TO_USINT) +forte_add_sourcefile_hcpp(F_WORD_BCD_TO_UINT) +forte_add_sourcefile_hcpp(F_DWORD_BCD_TO_UDINT) + +forte_add_sourcefile_hcpp(F_USINT_TO_BCD_BYTE) +forte_add_sourcefile_hcpp(F_UINT_TO_BCD_WORD) +forte_add_sourcefile_hcpp(F_UDINT_TO_BCD_DWORD) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_LWORD_BCD_TO_ULINT) + forte_add_sourcefile_hcpp(F_ULINT_TO_BCD_LWORD) +endif(FORTE_USE_64BIT_DATATYPES) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_BYTE_BCD_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_BYTE_BCD_TO_USINT.cpp new file mode 100644 index 000000000..a6d587a40 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_BYTE_BCD_TO_USINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_BCD_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_BCD_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_BCD_TO_USINT, g_nStringIdF_BYTE_BCD_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_BCD_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_BCD_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_BCD_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_BCD_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_BYTE_BCD_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_BCD_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_BCD_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_BCD_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_BCD_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_BCD_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_BCD_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_BCD_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_BCD_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_BYTE_BCD_TO_USINT.h b/src/modules/IEC61131-3/Conversion/BCD/F_BYTE_BCD_TO_USINT.h new file mode 100644 index 000000000..43944c26d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_BYTE_BCD_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_BCD_TO_USINT_H_ +#define _F_BYTE_BCD_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_BCD_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_BCD_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_BCD_TO_USINT){ + }; + + virtual ~FORTE_F_BYTE_BCD_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_DWORD_BCD_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_DWORD_BCD_TO_UDINT.cpp new file mode 100644 index 000000000..560947290 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_DWORD_BCD_TO_UDINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_BCD_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_BCD_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_BCD_TO_UDINT, g_nStringIdF_DWORD_BCD_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_BCD_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_BCD_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_BCD_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_BCD_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_DWORD_BCD_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_BCD_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_BCD_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_BCD_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_BCD_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_BCD_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_BCD_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_BCD_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_BCD_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_DWORD_BCD_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/BCD/F_DWORD_BCD_TO_UDINT.h new file mode 100644 index 000000000..94c24ffc0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_DWORD_BCD_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_BCD_TO_UDINT_H_ +#define _F_DWORD_BCD_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_BCD_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_BCD_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_BCD_TO_UDINT){ + }; + + virtual ~FORTE_F_DWORD_BCD_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_LWORD_BCD_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_LWORD_BCD_TO_ULINT.cpp new file mode 100644 index 000000000..818de5b22 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_LWORD_BCD_TO_ULINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_BCD_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_BCD_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_BCD_TO_ULINT, g_nStringIdF_LWORD_BCD_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_BCD_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_BCD_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_BCD_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_BCD_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_LWORD_BCD_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_BCD_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_BCD_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_BCD_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_BCD_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_BCD_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_BCD_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_BCD_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_BCD_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_LWORD_BCD_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/BCD/F_LWORD_BCD_TO_ULINT.h new file mode 100644 index 000000000..c400de2d5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_LWORD_BCD_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_BCD_TO_ULINT_H_ +#define _F_LWORD_BCD_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_BCD_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_BCD_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_BCD_TO_ULINT){ + }; + + virtual ~FORTE_F_LWORD_BCD_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_UDINT_TO_BCD_DWORD.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_UDINT_TO_BCD_DWORD.cpp new file mode 100644 index 000000000..564ab6e2b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_UDINT_TO_BCD_DWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_BCD_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_BCD_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_BCD_DWORD, g_nStringIdF_UDINT_TO_BCD_DWORD) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BCD_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BCD_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BCD_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BCD_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_UDINT_TO_BCD_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_BCD_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BCD_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_BCD_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_BCD_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BCD_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_BCD_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_BCD_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_BCD_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_UDINT_TO_BCD_DWORD.h b/src/modules/IEC61131-3/Conversion/BCD/F_UDINT_TO_BCD_DWORD.h new file mode 100644 index 000000000..23fbd02cf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_UDINT_TO_BCD_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_BCD_DWORD_H_ +#define _F_UDINT_TO_BCD_DWORD_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_BCD_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_BCD_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_BCD_DWORD){ + }; + + virtual ~FORTE_F_UDINT_TO_BCD_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_UINT_TO_BCD_WORD.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_UINT_TO_BCD_WORD.cpp new file mode 100644 index 000000000..ae2d6de20 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_UINT_TO_BCD_WORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UINT_TO_BCD_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_BCD_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_BCD_WORD, g_nStringIdF_UINT_TO_BCD_WORD) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BCD_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BCD_WORD::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BCD_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BCD_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_UINT_TO_BCD_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_BCD_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_BCD_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_BCD_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_BCD_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_BCD_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_BCD_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_BCD_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_BCD_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_UINT_TO_BCD_WORD.h b/src/modules/IEC61131-3/Conversion/BCD/F_UINT_TO_BCD_WORD.h new file mode 100644 index 000000000..85aab6b50 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_UINT_TO_BCD_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UINT_TO_BCD_WORD_H_ +#define _F_UINT_TO_BCD_WORD_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_BCD_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_BCD_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_BCD_WORD){ + }; + + virtual ~FORTE_F_UINT_TO_BCD_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_ULINT_TO_BCD_LWORD.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_ULINT_TO_BCD_LWORD.cpp new file mode 100644 index 000000000..92123d9cf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_ULINT_TO_BCD_LWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ULINT_TO_BCD_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_BCD_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_BCD_LWORD, g_nStringIdF_ULINT_TO_BCD_LWORD) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BCD_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BCD_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BCD_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BCD_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_ULINT_TO_BCD_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_BCD_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BCD_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_BCD_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_BCD_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BCD_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_BCD_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_BCD_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_BCD_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_ULINT_TO_BCD_LWORD.h b/src/modules/IEC61131-3/Conversion/BCD/F_ULINT_TO_BCD_LWORD.h new file mode 100644 index 000000000..44d8c8d84 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_ULINT_TO_BCD_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ULINT_TO_BCD_LWORD_H_ +#define _F_ULINT_TO_BCD_LWORD_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_BCD_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_BCD_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_BCD_LWORD){ + }; + + virtual ~FORTE_F_ULINT_TO_BCD_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_USINT_TO_BCD_BYTE.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_USINT_TO_BCD_BYTE.cpp new file mode 100644 index 000000000..f0a6c1306 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_USINT_TO_BCD_BYTE.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_USINT_TO_BCD_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_BCD_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_BCD_BYTE, g_nStringIdF_USINT_TO_BCD_BYTE) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BCD_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BCD_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BCD_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BCD_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_USINT_TO_BCD_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_BCD_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_BCD_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_BCD_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_BCD_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_BCD_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_BCD_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_BCD_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_BCD_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_USINT_TO_BCD_BYTE.h b/src/modules/IEC61131-3/Conversion/BCD/F_USINT_TO_BCD_BYTE.h new file mode 100644 index 000000000..7e01e3a9b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_USINT_TO_BCD_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_USINT_TO_BCD_BYTE_H_ +#define _F_USINT_TO_BCD_BYTE_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_BCD_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_BCD_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_BCD_BYTE){ + }; + + virtual ~FORTE_F_USINT_TO_BCD_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_WORD_BCD_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/BCD/F_WORD_BCD_TO_UINT.cpp new file mode 100644 index 000000000..0b62af7d7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_WORD_BCD_TO_UINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WORD_BCD_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_BCD_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_BCD_TO_UINT, g_nStringIdF_WORD_BCD_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_WORD_BCD_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_BCD_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_BCD_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_BCD_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_WORD_BCD_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_BCD_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_BCD_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_BCD_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_BCD_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_BCD_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_BCD_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_BCD_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_BCD_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BCD/F_WORD_BCD_TO_UINT.h b/src/modules/IEC61131-3/Conversion/BCD/F_WORD_BCD_TO_UINT.h new file mode 100644 index 000000000..d1914cd2e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BCD/F_WORD_BCD_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WORD_BCD_TO_UINT_H_ +#define _F_WORD_BCD_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_BCD_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_BCD_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_BCD_TO_UINT){ + }; + + virtual ~FORTE_F_WORD_BCD_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/BOOL/CMakeLists.txt new file mode 100644 index 000000000..09bd28916 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# BOOL_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_BOOL_TO_BYTE) +forte_add_sourcefile_hcpp(F_BOOL_TO_DINT) +forte_add_sourcefile_hcpp(F_BOOL_TO_DWORD) +forte_add_sourcefile_hcpp(F_BOOL_TO_INT) +forte_add_sourcefile_hcpp(F_BOOL_TO_SINT) +forte_add_sourcefile_hcpp(F_BOOL_TO_UDINT) +forte_add_sourcefile_hcpp(F_BOOL_TO_UINT) +forte_add_sourcefile_hcpp(F_BOOL_TO_USINT) +forte_add_sourcefile_hcpp(F_BOOL_TO_WORD) +forte_add_sourcefile_hcpp(F_BOOL_TO_STRING) +forte_add_sourcefile_hcpp(F_BOOL_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_BOOL_TO_LINT) + forte_add_sourcefile_hcpp(F_BOOL_TO_LWORD) + forte_add_sourcefile_hcpp(F_BOOL_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_BOOL_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_BOOL_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_BOOL_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_BYTE.cpp new file mode 100644 index 000000000..9ec882e5d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_BYTE, g_nStringIdF_BOOL_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_BOOL_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_BYTE.h new file mode 100644 index 000000000..3b4e7ebd2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_BYTE_H_ +#define _F_BOOL_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_BYTE){ + }; + + virtual ~FORTE_F_BOOL_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DINT.cpp new file mode 100644 index 000000000..c3cbaa758 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_DINT, g_nStringIdF_BOOL_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_BOOL_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DINT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DINT.h new file mode 100644 index 000000000..a532ec3bd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_DINT_H_ +#define _F_BOOL_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_DINT){ + }; + + virtual ~FORTE_F_BOOL_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DWORD.cpp new file mode 100644 index 000000000..8f219d3aa --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_DWORD, g_nStringIdF_BOOL_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_BOOL_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DWORD.h new file mode 100644 index 000000000..f84ffa7ec --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_DWORD_H_ +#define _F_BOOL_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_DWORD){ + }; + + virtual ~FORTE_F_BOOL_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_INT.cpp new file mode 100644 index 000000000..189791d0a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_INT, g_nStringIdF_BOOL_TO_INT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_BOOL_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_INT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_INT.h new file mode 100644 index 000000000..f2d7843f1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_INT_H_ +#define _F_BOOL_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_INT){ + }; + + virtual ~FORTE_F_BOOL_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LINT.cpp new file mode 100644 index 000000000..7a49ce0c4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_LINT, g_nStringIdF_BOOL_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_BOOL_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LINT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LINT.h new file mode 100644 index 000000000..207305606 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_LINT_H_ +#define _F_BOOL_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_LINT){ + }; + + virtual ~FORTE_F_BOOL_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LREAL.cpp new file mode 100644 index 000000000..51dfaf154 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_LREAL, g_nStringIdF_BOOL_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_BOOL_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LREAL.h new file mode 100644 index 000000000..6034158f4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_LREAL_H_ +#define _F_BOOL_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_LREAL){ + }; + + virtual ~FORTE_F_BOOL_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LWORD.cpp new file mode 100644 index 000000000..c0a18d8a6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_LWORD, g_nStringIdF_BOOL_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_BOOL_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LWORD.h new file mode 100644 index 000000000..e91dd398d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_LWORD_H_ +#define _F_BOOL_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_LWORD){ + }; + + virtual ~FORTE_F_BOOL_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_REAL.cpp new file mode 100644 index 000000000..7d4c8bd17 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_REAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_REAL, g_nStringIdF_BOOL_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_BOOL_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_REAL.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_REAL.h new file mode 100644 index 000000000..98648ebb3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_REAL_H_ +#define _F_BOOL_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_REAL){ + }; + + virtual ~FORTE_F_BOOL_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_SINT.cpp new file mode 100644 index 000000000..3a277aeb9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_SINT, g_nStringIdF_BOOL_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_BOOL_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_SINT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_SINT.h new file mode 100644 index 000000000..399d0e6bd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_SINT_H_ +#define _F_BOOL_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_SINT){ + }; + + virtual ~FORTE_F_BOOL_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_STRING.cpp new file mode 100644 index 000000000..e7fea9fb5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_STRING, g_nStringIdF_BOOL_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_BOOL_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_STRING.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_STRING.h new file mode 100644 index 000000000..e36b0a170 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_STRING_H_ +#define _F_BOOL_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_STRING){ + }; + + virtual ~FORTE_F_BOOL_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_TIME.cpp new file mode 100644 index 000000000..e50287c38 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_TIME, g_nStringIdF_BOOL_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_BOOL_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_TIME.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_TIME.h new file mode 100644 index 000000000..9da0d70d7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_TIME_H_ +#define _F_BOOL_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_TIME){ + }; + + virtual ~FORTE_F_BOOL_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UDINT.cpp new file mode 100644 index 000000000..01b99bdfe --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_UDINT, g_nStringIdF_BOOL_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_BOOL_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UDINT.h new file mode 100644 index 000000000..99f581a2f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_UDINT_H_ +#define _F_BOOL_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_UDINT){ + }; + + virtual ~FORTE_F_BOOL_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UINT.cpp new file mode 100644 index 000000000..ee003af19 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_UINT, g_nStringIdF_BOOL_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_BOOL_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UINT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UINT.h new file mode 100644 index 000000000..736225c9f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_UINT_H_ +#define _F_BOOL_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_UINT){ + }; + + virtual ~FORTE_F_BOOL_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_ULINT.cpp new file mode 100644 index 000000000..8c31b666d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_ULINT.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_ULINT, g_nStringIdF_BOOL_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_BOOL_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_ULINT.h new file mode 100644 index 000000000..fb93afe8a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_ULINT_H_ +#define _F_BOOL_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_ULINT){ + }; + + virtual ~FORTE_F_BOOL_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_USINT.cpp new file mode 100644 index 000000000..e6fdb031d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_USINT, g_nStringIdF_BOOL_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_BOOL_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_USINT.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_USINT.h new file mode 100644 index 000000000..50ce6e3f2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_USINT_H_ +#define _F_BOOL_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_USINT){ + }; + + virtual ~FORTE_F_BOOL_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WORD.cpp new file mode 100644 index 000000000..fc939bfd0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_WORD, g_nStringIdF_BOOL_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_BOOL_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WORD.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WORD.h new file mode 100644 index 000000000..e48fab1ce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_WORD_H_ +#define _F_BOOL_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_WORD){ + }; + + virtual ~FORTE_F_BOOL_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WSTRING.cpp new file mode 100644 index 000000000..0e540a76f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BOOL_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BOOL_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BOOL_TO_WSTRING, g_nStringIdF_BOOL_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_BOOL_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BOOL_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BOOL_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BOOL_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BOOL_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BOOL_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BOOL_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BOOL_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WSTRING.h new file mode 100644 index 000000000..0399fde3f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BOOL/F_BOOL_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BOOL_TO_WSTRING_H_ +#define _F_BOOL_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_BOOL_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BOOL_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BOOL_TO_WSTRING){ + }; + + virtual ~FORTE_F_BOOL_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/BYTE/CMakeLists.txt new file mode 100644 index 000000000..de9bca17e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# BYTE_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_BYTE_TO_BOOL) +forte_add_sourcefile_hcpp(F_BYTE_TO_DINT) +forte_add_sourcefile_hcpp(F_BYTE_TO_DWORD) +forte_add_sourcefile_hcpp(F_BYTE_TO_INT) +forte_add_sourcefile_hcpp(F_BYTE_TO_SINT) +forte_add_sourcefile_hcpp(F_BYTE_TO_UDINT) +forte_add_sourcefile_hcpp(F_BYTE_TO_UINT) +forte_add_sourcefile_hcpp(F_BYTE_TO_USINT) +forte_add_sourcefile_hcpp(F_BYTE_TO_WORD) +forte_add_sourcefile_hcpp(F_BYTE_TO_STRING) +forte_add_sourcefile_hcpp(F_BYTE_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_BYTE_TO_LINT) + forte_add_sourcefile_hcpp(F_BYTE_TO_LWORD) + forte_add_sourcefile_hcpp(F_BYTE_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_BYTE_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_BYTE_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_BYTE_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_BOOL.cpp new file mode 100644 index 000000000..f798fbbc2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_BOOL, g_nStringIdF_BYTE_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_BYTE_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_BOOL.h new file mode 100644 index 000000000..3cd0b48c9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_BOOL_H_ +#define _F_BYTE_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_BOOL){ + }; + + virtual ~FORTE_F_BYTE_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DINT.cpp new file mode 100644 index 000000000..1882cde51 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_DINT, g_nStringIdF_BYTE_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_BYTE_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DINT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DINT.h new file mode 100644 index 000000000..6ca1bb86b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_DINT_H_ +#define _F_BYTE_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_DINT){ + }; + + virtual ~FORTE_F_BYTE_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DWORD.cpp new file mode 100644 index 000000000..e0fb8cdd0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_DWORD, g_nStringIdF_BYTE_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_BYTE_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DWORD.h new file mode 100644 index 000000000..ae2580dcf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_DWORD_H_ +#define _F_BYTE_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_DWORD){ + }; + + virtual ~FORTE_F_BYTE_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_INT.cpp new file mode 100644 index 000000000..dc31fa256 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_INT, g_nStringIdF_BYTE_TO_INT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_BYTE_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_INT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_INT.h new file mode 100644 index 000000000..ec58ea4a3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_INT_H_ +#define _F_BYTE_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_INT){ + }; + + virtual ~FORTE_F_BYTE_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LINT.cpp new file mode 100644 index 000000000..b80f4651d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_LINT, g_nStringIdF_BYTE_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_BYTE_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LINT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LINT.h new file mode 100644 index 000000000..e7e680db7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_LINT_H_ +#define _F_BYTE_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_LINT){ + }; + + virtual ~FORTE_F_BYTE_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LREAL.cpp new file mode 100644 index 000000000..1f76a1087 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_LREAL, g_nStringIdF_BYTE_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_BYTE_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LREAL.h new file mode 100644 index 000000000..084210afd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_LREAL_H_ +#define _F_BYTE_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_LREAL){ + }; + + virtual ~FORTE_F_BYTE_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LWORD.cpp new file mode 100644 index 000000000..64f4797c0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_LWORD, g_nStringIdF_BYTE_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_BYTE_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LWORD.h new file mode 100644 index 000000000..c5361715e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_LWORD_H_ +#define _F_BYTE_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_LWORD){ + }; + + virtual ~FORTE_F_BYTE_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_REAL.cpp new file mode 100644 index 000000000..b2123d85c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_REAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_REAL, g_nStringIdF_BYTE_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_BYTE_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_REAL.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_REAL.h new file mode 100644 index 000000000..2bade1650 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_REAL_H_ +#define _F_BYTE_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_REAL){ + }; + + virtual ~FORTE_F_BYTE_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_SINT.cpp new file mode 100644 index 000000000..085576ba2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_SINT, g_nStringIdF_BYTE_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_BYTE_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_SINT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_SINT.h new file mode 100644 index 000000000..683fa44b7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_SINT_H_ +#define _F_BYTE_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_SINT){ + }; + + virtual ~FORTE_F_BYTE_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_STRING.cpp new file mode 100644 index 000000000..b887004be --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_STRING, g_nStringIdF_BYTE_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_BYTE_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_STRING.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_STRING.h new file mode 100644 index 000000000..1c792fba0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_STRING_H_ +#define _F_BYTE_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_STRING){ + }; + + virtual ~FORTE_F_BYTE_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_TIME.cpp new file mode 100644 index 000000000..cfd0c5743 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_TIME, g_nStringIdF_BYTE_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_BYTE_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_TIME.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_TIME.h new file mode 100644 index 000000000..05fdba8e4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_TIME_H_ +#define _F_BYTE_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_TIME){ + }; + + virtual ~FORTE_F_BYTE_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UDINT.cpp new file mode 100644 index 000000000..9a24f8239 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_UDINT, g_nStringIdF_BYTE_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_BYTE_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UDINT.h new file mode 100644 index 000000000..569caeff7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_UDINT_H_ +#define _F_BYTE_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_UDINT){ + }; + + virtual ~FORTE_F_BYTE_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UINT.cpp new file mode 100644 index 000000000..9c0a10562 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_BYTE_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_UINT, g_nStringIdF_BYTE_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_BYTE_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UINT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UINT.h new file mode 100644 index 000000000..eb35a8b4b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_UINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_BYTE_TO_UINT_H_ +#define _F_BYTE_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_UINT){ + }; + + virtual ~FORTE_F_BYTE_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_ULINT.cpp new file mode 100644 index 000000000..488254a55 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_ULINT, g_nStringIdF_BYTE_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_BYTE_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_ULINT.h new file mode 100644 index 000000000..c8443f38b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_ULINT_H_ +#define _F_BYTE_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_ULINT){ + }; + + virtual ~FORTE_F_BYTE_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_USINT.cpp new file mode 100644 index 000000000..6e614e473 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_USINT, g_nStringIdF_BYTE_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_BYTE_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_USINT.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_USINT.h new file mode 100644 index 000000000..d8533cebc --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_USINT_H_ +#define _F_BYTE_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_USINT){ + }; + + virtual ~FORTE_F_BYTE_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WORD.cpp new file mode 100644 index 000000000..438698b31 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_WORD, g_nStringIdF_BYTE_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_BYTE_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WORD.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WORD.h new file mode 100644 index 000000000..62cee79a6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_WORD_H_ +#define _F_BYTE_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_WORD){ + }; + + virtual ~FORTE_F_BYTE_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WSTRING.cpp new file mode 100644 index 000000000..4a3438295 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_BYTE_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_BYTE_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_BYTE_TO_WSTRING, g_nStringIdF_BYTE_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdBYTE}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_BYTE_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_BYTE_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_BYTE_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_BYTE_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_BYTE_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_BYTE_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_BYTE_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = BYTE_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WSTRING.h new file mode 100644 index 000000000..79dd605c2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/BYTE/F_BYTE_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_BYTE_TO_WSTRING_H_ +#define _F_BYTE_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_BYTE_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_BYTE_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BYTE &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_BYTE_TO_WSTRING){ + }; + + virtual ~FORTE_F_BYTE_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/CMakeLists.txt new file mode 100644 index 000000000..f6825538f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/CMakeLists.txt @@ -0,0 +1,46 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2013 ACIN, Profacor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Conversion +############################################################################# +forte_add_subdirectory(BOOL) +forte_add_subdirectory(BYTE) +forte_add_subdirectory(DINT) +forte_add_subdirectory(DWORD) +forte_add_subdirectory(INT) +forte_add_subdirectory(SINT) +forte_add_subdirectory(STRING) +forte_add_subdirectory(TIME) +forte_add_subdirectory(UDINT) +forte_add_subdirectory(UINT) +forte_add_subdirectory(USINT) +forte_add_subdirectory(WORD) +forte_add_subdirectory(BCD) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_subdirectory(WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_subdirectory(REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_subdirectory(LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_subdirectory(ULINT) + forte_add_subdirectory(LWORD) + forte_add_subdirectory(LINT) + forte_add_subdirectory(DT) +endif(FORTE_USE_64BIT_DATATYPES) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/DINT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/DINT/CMakeLists.txt new file mode 100644 index 000000000..6ef5c1480 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# DINT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_DINT_TO_BOOL) +forte_add_sourcefile_hcpp(F_DINT_TO_BYTE) +forte_add_sourcefile_hcpp(F_DINT_TO_DWORD) +forte_add_sourcefile_hcpp(F_DINT_TO_INT) +forte_add_sourcefile_hcpp(F_DINT_TO_SINT) +forte_add_sourcefile_hcpp(F_DINT_TO_UINT) +forte_add_sourcefile_hcpp(F_DINT_TO_UDINT) +forte_add_sourcefile_hcpp(F_DINT_TO_USINT) +forte_add_sourcefile_hcpp(F_DINT_TO_WORD) +forte_add_sourcefile_hcpp(F_DINT_TO_STRING) +forte_add_sourcefile_hcpp(F_DINT_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_DINT_TO_LINT) + forte_add_sourcefile_hcpp(F_DINT_TO_LWORD) + forte_add_sourcefile_hcpp(F_DINT_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_DINT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_DINT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_DINT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BOOL.cpp new file mode 100644 index 000000000..b0a2f39aa --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_BOOL, g_nStringIdF_DINT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_DINT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BOOL.h new file mode 100644 index 000000000..3e4f36c1b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_BOOL_H_ +#define _F_DINT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_BOOL){ + }; + + virtual ~FORTE_F_DINT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BYTE.cpp new file mode 100644 index 000000000..6bf1f7bbe --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_BYTE, g_nStringIdF_DINT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_DINT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BYTE.h new file mode 100644 index 000000000..7bf676021 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_BYTE_H_ +#define _F_DINT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_BYTE){ + }; + + virtual ~FORTE_F_DINT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_DWORD.cpp new file mode 100644 index 000000000..4a3f203e4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_DWORD, g_nStringIdF_DINT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_DINT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_DWORD.h new file mode 100644 index 000000000..5c2ac6b49 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_DWORD_H_ +#define _F_DINT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_DWORD){ + }; + + virtual ~FORTE_F_DINT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_INT.cpp new file mode 100644 index 000000000..719d5a157 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_INT, g_nStringIdF_DINT_TO_INT) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_DINT_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_INT.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_INT.h new file mode 100644 index 000000000..6e2a640a8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_INT_H_ +#define _F_DINT_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_INT){ + }; + + virtual ~FORTE_F_DINT_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LINT.cpp new file mode 100644 index 000000000..4401c1113 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_LINT, g_nStringIdF_DINT_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_DINT_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LINT.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LINT.h new file mode 100644 index 000000000..f7b124f88 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_LINT_H_ +#define _F_DINT_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_LINT){ + }; + + virtual ~FORTE_F_DINT_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LREAL.cpp new file mode 100644 index 000000000..a307a37ac --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_LREAL, g_nStringIdF_DINT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_DINT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LREAL.h new file mode 100644 index 000000000..13741ed43 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_LREAL_H_ +#define _F_DINT_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_LREAL){ + }; + + virtual ~FORTE_F_DINT_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LWORD.cpp new file mode 100644 index 000000000..ec64bc5d0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_LWORD, g_nStringIdF_DINT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_DINT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LWORD.h new file mode 100644 index 000000000..a18e8d0a8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_LWORD_H_ +#define _F_DINT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_LWORD){ + }; + + virtual ~FORTE_F_DINT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_REAL.cpp new file mode 100644 index 000000000..a9daf0f69 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_REAL.cpp @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_DINT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_REAL_gen.cpp" +#endif + +#ifdef FORTE_USE_REAL_DATATYPE + + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_REAL, g_nStringIdF_DINT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_DINT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_REAL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + +#endif + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_REAL.h new file mode 100644 index 000000000..24af0e637 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_REAL.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_DINT_TO_REAL_H_ +#define _F_DINT_TO_REAL_H_ + +#ifdef FORTE_USE_REAL_DATATYPE + +#include +#include +#include + + + +class FORTE_F_DINT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_REAL){ + }; + + virtual ~FORTE_F_DINT_TO_REAL(){}; + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_SINT.cpp new file mode 100644 index 000000000..f5f860563 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_SINT, g_nStringIdF_DINT_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_DINT_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_SINT.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_SINT.h new file mode 100644 index 000000000..6593f5883 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_SINT_H_ +#define _F_DINT_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_SINT){ + }; + + virtual ~FORTE_F_DINT_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_STRING.cpp new file mode 100644 index 000000000..405479d23 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_STRING, g_nStringIdF_DINT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_DINT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_STRING.h new file mode 100644 index 000000000..ae33df775 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_STRING_H_ +#define _F_DINT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_STRING){ + }; + + virtual ~FORTE_F_DINT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_TIME.cpp new file mode 100644 index 000000000..a0b285532 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_TIME, g_nStringIdF_DINT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_DINT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_TIME.h new file mode 100644 index 000000000..a3c4e63c8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_TIME_H_ +#define _F_DINT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_TIME){ + }; + + virtual ~FORTE_F_DINT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UDINT.cpp new file mode 100644 index 000000000..33e89667c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_UDINT, g_nStringIdF_DINT_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_DINT_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UDINT.h new file mode 100644 index 000000000..10cf7b551 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_UDINT_H_ +#define _F_DINT_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_UDINT){ + }; + + virtual ~FORTE_F_DINT_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UINT.cpp new file mode 100644 index 000000000..304f851f3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_UINT, g_nStringIdF_DINT_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_DINT_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UINT.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UINT.h new file mode 100644 index 000000000..f286e0b2e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_UINT_H_ +#define _F_DINT_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_UINT){ + }; + + virtual ~FORTE_F_DINT_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_ULINT.cpp new file mode 100644 index 000000000..8e7f6a5cd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_ULINT, g_nStringIdF_DINT_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_DINT_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_ULINT.h new file mode 100644 index 000000000..3091211b3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_ULINT_H_ +#define _F_DINT_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_ULINT){ + }; + + virtual ~FORTE_F_DINT_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_USINT.cpp new file mode 100644 index 000000000..202c8ec34 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_USINT, g_nStringIdF_DINT_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_DINT_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_USINT.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_USINT.h new file mode 100644 index 000000000..a4a3195c6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_USINT_H_ +#define _F_DINT_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_USINT){ + }; + + virtual ~FORTE_F_DINT_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WORD.cpp new file mode 100644 index 000000000..73ce7ffe9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_WORD, g_nStringIdF_DINT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_DINT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WORD.h new file mode 100644 index 000000000..7ccf989cb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_WORD_H_ +#define _F_DINT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_WORD){ + }; + + virtual ~FORTE_F_DINT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WSTRING.cpp new file mode 100644 index 000000000..639bfd17c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DINT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DINT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DINT_TO_WSTRING, g_nStringIdF_DINT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdDINT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DINT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_DINT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DINT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DINT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DINT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DINT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DINT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DINT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DINT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WSTRING.h new file mode 100644 index 000000000..b02eec860 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DINT/F_DINT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DINT_TO_WSTRING_H_ +#define _F_DINT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_DINT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DINT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DINT_TO_WSTRING){ + }; + + virtual ~FORTE_F_DINT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/DT/CMakeLists.txt new file mode 100644 index 000000000..2323531f8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DT/CMakeLists.txt @@ -0,0 +1,16 @@ +#******************************************************************************* +# * Copyright (c) 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# DT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_DT_TO_TOD) +forte_add_sourcefile_hcpp(F_DT_TO_DATE) diff --git a/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_DATE.cpp b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_DATE.cpp new file mode 100644 index 000000000..9154b0731 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_DATE.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DT_TO_DATE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DT_TO_DATE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DT_TO_DATE, g_nStringIdF_DT_TO_DATE) + +const CStringDictionary::TStringId FORTE_F_DT_TO_DATE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DT_TO_DATE::scm_anDataInputTypeIds[] = {g_nStringIdDATE_AND_TIME}; + +const CStringDictionary::TStringId FORTE_F_DT_TO_DATE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DT_TO_DATE::scm_anDataOutputTypeIds[] = {g_nStringIdDATE}; + +const TForteInt16 FORTE_F_DT_TO_DATE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DT_TO_DATE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DT_TO_DATE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DT_TO_DATE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DT_TO_DATE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DT_TO_DATE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DT_TO_DATE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DT_TO_DATE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DT_TO_DATE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_DATE.h b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_DATE.h new file mode 100644 index 000000000..002e055f1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_DATE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DT_TO_DATE_H_ +#define _F_DT_TO_DATE_H_ + +#include +#include +#include + +class FORTE_F_DT_TO_DATE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DT_TO_DATE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DATE_AND_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DATE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DT_TO_DATE){ + }; + + virtual ~FORTE_F_DT_TO_DATE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_TOD.cpp b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_TOD.cpp new file mode 100644 index 000000000..fc2a5c175 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_TOD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DT_TO_TOD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DT_TO_TOD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DT_TO_TOD, g_nStringIdF_DT_TO_TOD) + +const CStringDictionary::TStringId FORTE_F_DT_TO_TOD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DT_TO_TOD::scm_anDataInputTypeIds[] = {g_nStringIdDATE_AND_TIME}; + +const CStringDictionary::TStringId FORTE_F_DT_TO_TOD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DT_TO_TOD::scm_anDataOutputTypeIds[] = {g_nStringIdTIME_OF_DAY}; + +const TForteInt16 FORTE_F_DT_TO_TOD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DT_TO_TOD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DT_TO_TOD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DT_TO_TOD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DT_TO_TOD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DT_TO_TOD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DT_TO_TOD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DT_TO_TOD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DT_TO_TOD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_TOD.h b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_TOD.h new file mode 100644 index 000000000..2453da8d5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DT/F_DT_TO_TOD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DT_TO_TOD_H_ +#define _F_DT_TO_TOD_H_ + +#include +#include +#include + +class FORTE_F_DT_TO_TOD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DT_TO_TOD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DATE_AND_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME_OF_DAY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DT_TO_TOD){ + }; + + virtual ~FORTE_F_DT_TO_TOD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/DWORD/CMakeLists.txt new file mode 100644 index 000000000..ab0f2f76a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# DWORD_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_DWORD_TO_BOOL) +forte_add_sourcefile_hcpp(F_DWORD_TO_BYTE) +forte_add_sourcefile_hcpp(F_DWORD_TO_DINT) +forte_add_sourcefile_hcpp(F_DWORD_TO_INT) +forte_add_sourcefile_hcpp(F_DWORD_TO_SINT) +forte_add_sourcefile_hcpp(F_DWORD_TO_UDINT) +forte_add_sourcefile_hcpp(F_DWORD_TO_UINT) +forte_add_sourcefile_hcpp(F_DWORD_TO_USINT) +forte_add_sourcefile_hcpp(F_DWORD_TO_WORD) +forte_add_sourcefile_hcpp(F_DWORD_TO_STRING) +forte_add_sourcefile_hcpp(F_DWORD_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_DWORD_TO_LINT) + forte_add_sourcefile_hcpp(F_DWORD_TO_LWORD) + forte_add_sourcefile_hcpp(F_DWORD_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_DWORD_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_DWORD_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_DWORD_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BOOL.cpp new file mode 100644 index 000000000..50a27a636 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_BOOL, g_nStringIdF_DWORD_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_DWORD_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BOOL.h new file mode 100644 index 000000000..982649156 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_BOOL_H_ +#define _F_DWORD_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_BOOL){ + }; + + virtual ~FORTE_F_DWORD_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BYTE.cpp new file mode 100644 index 000000000..0a73371fd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_BYTE, g_nStringIdF_DWORD_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_DWORD_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BYTE.h new file mode 100644 index 000000000..e3f1aa098 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_BYTE_H_ +#define _F_DWORD_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_BYTE){ + }; + + virtual ~FORTE_F_DWORD_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_DINT.cpp new file mode 100644 index 000000000..32d63d160 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_DINT, g_nStringIdF_DWORD_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_DWORD_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_DINT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_DINT.h new file mode 100644 index 000000000..08efaa00b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_DINT_H_ +#define _F_DWORD_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_DINT){ + }; + + virtual ~FORTE_F_DWORD_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_INT.cpp new file mode 100644 index 000000000..9c6611e5c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_INT, g_nStringIdF_DWORD_TO_INT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_DWORD_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_INT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_INT.h new file mode 100644 index 000000000..51220bd78 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_INT_H_ +#define _F_DWORD_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_INT){ + }; + + virtual ~FORTE_F_DWORD_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LINT.cpp new file mode 100644 index 000000000..169c9469b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_LINT, g_nStringIdF_DWORD_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_DWORD_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LINT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LINT.h new file mode 100644 index 000000000..2e3839da7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_LINT_H_ +#define _F_DWORD_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_LINT){ + }; + + virtual ~FORTE_F_DWORD_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LREAL.cpp new file mode 100644 index 000000000..6c9ec56ce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_LREAL, g_nStringIdF_DWORD_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_DWORD_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LREAL.h new file mode 100644 index 000000000..d8d4e9eec --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_LREAL_H_ +#define _F_DWORD_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_LREAL){ + }; + + virtual ~FORTE_F_DWORD_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LWORD.cpp new file mode 100644 index 000000000..4b989fcd8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_LWORD, g_nStringIdF_DWORD_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_DWORD_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LWORD.h new file mode 100644 index 000000000..ae13918a0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_LWORD_H_ +#define _F_DWORD_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_LWORD){ + }; + + virtual ~FORTE_F_DWORD_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_REAL.cpp new file mode 100644 index 000000000..85968d2d2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_REAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_REAL, g_nStringIdF_DWORD_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_DWORD_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_REAL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +void FORTE_F_DWORD_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_REAL.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_REAL.h new file mode 100644 index 000000000..cc8a176fd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_REAL_H_ +#define _F_DWORD_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_REAL){ + }; + + virtual ~FORTE_F_DWORD_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_SINT.cpp new file mode 100644 index 000000000..429a16d83 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_SINT, g_nStringIdF_DWORD_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_DWORD_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_SINT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_SINT.h new file mode 100644 index 000000000..bf068e87b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_SINT_H_ +#define _F_DWORD_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_SINT){ + }; + + virtual ~FORTE_F_DWORD_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_STRING.cpp new file mode 100644 index 000000000..0ba376bb9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_STRING, g_nStringIdF_DWORD_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_DWORD_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() =DWORD_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_STRING.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_STRING.h new file mode 100644 index 000000000..cb6668b19 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_STRING_H_ +#define _F_DWORD_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_STRING){ + }; + + virtual ~FORTE_F_DWORD_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_TIME.cpp new file mode 100644 index 000000000..4cb099326 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_TIME.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_TIME, g_nStringIdF_DWORD_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_DWORD_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_TIME.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_TIME.h new file mode 100644 index 000000000..6bc5d8f3c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_TIME_H_ +#define _F_DWORD_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_TIME){ + }; + + virtual ~FORTE_F_DWORD_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UDINT.cpp new file mode 100644 index 000000000..112dd6b96 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_UDINT, g_nStringIdF_DWORD_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_DWORD_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UDINT.h new file mode 100644 index 000000000..6cb822a45 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_UDINT_H_ +#define _F_DWORD_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_UDINT){ + }; + + virtual ~FORTE_F_DWORD_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UINT.cpp new file mode 100644 index 000000000..c0f64a376 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_UINT, g_nStringIdF_DWORD_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_DWORD_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UINT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UINT.h new file mode 100644 index 000000000..596ea2acc --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_UINT_H_ +#define _F_DWORD_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_UINT){ + }; + + virtual ~FORTE_F_DWORD_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_ULINT.cpp new file mode 100644 index 000000000..3c0a00bec --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_ULINT, g_nStringIdF_DWORD_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_DWORD_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_ULINT.h new file mode 100644 index 000000000..9be7aa743 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_ULINT_H_ +#define _F_DWORD_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_ULINT){ + }; + + virtual ~FORTE_F_DWORD_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_USINT.cpp new file mode 100644 index 000000000..960c018bf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_USINT, g_nStringIdF_DWORD_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_DWORD_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_USINT.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_USINT.h new file mode 100644 index 000000000..73ec5cb6e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_USINT_H_ +#define _F_DWORD_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_USINT){ + }; + + virtual ~FORTE_F_DWORD_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WORD.cpp new file mode 100644 index 000000000..d4660a45a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_WORD, g_nStringIdF_DWORD_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_DWORD_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WORD.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WORD.h new file mode 100644 index 000000000..0df8c3241 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_WORD_H_ +#define _F_DWORD_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_WORD){ + }; + + virtual ~FORTE_F_DWORD_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WSTRING.cpp new file mode 100644 index 000000000..8ea8d394b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WSTRING.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_DWORD_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_DWORD_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_DWORD_TO_WSTRING, g_nStringIdF_DWORD_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdDWORD}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_DWORD_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_DWORD_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_DWORD_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_DWORD_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_DWORD_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_DWORD_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_DWORD_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = DWORD_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + diff --git a/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WSTRING.h new file mode 100644 index 000000000..d1c71679f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/DWORD/F_DWORD_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_DWORD_TO_WSTRING_H_ +#define _F_DWORD_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_DWORD_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_DWORD_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_DWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_DWORD_TO_WSTRING){ + }; + + virtual ~FORTE_F_DWORD_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/INT/CMakeLists.txt new file mode 100644 index 000000000..c35f59764 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# INT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_INT_TO_BOOL) +forte_add_sourcefile_hcpp(F_INT_TO_BYTE) +forte_add_sourcefile_hcpp(F_INT_TO_DINT) +forte_add_sourcefile_hcpp(F_INT_TO_DWORD) +forte_add_sourcefile_hcpp(F_INT_TO_SINT) +forte_add_sourcefile_hcpp(F_INT_TO_UDINT) +forte_add_sourcefile_hcpp(F_INT_TO_UINT) +forte_add_sourcefile_hcpp(F_INT_TO_USINT) +forte_add_sourcefile_hcpp(F_INT_TO_WORD) +forte_add_sourcefile_hcpp(F_INT_TO_STRING) +forte_add_sourcefile_hcpp(F_INT_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_INT_TO_LINT) + forte_add_sourcefile_hcpp(F_INT_TO_LWORD) + forte_add_sourcefile_hcpp(F_INT_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_INT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_INT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_INT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BOOL.cpp new file mode 100644 index 000000000..2e70536ef --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_BOOL, g_nStringIdF_INT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_INT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_INT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BOOL.h new file mode 100644 index 000000000..bb2a190ec --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_BOOL_H_ +#define _F_INT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_BOOL){ + }; + + virtual ~FORTE_F_INT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BYTE.cpp new file mode 100644 index 000000000..9f0989966 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_BYTE, g_nStringIdF_INT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_INT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_INT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BYTE.h new file mode 100644 index 000000000..828afe763 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_BYTE_H_ +#define _F_INT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_BYTE){ + }; + + virtual ~FORTE_F_INT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DINT.cpp new file mode 100644 index 000000000..d4925d80a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_DINT, g_nStringIdF_INT_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_INT_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_INT_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DINT.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DINT.h new file mode 100644 index 000000000..3f137db7a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_DINT_H_ +#define _F_INT_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_DINT){ + }; + + virtual ~FORTE_F_INT_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DWORD.cpp new file mode 100644 index 000000000..adacbb649 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_DWORD, g_nStringIdF_INT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_INT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_INT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DWORD.h new file mode 100644 index 000000000..31d6daf5c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_DWORD_H_ +#define _F_INT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_DWORD){ + }; + + virtual ~FORTE_F_INT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LINT.cpp new file mode 100644 index 000000000..1e698b79c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_LINT, g_nStringIdF_INT_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_INT_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_INT_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LINT.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LINT.h new file mode 100644 index 000000000..7d39cec23 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_LINT_H_ +#define _F_INT_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_LINT){ + }; + + virtual ~FORTE_F_INT_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LREAL.cpp new file mode 100644 index 000000000..eaacf4d28 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LREAL.cpp @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_INT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_LREAL_gen.cpp" +#endif + +#ifdef FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_LREAL, g_nStringIdF_INT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_INT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_INT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_LREAL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_INT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + +#endif +#endif + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LREAL.h new file mode 100644 index 000000000..cf39188f0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LREAL.h @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_INT_TO_LREAL_H_ +#define _F_INT_TO_LREAL_H_ + +#ifdef FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + + +#include +#include +#include + +class FORTE_F_INT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_LREAL){ + }; + + virtual ~FORTE_F_INT_TO_LREAL(){}; + +}; + +#endif +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LWORD.cpp new file mode 100644 index 000000000..28adc4e34 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_LWORD, g_nStringIdF_INT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_INT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_INT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LWORD.h new file mode 100644 index 000000000..f896a2031 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_LWORD_H_ +#define _F_INT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_LWORD){ + }; + + virtual ~FORTE_F_INT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_REAL.cpp new file mode 100644 index 000000000..c1c689a56 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_REAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_REAL, g_nStringIdF_INT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_INT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_INT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_REAL.h new file mode 100644 index 000000000..b235b810a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_REAL_H_ +#define _F_INT_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_REAL){ + }; + + virtual ~FORTE_F_INT_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_SINT.cpp new file mode 100644 index 000000000..6d30379ec --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_SINT, g_nStringIdF_INT_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_INT_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_INT_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_SINT.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_SINT.h new file mode 100644 index 000000000..737ab6522 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_SINT_H_ +#define _F_INT_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_SINT){ + }; + + virtual ~FORTE_F_INT_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_STRING.cpp new file mode 100644 index 000000000..6c15fbfbd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_STRING, g_nStringIdF_INT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_INT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_INT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_STRING.h new file mode 100644 index 000000000..e82215ca7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_STRING_H_ +#define _F_INT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_STRING){ + }; + + virtual ~FORTE_F_INT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_TIME.cpp new file mode 100644 index 000000000..730a3e954 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_TIME, g_nStringIdF_INT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_INT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_INT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_TIME.h new file mode 100644 index 000000000..a6293c86b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_TIME_H_ +#define _F_INT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_TIME){ + }; + + virtual ~FORTE_F_INT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UDINT.cpp new file mode 100644 index 000000000..501ad6f8e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_UDINT, g_nStringIdF_INT_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_INT_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_INT_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UDINT.h new file mode 100644 index 000000000..1b5a08226 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_UDINT_H_ +#define _F_INT_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_UDINT){ + }; + + virtual ~FORTE_F_INT_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UINT.cpp new file mode 100644 index 000000000..3f1336c60 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_UINT, g_nStringIdF_INT_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_INT_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_INT_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UINT.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UINT.h new file mode 100644 index 000000000..27e48b359 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_UINT_H_ +#define _F_INT_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_UINT){ + }; + + virtual ~FORTE_F_INT_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_ULINT.cpp new file mode 100644 index 000000000..d16802778 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_ULINT, g_nStringIdF_INT_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_INT_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_INT_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_ULINT.h new file mode 100644 index 000000000..47a7eb4e1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_ULINT_H_ +#define _F_INT_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_ULINT){ + }; + + virtual ~FORTE_F_INT_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_USINT.cpp new file mode 100644 index 000000000..c0df718a7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_USINT, g_nStringIdF_INT_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_INT_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_INT_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_USINT.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_USINT.h new file mode 100644 index 000000000..9b691a436 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_USINT_H_ +#define _F_INT_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_USINT){ + }; + + virtual ~FORTE_F_INT_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WORD.cpp new file mode 100644 index 000000000..84c14fe0a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_WORD, g_nStringIdF_INT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_INT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_INT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WORD.h new file mode 100644 index 000000000..7b150ed60 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_WORD_H_ +#define _F_INT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_WORD){ + }; + + virtual ~FORTE_F_INT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WSTRING.cpp new file mode 100644 index 000000000..9eabbf4a1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_INT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_INT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_INT_TO_WSTRING, g_nStringIdF_INT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_INT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdINT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_INT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_INT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_INT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_INT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_INT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_INT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_INT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_INT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_INT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = INT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WSTRING.h new file mode 100644 index 000000000..d87710252 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/INT/F_INT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_INT_TO_WSTRING_H_ +#define _F_INT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_INT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_INT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_INT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_INT_TO_WSTRING){ + }; + + virtual ~FORTE_F_INT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/LINT/CMakeLists.txt new file mode 100644 index 000000000..4e35a1974 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# LINT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_LINT_TO_BOOL) +forte_add_sourcefile_hcpp(F_LINT_TO_BYTE) +forte_add_sourcefile_hcpp(F_LINT_TO_DINT) +forte_add_sourcefile_hcpp(F_LINT_TO_DWORD) +forte_add_sourcefile_hcpp(F_LINT_TO_INT) +forte_add_sourcefile_hcpp(F_LINT_TO_SINT) +forte_add_sourcefile_hcpp(F_LINT_TO_UDINT) +forte_add_sourcefile_hcpp(F_LINT_TO_UINT) +forte_add_sourcefile_hcpp(F_LINT_TO_USINT) +forte_add_sourcefile_hcpp(F_LINT_TO_WORD) +forte_add_sourcefile_hcpp(F_LINT_TO_STRING) +forte_add_sourcefile_hcpp(F_LINT_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_LINT_TO_LWORD) + forte_add_sourcefile_hcpp(F_LINT_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_LINT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_LINT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_LINT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BOOL.cpp new file mode 100644 index 000000000..7aed1c3cd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_BOOL, g_nStringIdF_LINT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_LINT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BOOL.h new file mode 100644 index 000000000..c0c08f355 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_BOOL_H_ +#define _F_LINT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_BOOL){ + }; + + virtual ~FORTE_F_LINT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BYTE.cpp new file mode 100644 index 000000000..5924935d0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_BYTE, g_nStringIdF_LINT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_LINT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BYTE.h new file mode 100644 index 000000000..e5c122b3a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_BYTE_H_ +#define _F_LINT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_BYTE){ + }; + + virtual ~FORTE_F_LINT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DINT.cpp new file mode 100644 index 000000000..78f373f93 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_DINT, g_nStringIdF_LINT_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_LINT_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DINT.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DINT.h new file mode 100644 index 000000000..e87dfa547 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_DINT_H_ +#define _F_LINT_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_DINT){ + }; + + virtual ~FORTE_F_LINT_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DWORD.cpp new file mode 100644 index 000000000..7581b7451 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_DWORD, g_nStringIdF_LINT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_LINT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DWORD.h new file mode 100644 index 000000000..252832034 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_DWORD_H_ +#define _F_LINT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_DWORD){ + }; + + virtual ~FORTE_F_LINT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_INT.cpp new file mode 100644 index 000000000..2fab78050 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_INT, g_nStringIdF_LINT_TO_INT) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_LINT_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_INT.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_INT.h new file mode 100644 index 000000000..3cd5c1314 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_INT_H_ +#define _F_LINT_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_INT){ + }; + + virtual ~FORTE_F_LINT_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LREAL.cpp new file mode 100644 index 000000000..7c0eb7d06 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_LREAL, g_nStringIdF_LINT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_LINT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LREAL.h new file mode 100644 index 000000000..3b06d853a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_LREAL_H_ +#define _F_LINT_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_LREAL){ + }; + + virtual ~FORTE_F_LINT_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LWORD.cpp new file mode 100644 index 000000000..a8d78edb6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_LWORD, g_nStringIdF_LINT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_LINT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LWORD.h new file mode 100644 index 000000000..4d676cbd9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_LWORD_H_ +#define _F_LINT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_LWORD){ + }; + + virtual ~FORTE_F_LINT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_REAL.cpp new file mode 100644 index 000000000..5a12ddff8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_REAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_REAL, g_nStringIdF_LINT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_LINT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_REAL.h new file mode 100644 index 000000000..c7e47638d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_REAL_H_ +#define _F_LINT_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_REAL){ + }; + + virtual ~FORTE_F_LINT_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_SINT.cpp new file mode 100644 index 000000000..f56c9ce02 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_SINT, g_nStringIdF_LINT_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_LINT_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_SINT.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_SINT.h new file mode 100644 index 000000000..11188d880 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_SINT_H_ +#define _F_LINT_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_SINT){ + }; + + virtual ~FORTE_F_LINT_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_STRING.cpp new file mode 100644 index 000000000..883df033a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_STRING, g_nStringIdF_LINT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_LINT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_STRING.h new file mode 100644 index 000000000..df4dfe63c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_STRING_H_ +#define _F_LINT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_STRING){ + }; + + virtual ~FORTE_F_LINT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_TIME.cpp new file mode 100644 index 000000000..ea4a2ed43 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_TIME, g_nStringIdF_LINT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_LINT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_TIME.h new file mode 100644 index 000000000..19e434719 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_TIME_H_ +#define _F_LINT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_TIME){ + }; + + virtual ~FORTE_F_LINT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UDINT.cpp new file mode 100644 index 000000000..353998435 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_UDINT, g_nStringIdF_LINT_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_LINT_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UDINT.h new file mode 100644 index 000000000..6697cd362 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_UDINT_H_ +#define _F_LINT_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_UDINT){ + }; + + virtual ~FORTE_F_LINT_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UINT.cpp new file mode 100644 index 000000000..6e639c0b8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_UINT, g_nStringIdF_LINT_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_LINT_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UINT.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UINT.h new file mode 100644 index 000000000..8329de189 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_UINT_H_ +#define _F_LINT_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_UINT){ + }; + + virtual ~FORTE_F_LINT_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_ULINT.cpp new file mode 100644 index 000000000..8237a7fa0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_ULINT, g_nStringIdF_LINT_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_LINT_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_ULINT.h new file mode 100644 index 000000000..7e06da88b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_ULINT_H_ +#define _F_LINT_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_ULINT){ + }; + + virtual ~FORTE_F_LINT_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_USINT.cpp new file mode 100644 index 000000000..5c9875d0e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_USINT, g_nStringIdF_LINT_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_LINT_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_USINT.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_USINT.h new file mode 100644 index 000000000..4d188f0a1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_USINT_H_ +#define _F_LINT_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_USINT){ + }; + + virtual ~FORTE_F_LINT_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WORD.cpp new file mode 100644 index 000000000..6bc9150e8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_WORD, g_nStringIdF_LINT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_LINT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WORD.h new file mode 100644 index 000000000..2783ce414 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_WORD_H_ +#define _F_LINT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_WORD){ + }; + + virtual ~FORTE_F_LINT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WSTRING.cpp new file mode 100644 index 000000000..5de354c72 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LINT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LINT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LINT_TO_WSTRING, g_nStringIdF_LINT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdLINT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LINT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_LINT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LINT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LINT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LINT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LINT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LINT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LINT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LINT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WSTRING.h new file mode 100644 index 000000000..8f69d74ad --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LINT/F_LINT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LINT_TO_WSTRING_H_ +#define _F_LINT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_LINT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LINT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LINT_TO_WSTRING){ + }; + + virtual ~FORTE_F_LINT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/LREAL/CMakeLists.txt new file mode 100644 index 000000000..ab1aaa642 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/CMakeLists.txt @@ -0,0 +1,40 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# LREAL_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_LREAL_TO_BOOL) +forte_add_sourcefile_hcpp(F_LREAL_TO_BYTE) +forte_add_sourcefile_hcpp(F_LREAL_TO_DWORD) +forte_add_sourcefile_hcpp(F_LREAL_TO_WORD) +forte_add_sourcefile_hcpp(F_LREAL_TO_DINT) +forte_add_sourcefile_hcpp(F_LREAL_TO_INT) +forte_add_sourcefile_hcpp(F_LREAL_TO_SINT) +forte_add_sourcefile_hcpp(F_LREAL_TO_UDINT) +forte_add_sourcefile_hcpp(F_LREAL_TO_UINT) +forte_add_sourcefile_hcpp(F_LREAL_TO_USINT) +forte_add_sourcefile_hcpp(F_LREAL_TO_STRING) +forte_add_sourcefile_hcpp(F_LREAL_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_LREAL_TO_LINT) + forte_add_sourcefile_hcpp(F_LREAL_TO_LWORD) + forte_add_sourcefile_hcpp(F_LREAL_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_LREAL_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_LREAL_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BOOL.cpp new file mode 100644 index 000000000..851e976a3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_BOOL, g_nStringIdF_LREAL_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_LREAL_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BOOL.h new file mode 100644 index 000000000..639d9ac1c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_BOOL_H_ +#define _F_LREAL_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_BOOL){ + }; + + virtual ~FORTE_F_LREAL_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BYTE.cpp new file mode 100644 index 000000000..d79d98665 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_BYTE, g_nStringIdF_LREAL_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_LREAL_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BYTE.h new file mode 100644 index 000000000..5f1e14276 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_BYTE_H_ +#define _F_LREAL_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_BYTE){ + }; + + virtual ~FORTE_F_LREAL_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DINT.cpp new file mode 100644 index 000000000..3bacab839 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_DINT, g_nStringIdF_LREAL_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_LREAL_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DINT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DINT.h new file mode 100644 index 000000000..b4dd61e73 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_DINT_H_ +#define _F_LREAL_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_DINT){ + }; + + virtual ~FORTE_F_LREAL_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DWORD.cpp new file mode 100644 index 000000000..bdcb0ffb6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_DWORD, g_nStringIdF_LREAL_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_LREAL_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DWORD.h new file mode 100644 index 000000000..a6810d9b6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_DWORD_H_ +#define _F_LREAL_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_DWORD){ + }; + + virtual ~FORTE_F_LREAL_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_INT.cpp new file mode 100644 index 000000000..6cff6874b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_INT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_INT, g_nStringIdF_LREAL_TO_INT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_LREAL_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_INT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_INT.h new file mode 100644 index 000000000..557f3c38e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_INT_H_ +#define _F_LREAL_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_INT){ + }; + + virtual ~FORTE_F_LREAL_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LINT.cpp new file mode 100644 index 000000000..7b2e58463 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_LINT, g_nStringIdF_LREAL_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_LREAL_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LINT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LINT.h new file mode 100644 index 000000000..150bc4527 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_LINT_H_ +#define _F_LREAL_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_LINT){ + }; + + virtual ~FORTE_F_LREAL_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LWORD.cpp new file mode 100644 index 000000000..740bf8846 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_LWORD, g_nStringIdF_LREAL_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_LREAL_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LWORD.h new file mode 100644 index 000000000..4876cd454 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_LWORD_H_ +#define _F_LREAL_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_LWORD){ + }; + + virtual ~FORTE_F_LREAL_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_REAL.cpp new file mode 100644 index 000000000..f4ca85b48 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_REAL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_REAL, g_nStringIdF_LREAL_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_LREAL_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_REAL.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_REAL.h new file mode 100644 index 000000000..a03d4cbff --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_REAL_H_ +#define _F_LREAL_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_REAL){ + }; + + virtual ~FORTE_F_LREAL_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_SINT.cpp new file mode 100644 index 000000000..ac157ac27 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_SINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_SINT, g_nStringIdF_LREAL_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_LREAL_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_SINT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_SINT.h new file mode 100644 index 000000000..dc6c7886c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_SINT_H_ +#define _F_LREAL_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_SINT){ + }; + + virtual ~FORTE_F_LREAL_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_STRING.cpp new file mode 100644 index 000000000..2980d29c3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_STRING, g_nStringIdF_LREAL_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_LREAL_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_STRING.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_STRING.h new file mode 100644 index 000000000..402d85b5b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_STRING_H_ +#define _F_LREAL_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_STRING){ + }; + + virtual ~FORTE_F_LREAL_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_TIME.cpp new file mode 100644 index 000000000..64882769f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_TIME, g_nStringIdF_LREAL_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_LREAL_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_TIME.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_TIME.h new file mode 100644 index 000000000..f51845b5d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_TIME_H_ +#define _F_LREAL_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_TIME){ + }; + + virtual ~FORTE_F_LREAL_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UDINT.cpp new file mode 100644 index 000000000..89ad46b61 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UDINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_UDINT, g_nStringIdF_LREAL_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_LREAL_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UDINT.h new file mode 100644 index 000000000..e1a74eaf9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_UDINT_H_ +#define _F_LREAL_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_UDINT){ + }; + + virtual ~FORTE_F_LREAL_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UINT.cpp new file mode 100644 index 000000000..46fcc032c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_LREAL_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_UINT, g_nStringIdF_LREAL_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_LREAL_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UINT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UINT.h new file mode 100644 index 000000000..4d34c17e3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_UINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_LREAL_TO_UINT_H_ +#define _F_LREAL_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_UINT){ + }; + + virtual ~FORTE_F_LREAL_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_ULINT.cpp new file mode 100644 index 000000000..6c3a93114 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_ULINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_ULINT, g_nStringIdF_LREAL_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_LREAL_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_ULINT.h new file mode 100644 index 000000000..36d7c3fca --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_ULINT_H_ +#define _F_LREAL_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_ULINT){ + }; + + virtual ~FORTE_F_LREAL_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_USINT.cpp new file mode 100644 index 000000000..6314cb70a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_USINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_USINT, g_nStringIdF_LREAL_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_LREAL_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_USINT.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_USINT.h new file mode 100644 index 000000000..11122ba56 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_USINT_H_ +#define _F_LREAL_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_USINT){ + }; + + virtual ~FORTE_F_LREAL_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WORD.cpp new file mode 100644 index 000000000..f262f1c60 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_WORD, g_nStringIdF_LREAL_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_LREAL_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WORD.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WORD.h new file mode 100644 index 000000000..65481f4a5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_WORD_H_ +#define _F_LREAL_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_WORD){ + }; + + virtual ~FORTE_F_LREAL_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WSTRING.cpp new file mode 100644 index 000000000..f3b8852a6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LREAL_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LREAL_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LREAL_TO_WSTRING, g_nStringIdF_LREAL_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdLREAL}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_LREAL_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LREAL_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LREAL_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LREAL_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LREAL_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LREAL_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LREAL_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LREAL_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WSTRING.h new file mode 100644 index 000000000..aee5fe3db --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LREAL/F_LREAL_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LREAL_TO_WSTRING_H_ +#define _F_LREAL_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_LREAL_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LREAL_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LREAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LREAL_TO_WSTRING){ + }; + + virtual ~FORTE_F_LREAL_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/LWORD/CMakeLists.txt new file mode 100644 index 000000000..a24c0f3de --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/CMakeLists.txt @@ -0,0 +1,40 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# LWORD_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_LWORD_TO_BOOL) +forte_add_sourcefile_hcpp(F_LWORD_TO_BYTE) +forte_add_sourcefile_hcpp(F_LWORD_TO_DINT) +forte_add_sourcefile_hcpp(F_LWORD_TO_DWORD) +forte_add_sourcefile_hcpp(F_LWORD_TO_INT) +forte_add_sourcefile_hcpp(F_LWORD_TO_LINT) +forte_add_sourcefile_hcpp(F_LWORD_TO_SINT) +forte_add_sourcefile_hcpp(F_LWORD_TO_UDINT) +forte_add_sourcefile_hcpp(F_LWORD_TO_UINT) +forte_add_sourcefile_hcpp(F_LWORD_TO_ULINT) +forte_add_sourcefile_hcpp(F_LWORD_TO_USINT) +forte_add_sourcefile_hcpp(F_LWORD_TO_WORD) +forte_add_sourcefile_hcpp(F_LWORD_TO_STRING) +forte_add_sourcefile_hcpp(F_LWORD_TO_TIME) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_LWORD_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_LWORD_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_LWORD_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BOOL.cpp new file mode 100644 index 000000000..82fcb6d18 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_BOOL, g_nStringIdF_LWORD_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_LWORD_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BOOL.h new file mode 100644 index 000000000..9d3038119 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_BOOL_H_ +#define _F_LWORD_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_BOOL){ + }; + + virtual ~FORTE_F_LWORD_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BYTE.cpp new file mode 100644 index 000000000..1c738f2ae --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_BYTE, g_nStringIdF_LWORD_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_LWORD_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BYTE.h new file mode 100644 index 000000000..f3ab6e1c9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_BYTE_H_ +#define _F_LWORD_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_BYTE){ + }; + + virtual ~FORTE_F_LWORD_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DINT.cpp new file mode 100644 index 000000000..9a1df1c45 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_DINT, g_nStringIdF_LWORD_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_LWORD_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DINT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DINT.h new file mode 100644 index 000000000..292f7a2ab --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_DINT_H_ +#define _F_LWORD_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_DINT){ + }; + + virtual ~FORTE_F_LWORD_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DWORD.cpp new file mode 100644 index 000000000..8c1dc6b26 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_DWORD, g_nStringIdF_LWORD_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_LWORD_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DWORD.h new file mode 100644 index 000000000..4b73e320a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_DWORD_H_ +#define _F_LWORD_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_DWORD){ + }; + + virtual ~FORTE_F_LWORD_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_INT.cpp new file mode 100644 index 000000000..e73e82b98 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_INT, g_nStringIdF_LWORD_TO_INT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_LWORD_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_INT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_INT.h new file mode 100644 index 000000000..d1c39dfa8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_INT_H_ +#define _F_LWORD_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_INT){ + }; + + virtual ~FORTE_F_LWORD_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LINT.cpp new file mode 100644 index 000000000..573a90c2e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_LINT, g_nStringIdF_LWORD_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_LWORD_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LINT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LINT.h new file mode 100644 index 000000000..c1cf5fb29 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_LINT_H_ +#define _F_LWORD_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_LINT){ + }; + + virtual ~FORTE_F_LWORD_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LREAL.cpp new file mode 100644 index 000000000..a80fcf042 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_LREAL, g_nStringIdF_LWORD_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_LWORD_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LREAL.h new file mode 100644 index 000000000..ab050579f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_LREAL_H_ +#define _F_LWORD_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_LREAL){ + }; + + virtual ~FORTE_F_LWORD_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_REAL.cpp new file mode 100644 index 000000000..6f0eea07b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_REAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_REAL, g_nStringIdF_LWORD_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_LWORD_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_REAL.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_REAL.h new file mode 100644 index 000000000..59b09d054 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_REAL_H_ +#define _F_LWORD_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_REAL){ + }; + + virtual ~FORTE_F_LWORD_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_SINT.cpp new file mode 100644 index 000000000..633df40c4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_SINT, g_nStringIdF_LWORD_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_LWORD_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_SINT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_SINT.h new file mode 100644 index 000000000..0d781b7d9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_SINT_H_ +#define _F_LWORD_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_SINT){ + }; + + virtual ~FORTE_F_LWORD_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_STRING.cpp new file mode 100644 index 000000000..d0e6e4661 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_STRING, g_nStringIdF_LWORD_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_LWORD_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_STRING.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_STRING.h new file mode 100644 index 000000000..66991f802 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_STRING_H_ +#define _F_LWORD_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_STRING){ + }; + + virtual ~FORTE_F_LWORD_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_TIME.cpp new file mode 100644 index 000000000..ba67bf22a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_TIME, g_nStringIdF_LWORD_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_LWORD_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_TIME.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_TIME.h new file mode 100644 index 000000000..b593e7977 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_TIME_H_ +#define _F_LWORD_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_TIME){ + }; + + virtual ~FORTE_F_LWORD_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UDINT.cpp new file mode 100644 index 000000000..954b93322 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_UDINT, g_nStringIdF_LWORD_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_LWORD_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UDINT.h new file mode 100644 index 000000000..7749f612c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_UDINT_H_ +#define _F_LWORD_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_UDINT){ + }; + + virtual ~FORTE_F_LWORD_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UINT.cpp new file mode 100644 index 000000000..ee7664f45 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_UINT, g_nStringIdF_LWORD_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_LWORD_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UINT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UINT.h new file mode 100644 index 000000000..1fec98524 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_UINT.h @@ -0,0 +1,61 @@ +/************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_UINT_H_ +#define _F_LWORD_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_UINT){ + }; + + virtual ~FORTE_F_LWORD_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_ULINT.cpp new file mode 100644 index 000000000..741774df7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_ULINT, g_nStringIdF_LWORD_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_LWORD_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_ULINT.h new file mode 100644 index 000000000..e470e6c4f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_ULINT_H_ +#define _F_LWORD_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_ULINT){ + }; + + virtual ~FORTE_F_LWORD_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_USINT.cpp new file mode 100644 index 000000000..a8923f4b0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_USINT, g_nStringIdF_LWORD_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_LWORD_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_USINT.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_USINT.h new file mode 100644 index 000000000..665467a45 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_USINT_H_ +#define _F_LWORD_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_USINT){ + }; + + virtual ~FORTE_F_LWORD_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WORD.cpp new file mode 100644 index 000000000..c7d3b3949 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_WORD, g_nStringIdF_LWORD_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_LWORD_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WORD.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WORD.h new file mode 100644 index 000000000..a28aa0cdd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_WORD_H_ +#define _F_LWORD_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_WORD){ + }; + + virtual ~FORTE_F_LWORD_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WSTRING.cpp new file mode 100644 index 000000000..95a6c3610 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LWORD_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LWORD_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_LWORD_TO_WSTRING, g_nStringIdF_LWORD_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdLWORD}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_LWORD_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LWORD_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LWORD_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LWORD_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LWORD_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LWORD_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LWORD_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = LWORD_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WSTRING.h new file mode 100644 index 000000000..7623ad393 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/LWORD/F_LWORD_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LWORD_TO_WSTRING_H_ +#define _F_LWORD_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_LWORD_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LWORD_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_LWORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LWORD_TO_WSTRING){ + }; + + virtual ~FORTE_F_LWORD_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/REAL/CMakeLists.txt new file mode 100644 index 000000000..c700a07a0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/CMakeLists.txt @@ -0,0 +1,40 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# REAL_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_REAL_TO_BOOL) +forte_add_sourcefile_hcpp(F_REAL_TO_BYTE) +forte_add_sourcefile_hcpp(F_REAL_TO_WORD) +forte_add_sourcefile_hcpp(F_REAL_TO_DWORD) +forte_add_sourcefile_hcpp(F_REAL_TO_DINT) +forte_add_sourcefile_hcpp(F_REAL_TO_SINT) +forte_add_sourcefile_hcpp(F_REAL_TO_USINT) +forte_add_sourcefile_hcpp(F_REAL_TO_INT) +forte_add_sourcefile_hcpp(F_REAL_TO_TIME) +forte_add_sourcefile_hcpp(F_REAL_TO_UDINT) +forte_add_sourcefile_hcpp(F_REAL_TO_UINT) +forte_add_sourcefile_hcpp(F_REAL_TO_STRING) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_REAL_TO_LINT) + forte_add_sourcefile_hcpp(F_REAL_TO_LWORD) + forte_add_sourcefile_hcpp(F_REAL_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_REAL_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_REAL_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BOOL.cpp new file mode 100644 index 000000000..a248c9817 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_BOOL, g_nStringIdF_REAL_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_REAL_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BOOL.h new file mode 100644 index 000000000..745a260d3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_BOOL_H_ +#define _F_REAL_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_BOOL){ + }; + + virtual ~FORTE_F_REAL_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BYTE.cpp new file mode 100644 index 000000000..3cff9748f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BYTE.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_BYTE, g_nStringIdF_REAL_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_REAL_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BYTE.h new file mode 100644 index 000000000..5483734fd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_BYTE_H_ +#define _F_REAL_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_BYTE){ + }; + + virtual ~FORTE_F_REAL_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DINT.cpp new file mode 100644 index 000000000..88ab929da --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_REAL_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_DINT, g_nStringIdF_REAL_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_REAL_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_DINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DINT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DINT.h new file mode 100644 index 000000000..2097a2192 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_REAL_TO_DINT_H_ +#define _F_REAL_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_DINT){ + }; + + virtual ~FORTE_F_REAL_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DWORD.cpp new file mode 100644 index 000000000..0db1d40fa --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_DWORD, g_nStringIdF_REAL_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_REAL_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DWORD.h new file mode 100644 index 000000000..2e325af6c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_DWORD_H_ +#define _F_REAL_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_DWORD){ + }; + + virtual ~FORTE_F_REAL_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_INT.cpp new file mode 100644 index 000000000..e7bf92154 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_INT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_REAL_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_INT, g_nStringIdF_REAL_TO_INT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_REAL_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_INT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_INT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_INT.h new file mode 100644 index 000000000..05575dba4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_INT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_REAL_TO_INT_H_ +#define _F_REAL_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_INT){ + }; + + virtual ~FORTE_F_REAL_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LINT.cpp new file mode 100644 index 000000000..b34dfe9fb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_LINT, g_nStringIdF_REAL_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_REAL_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LINT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LINT.h new file mode 100644 index 000000000..021a0d6bb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_LINT_H_ +#define _F_REAL_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_LINT){ + }; + + virtual ~FORTE_F_REAL_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LREAL.cpp new file mode 100644 index 000000000..f22a6b600 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LREAL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_LREAL, g_nStringIdF_REAL_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_REAL_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LREAL.h new file mode 100644 index 000000000..7bb05f03f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_LREAL_H_ +#define _F_REAL_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_LREAL){ + }; + + virtual ~FORTE_F_REAL_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LWORD.cpp new file mode 100644 index 000000000..23e06cc6f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_LWORD, g_nStringIdF_REAL_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_REAL_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LWORD.h new file mode 100644 index 000000000..6efdf4409 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_LWORD_H_ +#define _F_REAL_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_LWORD){ + }; + + virtual ~FORTE_F_REAL_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_SINT.cpp new file mode 100644 index 000000000..b9cdc86a5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_SINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_SINT, g_nStringIdF_REAL_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_REAL_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_SINT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_SINT.h new file mode 100644 index 000000000..398069fdf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_SINT_H_ +#define _F_REAL_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_SINT){ + }; + + virtual ~FORTE_F_REAL_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_STRING.cpp new file mode 100644 index 000000000..9af05da67 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_STRING, g_nStringIdF_REAL_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_REAL_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_STRING.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_STRING.h new file mode 100644 index 000000000..cfac797f8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_STRING_H_ +#define _F_REAL_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_STRING){ + }; + + virtual ~FORTE_F_REAL_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_TIME.cpp new file mode 100644 index 000000000..474e5960f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_TIME.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_TIME, g_nStringIdF_REAL_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_REAL_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_TIME::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_TIME.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_TIME.h new file mode 100644 index 000000000..2a9f2e246 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_TIME.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_REAL_TO_TIME_H_ +#define _F_REAL_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_TIME){ + }; + + virtual ~FORTE_F_REAL_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UDINT.cpp new file mode 100644 index 000000000..e43a66e93 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UDINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_REAL_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_UDINT, g_nStringIdF_REAL_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_REAL_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_UDINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UDINT.h new file mode 100644 index 000000000..9317fe1f1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UDINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_REAL_TO_UDINT_H_ +#define _F_REAL_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_UDINT){ + }; + + virtual ~FORTE_F_REAL_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UINT.cpp new file mode 100644 index 000000000..bacc1c522 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_REAL_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_UINT, g_nStringIdF_REAL_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_REAL_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_UINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UINT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UINT.h new file mode 100644 index 000000000..95ae1b92d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_UINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_REAL_TO_UINT_H_ +#define _F_REAL_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_UINT){ + }; + + virtual ~FORTE_F_REAL_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_ULINT.cpp new file mode 100644 index 000000000..4e64d45bb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_ULINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_ULINT, g_nStringIdF_REAL_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_REAL_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_ULINT.h new file mode 100644 index 000000000..dd467552f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_ULINT_H_ +#define _F_REAL_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_ULINT){ + }; + + virtual ~FORTE_F_REAL_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_USINT.cpp new file mode 100644 index 000000000..fcb397ac2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_USINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_USINT, g_nStringIdF_REAL_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_REAL_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_USINT.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_USINT.h new file mode 100644 index 000000000..1921420c5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_USINT_H_ +#define _F_REAL_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_USINT){ + }; + + virtual ~FORTE_F_REAL_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WORD.cpp new file mode 100644 index 000000000..0c7d1e91d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_WORD, g_nStringIdF_REAL_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_REAL_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WORD.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WORD.h new file mode 100644 index 000000000..c5ab173de --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_WORD_H_ +#define _F_REAL_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_WORD){ + }; + + virtual ~FORTE_F_REAL_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WSTRING.cpp new file mode 100644 index 000000000..14a0d4e40 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_REAL_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_REAL_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_REAL_TO_WSTRING, g_nStringIdF_REAL_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdREAL}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_REAL_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_REAL_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_REAL_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_REAL_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_REAL_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_REAL_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_REAL_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_REAL_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = REAL_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WSTRING.h new file mode 100644 index 000000000..6300e8c35 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/REAL/F_REAL_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_REAL_TO_WSTRING_H_ +#define _F_REAL_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_REAL_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_REAL_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_REAL_TO_WSTRING){ + }; + + virtual ~FORTE_F_REAL_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/SINT/CMakeLists.txt new file mode 100644 index 000000000..f251db0ec --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/CMakeLists.txt @@ -0,0 +1,44 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# SINT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_SINT_TO_BOOL) +forte_add_sourcefile_hcpp(F_SINT_TO_BYTE) +forte_add_sourcefile_hcpp(F_SINT_TO_DINT) +forte_add_sourcefile_hcpp(F_SINT_TO_DWORD) +forte_add_sourcefile_hcpp(F_SINT_TO_INT) +forte_add_sourcefile_hcpp(F_SINT_TO_UDINT) +forte_add_sourcefile_hcpp(F_SINT_TO_UINT) +forte_add_sourcefile_hcpp(F_SINT_TO_USINT) +forte_add_sourcefile_hcpp(F_SINT_TO_WORD) +forte_add_sourcefile_hcpp(F_SINT_TO_STRING) +forte_add_sourcefile_hcpp(F_SINT_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_SINT_TO_LINT) + forte_add_sourcefile_hcpp(F_SINT_TO_LWORD) + forte_add_sourcefile_hcpp(F_SINT_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_SINT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_SINT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_SINT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) + \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BOOL.cpp new file mode 100644 index 000000000..cac3554bf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_BOOL, g_nStringIdF_SINT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_SINT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BOOL.h new file mode 100644 index 000000000..4a1f2f5e3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_BOOL_H_ +#define _F_SINT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_BOOL){ + }; + + virtual ~FORTE_F_SINT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BYTE.cpp new file mode 100644 index 000000000..76736918e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_BYTE, g_nStringIdF_SINT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_SINT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BYTE.h new file mode 100644 index 000000000..c479dfdef --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_BYTE_H_ +#define _F_SINT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_BYTE){ + }; + + virtual ~FORTE_F_SINT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DINT.cpp new file mode 100644 index 000000000..11839c3ee --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_DINT, g_nStringIdF_SINT_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_SINT_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DINT.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DINT.h new file mode 100644 index 000000000..40e160cce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_DINT_H_ +#define _F_SINT_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_DINT){ + }; + + virtual ~FORTE_F_SINT_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DWORD.cpp new file mode 100644 index 000000000..be3d42cb7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_DWORD, g_nStringIdF_SINT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_SINT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DWORD.h new file mode 100644 index 000000000..c7d220eb8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_DWORD_H_ +#define _F_SINT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_DWORD){ + }; + + virtual ~FORTE_F_SINT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_INT.cpp new file mode 100644 index 000000000..e371327f1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_INT, g_nStringIdF_SINT_TO_INT) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_SINT_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_INT.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_INT.h new file mode 100644 index 000000000..1564c31a3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_INT_H_ +#define _F_SINT_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_INT){ + }; + + virtual ~FORTE_F_SINT_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LINT.cpp new file mode 100644 index 000000000..b43773eb7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_LINT, g_nStringIdF_SINT_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_SINT_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LINT.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LINT.h new file mode 100644 index 000000000..ee8c0ae32 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_LINT_H_ +#define _F_SINT_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_LINT){ + }; + + virtual ~FORTE_F_SINT_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LREAL.cpp new file mode 100644 index 000000000..e60678ae3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_LREAL, g_nStringIdF_SINT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_SINT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LREAL.h new file mode 100644 index 000000000..9707ce47c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_LREAL_H_ +#define _F_SINT_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_LREAL){ + }; + + virtual ~FORTE_F_SINT_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LWORD.cpp new file mode 100644 index 000000000..bbe48f7f3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_LWORD, g_nStringIdF_SINT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_SINT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LWORD.h new file mode 100644 index 000000000..6375bc0dd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_LWORD_H_ +#define _F_SINT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_LWORD){ + }; + + virtual ~FORTE_F_SINT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_REAL.cpp new file mode 100644 index 000000000..abb0615fe --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_REAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_REAL, g_nStringIdF_SINT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_SINT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_REAL.h new file mode 100644 index 000000000..132b768f0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_REAL_H_ +#define _F_SINT_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_REAL){ + }; + + virtual ~FORTE_F_SINT_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_STRING.cpp new file mode 100644 index 000000000..af84a555f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_STRING, g_nStringIdF_SINT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_SINT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_STRING.h new file mode 100644 index 000000000..1ae344a64 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_STRING_H_ +#define _F_SINT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_STRING){ + }; + + virtual ~FORTE_F_SINT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_TIME.cpp new file mode 100644 index 000000000..99f9228ac --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_TIME, g_nStringIdF_SINT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_SINT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_TIME.h new file mode 100644 index 000000000..160d2f5d4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_TIME_H_ +#define _F_SINT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_TIME){ + }; + + virtual ~FORTE_F_SINT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UDINT.cpp new file mode 100644 index 000000000..2a57ab783 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UDINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_UDINT, g_nStringIdF_SINT_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_SINT_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UDINT.h new file mode 100644 index 000000000..626ed2edf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_UDINT_H_ +#define _F_SINT_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_UDINT){ + }; + + virtual ~FORTE_F_SINT_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UINT.cpp new file mode 100644 index 000000000..813cfe289 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_UINT, g_nStringIdF_SINT_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_SINT_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UINT.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UINT.h new file mode 100644 index 000000000..67eb2b057 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_UINT_H_ +#define _F_SINT_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_UINT){ + }; + + virtual ~FORTE_F_SINT_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_ULINT.cpp new file mode 100644 index 000000000..780f9552f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_ULINT, g_nStringIdF_SINT_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_SINT_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_ULINT.h new file mode 100644 index 000000000..9f2f244bc --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_ULINT_H_ +#define _F_SINT_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_ULINT){ + }; + + virtual ~FORTE_F_SINT_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_USINT.cpp new file mode 100644 index 000000000..225afed5f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_USINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_USINT, g_nStringIdF_SINT_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_SINT_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_USINT.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_USINT.h new file mode 100644 index 000000000..0f3b73205 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_USINT_H_ +#define _F_SINT_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_USINT){ + }; + + virtual ~FORTE_F_SINT_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WORD.cpp new file mode 100644 index 000000000..843cc61b6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_WORD, g_nStringIdF_SINT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_SINT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WORD.h new file mode 100644 index 000000000..2d6ce4029 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_WORD_H_ +#define _F_SINT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_WORD){ + }; + + virtual ~FORTE_F_SINT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WSTRING.cpp new file mode 100644 index 000000000..116f920a7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SINT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SINT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_SINT_TO_WSTRING, g_nStringIdF_SINT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdSINT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SINT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_SINT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SINT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SINT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SINT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SINT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SINT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SINT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = SINT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WSTRING.h new file mode 100644 index 000000000..358f5ab6d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/SINT/F_SINT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SINT_TO_WSTRING_H_ +#define _F_SINT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_SINT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SINT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_SINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SINT_TO_WSTRING){ + }; + + virtual ~FORTE_F_SINT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/STRING/CMakeLists.txt new file mode 100644 index 000000000..df969414c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# STRING_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_STRING_TO_BOOL) +forte_add_sourcefile_hcpp(F_STRING_TO_BYTE) +forte_add_sourcefile_hcpp(F_STRING_TO_WORD) +forte_add_sourcefile_hcpp(F_STRING_TO_DWORD) +forte_add_sourcefile_hcpp(F_STRING_TO_INT) +forte_add_sourcefile_hcpp(F_STRING_TO_UINT) +forte_add_sourcefile_hcpp(F_STRING_TO_DINT) +forte_add_sourcefile_hcpp(F_STRING_TO_SINT) +forte_add_sourcefile_hcpp(F_STRING_TO_USINT) +forte_add_sourcefile_hcpp(F_STRING_TO_UDINT) +forte_add_sourcefile_hcpp(F_STRING_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_STRING_TO_LINT) + forte_add_sourcefile_hcpp(F_STRING_TO_LWORD) + forte_add_sourcefile_hcpp(F_STRING_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_STRING_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_STRING_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_STRING_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BOOL.cpp new file mode 100644 index 000000000..92609ee40 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BOOL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_BOOL, g_nStringIdF_STRING_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_STRING_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BOOL.h new file mode 100644 index 000000000..011841c8b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_BOOL_H_ +#define _F_STRING_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_BOOL){ + }; + + virtual ~FORTE_F_STRING_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BYTE.cpp new file mode 100644 index 000000000..b6e419c24 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BYTE.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_BYTE, g_nStringIdF_STRING_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_STRING_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BYTE.h new file mode 100644 index 000000000..3001d73ef --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_BYTE_H_ +#define _F_STRING_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_BYTE){ + }; + + virtual ~FORTE_F_STRING_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DINT.cpp new file mode 100644 index 000000000..ee46706ce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_DINT, g_nStringIdF_STRING_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_STRING_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DINT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DINT.h new file mode 100644 index 000000000..87f126aa6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_DINT_H_ +#define _F_STRING_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_DINT){ + }; + + virtual ~FORTE_F_STRING_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DWORD.cpp new file mode 100644 index 000000000..2cedca9d2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_DWORD, g_nStringIdF_STRING_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_STRING_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DWORD.h new file mode 100644 index 000000000..5c81a3fd0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_DWORD_H_ +#define _F_STRING_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_DWORD){ + }; + + virtual ~FORTE_F_STRING_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_INT.cpp new file mode 100644 index 000000000..efa852638 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 ACIN, fortis GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_INT, g_nStringIdF_STRING_TO_INT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_STRING_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_INT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_INT.h new file mode 100644 index 000000000..c235fa320 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_INT_H_ +#define _F_STRING_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_INT){ + }; + + virtual ~FORTE_F_STRING_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LINT.cpp new file mode 100644 index 000000000..c6a94d371 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_LINT, g_nStringIdF_STRING_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_STRING_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LINT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LINT.h new file mode 100644 index 000000000..aa9702c95 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_LINT_H_ +#define _F_STRING_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_LINT){ + }; + + virtual ~FORTE_F_STRING_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LREAL.cpp new file mode 100644 index 000000000..e826a4bf8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LREAL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_LREAL, g_nStringIdF_STRING_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_STRING_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LREAL.h new file mode 100644 index 000000000..221648b0a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_LREAL_H_ +#define _F_STRING_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_LREAL){ + }; + + virtual ~FORTE_F_STRING_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LWORD.cpp new file mode 100644 index 000000000..2c7b8520c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_LWORD, g_nStringIdF_STRING_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_STRING_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LWORD.h new file mode 100644 index 000000000..334546bb7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_LWORD_H_ +#define _F_STRING_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_LWORD){ + }; + + virtual ~FORTE_F_STRING_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_REAL.cpp new file mode 100644 index 000000000..19f77ab02 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_REAL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_REAL, g_nStringIdF_STRING_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_STRING_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_REAL.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_REAL.h new file mode 100644 index 000000000..f8dec1c48 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_REAL_H_ +#define _F_STRING_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_REAL){ + }; + + virtual ~FORTE_F_STRING_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_SINT.cpp new file mode 100644 index 000000000..f9b62e0d8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_SINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_SINT, g_nStringIdF_STRING_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_STRING_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_SINT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_SINT.h new file mode 100644 index 000000000..898925417 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_SINT_H_ +#define _F_STRING_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_SINT){ + }; + + virtual ~FORTE_F_STRING_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_TIME.cpp new file mode 100644 index 000000000..2764dedb9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_TIME, g_nStringIdF_STRING_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_STRING_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_TIME.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_TIME.h new file mode 100644 index 000000000..971d36564 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_TIME_H_ +#define _F_STRING_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_TIME){ + }; + + virtual ~FORTE_F_STRING_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UDINT.cpp new file mode 100644 index 000000000..ea2502a7c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UDINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_UDINT, g_nStringIdF_STRING_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_STRING_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UDINT.h new file mode 100644 index 000000000..09a98a167 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_UDINT_H_ +#define _F_STRING_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_UDINT){ + }; + + virtual ~FORTE_F_STRING_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UINT.cpp new file mode 100644 index 000000000..621b5af32 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_UINT, g_nStringIdF_STRING_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_STRING_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UINT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UINT.h new file mode 100644 index 000000000..74c5bba60 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_UINT_H_ +#define _F_STRING_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_UINT){ + }; + + virtual ~FORTE_F_STRING_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_ULINT.cpp new file mode 100644 index 000000000..a9f82933f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_ULINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_ULINT, g_nStringIdF_STRING_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_STRING_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_ULINT.h new file mode 100644 index 000000000..27cbb67b7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_ULINT_H_ +#define _F_STRING_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_ULINT){ + }; + + virtual ~FORTE_F_STRING_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_USINT.cpp new file mode 100644 index 000000000..650ed5e4c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_USINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_USINT, g_nStringIdF_STRING_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_STRING_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_USINT.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_USINT.h new file mode 100644 index 000000000..34ccb6f59 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_USINT_H_ +#define _F_STRING_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_USINT){ + }; + + virtual ~FORTE_F_STRING_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WORD.cpp new file mode 100644 index 000000000..06b35881d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_WORD, g_nStringIdF_STRING_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_STRING_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WORD.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WORD.h new file mode 100644 index 000000000..d8217fb90 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_WORD_H_ +#define _F_STRING_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_WORD){ + }; + + virtual ~FORTE_F_STRING_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WSTRING.cpp new file mode 100644 index 000000000..70bdbf6f4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_STRING_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_STRING_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_STRING_TO_WSTRING, g_nStringIdF_STRING_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_STRING_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_STRING_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_STRING_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_STRING_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_STRING_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_STRING_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_STRING_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_STRING_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = STRING_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WSTRING.h new file mode 100644 index 000000000..3b121c7af --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/STRING/F_STRING_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_STRING_TO_WSTRING_H_ +#define _F_STRING_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_STRING_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_STRING_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_STRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_STRING_TO_WSTRING){ + }; + + virtual ~FORTE_F_STRING_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/TIME/CMakeLists.txt new file mode 100644 index 000000000..13836992a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# TIME_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_TIME_TO_BOOL) +forte_add_sourcefile_hcpp(F_TIME_TO_BYTE) +forte_add_sourcefile_hcpp(F_TIME_TO_WORD) +forte_add_sourcefile_hcpp(F_TIME_TO_INT) +forte_add_sourcefile_hcpp(F_TIME_TO_UINT) +forte_add_sourcefile_hcpp(F_TIME_TO_SINT) +forte_add_sourcefile_hcpp(F_TIME_TO_USINT) +forte_add_sourcefile_hcpp(F_TIME_TO_DINT) +forte_add_sourcefile_hcpp(F_TIME_TO_DWORD) +forte_add_sourcefile_hcpp(F_TIME_TO_UDINT) +forte_add_sourcefile_hcpp(F_TIME_TO_STRING) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_TIME_TO_LINT) + forte_add_sourcefile_hcpp(F_TIME_TO_LWORD) + forte_add_sourcefile_hcpp(F_TIME_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_TIME_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_TIME_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_TIME_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BOOL.cpp new file mode 100644 index 000000000..d6d8c035c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BOOL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_BOOL, g_nStringIdF_TIME_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_TIME_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BOOL.h new file mode 100644 index 000000000..2563b4691 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_BOOL_H_ +#define _F_TIME_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_BOOL){ + }; + + virtual ~FORTE_F_TIME_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BYTE.cpp new file mode 100644 index 000000000..33e5a1fce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BYTE.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_BYTE, g_nStringIdF_TIME_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_TIME_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BYTE.h new file mode 100644 index 000000000..59e53acc8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_BYTE_H_ +#define _F_TIME_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_BYTE){ + }; + + virtual ~FORTE_F_TIME_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DINT.cpp new file mode 100644 index 000000000..d2a35cacb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_DINT, g_nStringIdF_TIME_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_TIME_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DINT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DINT.h new file mode 100644 index 000000000..7fe5b407d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_DINT_H_ +#define _F_TIME_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_DINT){ + }; + + virtual ~FORTE_F_TIME_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DWORD.cpp new file mode 100644 index 000000000..abd66a830 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_TIME_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_DWORD, g_nStringIdF_TIME_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_TIME_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_DWORD::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DWORD.h new file mode 100644 index 000000000..b9b44b762 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_DWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_TIME_TO_DWORD_H_ +#define _F_TIME_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_DWORD){ + }; + + virtual ~FORTE_F_TIME_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_INT.cpp new file mode 100644 index 000000000..528f1eeb4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_INT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_INT, g_nStringIdF_TIME_TO_INT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_TIME_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_INT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_INT.h new file mode 100644 index 000000000..016bf953e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_INT_H_ +#define _F_TIME_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_INT){ + }; + + virtual ~FORTE_F_TIME_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LINT.cpp new file mode 100644 index 000000000..aafeafd44 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_LINT, g_nStringIdF_TIME_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_TIME_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LINT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LINT.h new file mode 100644 index 000000000..998cf4621 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_LINT_H_ +#define _F_TIME_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_LINT){ + }; + + virtual ~FORTE_F_TIME_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LREAL.cpp new file mode 100644 index 000000000..f2dab0612 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LREAL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_LREAL, g_nStringIdF_TIME_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_TIME_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LREAL.h new file mode 100644 index 000000000..e81790e7b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_LREAL_H_ +#define _F_TIME_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_LREAL){ + }; + + virtual ~FORTE_F_TIME_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LWORD.cpp new file mode 100644 index 000000000..4a64b8475 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_LWORD, g_nStringIdF_TIME_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_TIME_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LWORD.h new file mode 100644 index 000000000..72267c4fb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_LWORD_H_ +#define _F_TIME_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_LWORD){ + }; + + virtual ~FORTE_F_TIME_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_REAL.cpp new file mode 100644 index 000000000..5108d9e45 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_REAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_TIME_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_REAL, g_nStringIdF_TIME_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_TIME_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_REAL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_REAL.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_REAL.h new file mode 100644 index 000000000..1a4a2e06e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_REAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_TIME_TO_REAL_H_ +#define _F_TIME_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_REAL){ + }; + + virtual ~FORTE_F_TIME_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_SINT.cpp new file mode 100644 index 000000000..fc764dc8f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_SINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_SINT, g_nStringIdF_TIME_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_TIME_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_SINT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_SINT.h new file mode 100644 index 000000000..5ffa6db2a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_SINT_H_ +#define _F_TIME_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_SINT){ + }; + + virtual ~FORTE_F_TIME_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_STRING.cpp new file mode 100644 index 000000000..9776fe40b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_STRING, g_nStringIdF_TIME_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_TIME_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_STRING.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_STRING.h new file mode 100644 index 000000000..c1b2a43b5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_STRING_H_ +#define _F_TIME_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_STRING){ + }; + + virtual ~FORTE_F_TIME_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UDINT.cpp new file mode 100644 index 000000000..c7c675c8e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UDINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_TIME_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_UDINT, g_nStringIdF_TIME_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_TIME_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_UDINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UDINT.h new file mode 100644 index 000000000..99a5d0c0a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UDINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_TIME_TO_UDINT_H_ +#define _F_TIME_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_UDINT){ + }; + + virtual ~FORTE_F_TIME_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UINT.cpp new file mode 100644 index 000000000..b3a8c3e5b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UINT.cpp @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2011 -2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_TIME_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_UINT, g_nStringIdF_TIME_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_TIME_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UINT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UINT.h new file mode 100644 index 000000000..a79e313ab --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_UINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_TIME_TO_UINT_H_ +#define _F_TIME_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_UINT){ + }; + + virtual ~FORTE_F_TIME_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_ULINT.cpp new file mode 100644 index 000000000..43a29072d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_ULINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_ULINT, g_nStringIdF_TIME_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_TIME_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_ULINT.h new file mode 100644 index 000000000..0c451ff63 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_ULINT_H_ +#define _F_TIME_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_ULINT){ + }; + + virtual ~FORTE_F_TIME_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_USINT.cpp new file mode 100644 index 000000000..1d61fd6d3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_USINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_USINT, g_nStringIdF_TIME_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_TIME_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_USINT.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_USINT.h new file mode 100644 index 000000000..eb2e53cf0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_USINT_H_ +#define _F_TIME_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_USINT){ + }; + + virtual ~FORTE_F_TIME_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WORD.cpp new file mode 100644 index 000000000..b572a53cd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_WORD, g_nStringIdF_TIME_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_TIME_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WORD.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WORD.h new file mode 100644 index 000000000..e1dafcdd6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_WORD_H_ +#define _F_TIME_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_WORD){ + }; + + virtual ~FORTE_F_TIME_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WSTRING.cpp new file mode 100644 index 000000000..8180f3e34 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TIME_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TIME_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_TIME_TO_WSTRING, g_nStringIdF_TIME_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TIME_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_TIME_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TIME_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TIME_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TIME_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TIME_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TIME_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TIME_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = TIME_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WSTRING.h new file mode 100644 index 000000000..668a8cec3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/TIME/F_TIME_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TIME_TO_WSTRING_H_ +#define _F_TIME_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_TIME_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TIME_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TIME_TO_WSTRING){ + }; + + virtual ~FORTE_F_TIME_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/UDINT/CMakeLists.txt new file mode 100644 index 000000000..b19a7620d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# UDINT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_UDINT_TO_BOOL) +forte_add_sourcefile_hcpp(F_UDINT_TO_BYTE) +forte_add_sourcefile_hcpp(F_UDINT_TO_DINT) +forte_add_sourcefile_hcpp(F_UDINT_TO_DWORD) +forte_add_sourcefile_hcpp(F_UDINT_TO_INT) +forte_add_sourcefile_hcpp(F_UDINT_TO_SINT) +forte_add_sourcefile_hcpp(F_UDINT_TO_UINT) +forte_add_sourcefile_hcpp(F_UDINT_TO_WORD) +forte_add_sourcefile_hcpp(F_UDINT_TO_STRING) +#forte_add_sourcefile_hcpp(F_UDINT_TO_UDINT) +forte_add_sourcefile_hcpp(F_UDINT_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_UDINT_TO_LINT) + forte_add_sourcefile_hcpp(F_UDINT_TO_LWORD) + forte_add_sourcefile_hcpp(F_UDINT_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_UDINT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_UDINT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_UDINT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BOOL.cpp new file mode 100644 index 000000000..b9cd1a3b9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_BOOL, g_nStringIdF_UDINT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_UDINT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BOOL.h new file mode 100644 index 000000000..23b88f0ee --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_BOOL_H_ +#define _F_UDINT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_BOOL){ + }; + + virtual ~FORTE_F_UDINT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BYTE.cpp new file mode 100644 index 000000000..8056db31c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BYTE.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_BYTE, g_nStringIdF_UDINT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_UDINT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BYTE.h new file mode 100644 index 000000000..ffa7f9236 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_BYTE_H_ +#define _F_UDINT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_BYTE){ + }; + + virtual ~FORTE_F_UDINT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DINT.cpp new file mode 100644 index 000000000..b47a8bf53 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_DINT, g_nStringIdF_UDINT_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_UDINT_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DINT.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DINT.h new file mode 100644 index 000000000..56d008b61 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_DINT_H_ +#define _F_UDINT_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_DINT){ + }; + + virtual ~FORTE_F_UDINT_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DWORD.cpp new file mode 100644 index 000000000..bf16f0c98 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_DWORD, g_nStringIdF_UDINT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_UDINT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DWORD.h new file mode 100644 index 000000000..500106343 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_DWORD_H_ +#define _F_UDINT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_DWORD){ + }; + + virtual ~FORTE_F_UDINT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_INT.cpp new file mode 100644 index 000000000..d1289deab --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_INT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_INT, g_nStringIdF_UDINT_TO_INT) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_UDINT_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_INT.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_INT.h new file mode 100644 index 000000000..1f5dc6bce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_INT_H_ +#define _F_UDINT_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_INT){ + }; + + virtual ~FORTE_F_UDINT_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LINT.cpp new file mode 100644 index 000000000..abe684b37 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_LINT, g_nStringIdF_UDINT_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_UDINT_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LINT.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LINT.h new file mode 100644 index 000000000..448fea977 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_LINT_H_ +#define _F_UDINT_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_LINT){ + }; + + virtual ~FORTE_F_UDINT_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LREAL.cpp new file mode 100644 index 000000000..511921328 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LREAL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_LREAL, g_nStringIdF_UDINT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_UDINT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LREAL.h new file mode 100644 index 000000000..f79cd9dc8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_LREAL_H_ +#define _F_UDINT_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_LREAL){ + }; + + virtual ~FORTE_F_UDINT_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LWORD.cpp new file mode 100644 index 000000000..53409b564 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LWORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_LWORD, g_nStringIdF_UDINT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_UDINT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LWORD.h new file mode 100644 index 000000000..162bafffd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_LWORD_H_ +#define _F_UDINT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_LWORD){ + }; + + virtual ~FORTE_F_UDINT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_REAL.cpp new file mode 100644 index 000000000..b62ec36eb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_REAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UDINT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_REAL, g_nStringIdF_UDINT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_UDINT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_REAL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_REAL.h new file mode 100644 index 000000000..7b692b3dd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_REAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UDINT_TO_REAL_H_ +#define _F_UDINT_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_REAL){ + }; + + virtual ~FORTE_F_UDINT_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_SINT.cpp new file mode 100644 index 000000000..958429fc7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_SINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_SINT, g_nStringIdF_UDINT_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_UDINT_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_SINT.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_SINT.h new file mode 100644 index 000000000..3706379e5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_SINT_H_ +#define _F_UDINT_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_SINT){ + }; + + virtual ~FORTE_F_UDINT_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_STRING.cpp new file mode 100644 index 000000000..e19e99557 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_STRING, g_nStringIdF_UDINT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_UDINT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_STRING.h new file mode 100644 index 000000000..2ceff40d7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_STRING_H_ +#define _F_UDINT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_STRING){ + }; + + virtual ~FORTE_F_UDINT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_TIME.cpp new file mode 100644 index 000000000..7719c16ce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_TIME, g_nStringIdF_UDINT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_UDINT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_TIME.h new file mode 100644 index 000000000..feae44d06 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_TIME_H_ +#define _F_UDINT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_TIME){ + }; + + virtual ~FORTE_F_UDINT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_UINT.cpp new file mode 100644 index 000000000..7a1c99954 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_UINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_UINT, g_nStringIdF_UDINT_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_UDINT_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_UINT.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_UINT.h new file mode 100644 index 000000000..b15c0f003 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_UINT_H_ +#define _F_UDINT_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_UINT){ + }; + + virtual ~FORTE_F_UDINT_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_ULINT.cpp new file mode 100644 index 000000000..9b9e90bd2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_ULINT.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_ULINT, g_nStringIdF_UDINT_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_UDINT_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_ULINT.h new file mode 100644 index 000000000..87129e112 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_ULINT_H_ +#define _F_UDINT_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_ULINT){ + }; + + virtual ~FORTE_F_UDINT_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_USINT.cpp new file mode 100644 index 000000000..e58907373 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_USINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_USINT.h" + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_USINT, g_nStringIdF_UDINT_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_UDINT_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_USINT.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_USINT.h new file mode 100644 index 000000000..781b5f5d3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_USINT_H_ +#define _F_UDINT_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_USINT){ + }; + + virtual ~FORTE_F_UDINT_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WORD.cpp new file mode 100644 index 000000000..ad7f30011 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WORD.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_WORD, g_nStringIdF_UDINT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_UDINT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WORD.h new file mode 100644 index 000000000..0eb3b5f83 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_WORD_H_ +#define _F_UDINT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_WORD){ + }; + + virtual ~FORTE_F_UDINT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WSTRING.cpp new file mode 100644 index 000000000..2fce4c168 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UDINT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UDINT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UDINT_TO_WSTRING, g_nStringIdF_UDINT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdUDINT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_UDINT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UDINT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UDINT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UDINT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UDINT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UDINT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UDINT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UDINT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WSTRING.h new file mode 100644 index 000000000..b7d2f3dcf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UDINT/F_UDINT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UDINT_TO_WSTRING_H_ +#define _F_UDINT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_UDINT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UDINT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UDINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UDINT_TO_WSTRING){ + }; + + virtual ~FORTE_F_UDINT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/UINT/CMakeLists.txt new file mode 100644 index 000000000..cb423433b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# UINT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_UINT_TO_BOOL) +forte_add_sourcefile_hcpp(F_UINT_TO_BYTE) +forte_add_sourcefile_hcpp(F_UINT_TO_DINT) +forte_add_sourcefile_hcpp(F_UINT_TO_DWORD) +forte_add_sourcefile_hcpp(F_UINT_TO_INT) +forte_add_sourcefile_hcpp(F_UINT_TO_SINT) +forte_add_sourcefile_hcpp(F_UINT_TO_UDINT) +forte_add_sourcefile_hcpp(F_UINT_TO_USINT) +forte_add_sourcefile_hcpp(F_UINT_TO_WORD) +forte_add_sourcefile_hcpp(F_UINT_TO_STRING) +forte_add_sourcefile_hcpp(F_UINT_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_UINT_TO_LINT) + forte_add_sourcefile_hcpp(F_UINT_TO_LWORD) + forte_add_sourcefile_hcpp(F_UINT_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_UINT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_UINT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_UINT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BOOL.cpp new file mode 100644 index 000000000..6df1c4e32 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UINT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_BOOL, g_nStringIdF_UINT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_UINT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BOOL.h new file mode 100644 index 000000000..cfe22a97a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UINT_TO_BOOL_H_ +#define _F_UINT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_BOOL){ + }; + + virtual ~FORTE_F_UINT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BYTE.cpp new file mode 100644 index 000000000..d12659eb4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BYTE.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_BYTE, g_nStringIdF_UINT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_UINT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BYTE.h new file mode 100644 index 000000000..53ac2d9e9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_BYTE.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_BYTE_H_ +#define _F_UINT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_BYTE){ + }; + + virtual ~FORTE_F_UINT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DINT.cpp new file mode 100644 index 000000000..826dc2c05 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_DINT, g_nStringIdF_UINT_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_UINT_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DINT.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DINT.h new file mode 100644 index 000000000..2b389be98 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_DINT_H_ +#define _F_UINT_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_DINT){ + }; + + virtual ~FORTE_F_UINT_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DWORD.cpp new file mode 100644 index 000000000..4c7de3c9a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_DWORD, g_nStringIdF_UINT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_UINT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DWORD.h new file mode 100644 index 000000000..fa1e4996b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_DWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_DWORD_H_ +#define _F_UINT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_DWORD){ + }; + + virtual ~FORTE_F_UINT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_INT.cpp new file mode 100644 index 000000000..668b29aba --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_INT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_INT, g_nStringIdF_UINT_TO_INT) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_UINT_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_INT.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_INT.h new file mode 100644 index 000000000..1416a35b1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_INT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_INT_H_ +#define _F_UINT_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_INT){ + }; + + virtual ~FORTE_F_UINT_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LINT.cpp new file mode 100644 index 000000000..fe3a502b0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_LINT, g_nStringIdF_UINT_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_UINT_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LINT.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LINT.h new file mode 100644 index 000000000..27addc0c6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_LINT_H_ +#define _F_UINT_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_LINT){ + }; + + virtual ~FORTE_F_UINT_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LREAL.cpp new file mode 100644 index 000000000..687f3f116 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LREAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_LREAL, g_nStringIdF_UINT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_UINT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LREAL.h new file mode 100644 index 000000000..59731e577 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LREAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_LREAL_H_ +#define _F_UINT_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_LREAL){ + }; + + virtual ~FORTE_F_UINT_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LWORD.cpp new file mode 100644 index 000000000..61f1aa5ee --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_LWORD, g_nStringIdF_UINT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_UINT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LWORD.h new file mode 100644 index 000000000..8998512f5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_LWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_LWORD_H_ +#define _F_UINT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_LWORD){ + }; + + virtual ~FORTE_F_UINT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_REAL.cpp new file mode 100644 index 000000000..1aa910288 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_REAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_REAL, g_nStringIdF_UINT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_UINT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_REAL.h new file mode 100644 index 000000000..918dd0187 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_REAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_REAL_H_ +#define _F_UINT_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_REAL){ + }; + + virtual ~FORTE_F_UINT_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_SINT.cpp new file mode 100644 index 000000000..57542e5c9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_SINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_SINT, g_nStringIdF_UINT_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_UINT_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_SINT.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_SINT.h new file mode 100644 index 000000000..ed0741bef --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_SINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_SINT_H_ +#define _F_UINT_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_SINT){ + }; + + virtual ~FORTE_F_UINT_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_STRING.cpp new file mode 100644 index 000000000..d15aa8af0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UINT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_STRING, g_nStringIdF_UINT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_UINT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_STRING.h new file mode 100644 index 000000000..74038cdf6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UINT_TO_STRING_H_ +#define _F_UINT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_STRING){ + }; + + virtual ~FORTE_F_UINT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_TIME.cpp new file mode 100644 index 000000000..d57a6b445 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UINT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_TIME, g_nStringIdF_UINT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_UINT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_TIME.h new file mode 100644 index 000000000..d48748951 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UINT_TO_TIME_H_ +#define _F_UINT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_TIME){ + }; + + virtual ~FORTE_F_UINT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_UDINT.cpp new file mode 100644 index 000000000..ce450056e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_UDINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_UDINT, g_nStringIdF_UINT_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_UINT_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_UDINT.h new file mode 100644 index 000000000..fe072a471 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_UDINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_UDINT_H_ +#define _F_UINT_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_UDINT){ + }; + + virtual ~FORTE_F_UINT_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_ULINT.cpp new file mode 100644 index 000000000..1fa31e6b6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_ULINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_ULINT, g_nStringIdF_UINT_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_UINT_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_ULINT.h new file mode 100644 index 000000000..4f5d0b135 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_ULINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_ULINT_H_ +#define _F_UINT_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_ULINT){ + }; + + virtual ~FORTE_F_UINT_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_USINT.cpp new file mode 100644 index 000000000..74a0db523 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_USINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_USINT, g_nStringIdF_UINT_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_UINT_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_USINT.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_USINT.h new file mode 100644 index 000000000..7572a9d82 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_USINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_USINT_H_ +#define _F_UINT_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_USINT){ + }; + + virtual ~FORTE_F_UINT_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WORD.cpp new file mode 100644 index 000000000..e53f3985f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_UINT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_WORD, g_nStringIdF_UINT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_UINT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WORD.h new file mode 100644 index 000000000..9f1709f1e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_UINT_TO_WORD_H_ +#define _F_UINT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_WORD){ + }; + + virtual ~FORTE_F_UINT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WSTRING.cpp new file mode 100644 index 000000000..d2e8d5e4b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_UINT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_UINT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_UINT_TO_WSTRING, g_nStringIdF_UINT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_UINT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_UINT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_UINT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_UINT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_UINT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_UINT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_UINT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_UINT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = UINT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WSTRING.h new file mode 100644 index 000000000..0249e897e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/UINT/F_UINT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_UINT_TO_WSTRING_H_ +#define _F_UINT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_UINT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_UINT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_UINT_TO_WSTRING){ + }; + + virtual ~FORTE_F_UINT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/ULINT/CMakeLists.txt new file mode 100644 index 000000000..1ab2073e8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/CMakeLists.txt @@ -0,0 +1,40 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# ULINT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_ULINT_TO_BOOL) +forte_add_sourcefile_hcpp(F_ULINT_TO_BYTE) +forte_add_sourcefile_hcpp(F_ULINT_TO_DINT) +forte_add_sourcefile_hcpp(F_ULINT_TO_DWORD) +forte_add_sourcefile_hcpp(F_ULINT_TO_INT) +forte_add_sourcefile_hcpp(F_ULINT_TO_LINT) +forte_add_sourcefile_hcpp(F_ULINT_TO_LWORD) +forte_add_sourcefile_hcpp(F_ULINT_TO_SINT) +forte_add_sourcefile_hcpp(F_ULINT_TO_UDINT) +forte_add_sourcefile_hcpp(F_ULINT_TO_UINT) +forte_add_sourcefile_hcpp(F_ULINT_TO_USINT) +forte_add_sourcefile_hcpp(F_ULINT_TO_WORD) +forte_add_sourcefile_hcpp(F_ULINT_TO_STRING) +forte_add_sourcefile_hcpp(F_ULINT_TO_TIME) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_ULINT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_ULINT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_ULINT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BOOL.cpp new file mode 100644 index 000000000..1d8e76c94 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ULINT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_BOOL, g_nStringIdF_ULINT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_ULINT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BOOL.h new file mode 100644 index 000000000..58ed19fa1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ULINT_TO_BOOL_H_ +#define _F_ULINT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_BOOL){ + }; + + virtual ~FORTE_F_ULINT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BYTE.cpp new file mode 100644 index 000000000..4ba2783ab --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BYTE.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_BYTE, g_nStringIdF_ULINT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_ULINT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BYTE.h new file mode 100644 index 000000000..b7a8af056 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_BYTE.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_BYTE_H_ +#define _F_ULINT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_BYTE){ + }; + + virtual ~FORTE_F_ULINT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DINT.cpp new file mode 100644 index 000000000..038744d5f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_DINT, g_nStringIdF_ULINT_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_ULINT_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DINT.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DINT.h new file mode 100644 index 000000000..a0b7fd095 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_DINT_H_ +#define _F_ULINT_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_DINT){ + }; + + virtual ~FORTE_F_ULINT_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DWORD.cpp new file mode 100644 index 000000000..75d7c4634 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_DWORD, g_nStringIdF_ULINT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_ULINT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DWORD.h new file mode 100644 index 000000000..95db184cf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_DWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_DWORD_H_ +#define _F_ULINT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_DWORD){ + }; + + virtual ~FORTE_F_ULINT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_INT.cpp new file mode 100644 index 000000000..c660ddff1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_INT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_INT, g_nStringIdF_ULINT_TO_INT) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_ULINT_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_INT.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_INT.h new file mode 100644 index 000000000..75f439893 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_INT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_INT_H_ +#define _F_ULINT_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_INT){ + }; + + virtual ~FORTE_F_ULINT_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LINT.cpp new file mode 100644 index 000000000..2826fbc26 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_LINT, g_nStringIdF_ULINT_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_ULINT_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LINT.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LINT.h new file mode 100644 index 000000000..fc1db3a13 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_LINT_H_ +#define _F_ULINT_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_LINT){ + }; + + virtual ~FORTE_F_ULINT_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LREAL.cpp new file mode 100644 index 000000000..554a13c38 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LREAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_LREAL, g_nStringIdF_ULINT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_ULINT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LREAL.h new file mode 100644 index 000000000..881674182 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LREAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_LREAL_H_ +#define _F_ULINT_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_LREAL){ + }; + + virtual ~FORTE_F_ULINT_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LWORD.cpp new file mode 100644 index 000000000..6faedd49f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_LWORD, g_nStringIdF_ULINT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_ULINT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LWORD.h new file mode 100644 index 000000000..c37dae96b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_LWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_LWORD_H_ +#define _F_ULINT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_LWORD){ + }; + + virtual ~FORTE_F_ULINT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_REAL.cpp new file mode 100644 index 000000000..5b8c6db00 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_REAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_REAL, g_nStringIdF_ULINT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_ULINT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_REAL.h new file mode 100644 index 000000000..011ce4e7a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_REAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_REAL_H_ +#define _F_ULINT_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_REAL){ + }; + + virtual ~FORTE_F_ULINT_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_SINT.cpp new file mode 100644 index 000000000..48b5fdf56 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_SINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_SINT, g_nStringIdF_ULINT_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_ULINT_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_SINT.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_SINT.h new file mode 100644 index 000000000..7389fc790 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_SINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_SINT_H_ +#define _F_ULINT_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_SINT){ + }; + + virtual ~FORTE_F_ULINT_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_STRING.cpp new file mode 100644 index 000000000..4370e9706 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ULINT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_STRING, g_nStringIdF_ULINT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_ULINT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_STRING.h new file mode 100644 index 000000000..ff9442f28 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ULINT_TO_STRING_H_ +#define _F_ULINT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_STRING){ + }; + + virtual ~FORTE_F_ULINT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_TIME.cpp new file mode 100644 index 000000000..184d36e9c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ULINT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_TIME, g_nStringIdF_ULINT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_ULINT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_TIME.h new file mode 100644 index 000000000..9330fa691 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ULINT_TO_TIME_H_ +#define _F_ULINT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_TIME){ + }; + + virtual ~FORTE_F_ULINT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UDINT.cpp new file mode 100644 index 000000000..f77bf0e5f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UDINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_UDINT, g_nStringIdF_ULINT_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_ULINT_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UDINT.h new file mode 100644 index 000000000..7b9177e4f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UDINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_UDINT_H_ +#define _F_ULINT_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_UDINT){ + }; + + virtual ~FORTE_F_ULINT_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UINT.cpp new file mode 100644 index 000000000..68aadc247 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_UINT, g_nStringIdF_ULINT_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_ULINT_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UINT.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UINT.h new file mode 100644 index 000000000..17ede037e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_UINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_UINT_H_ +#define _F_ULINT_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_UINT){ + }; + + virtual ~FORTE_F_ULINT_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_USINT.cpp new file mode 100644 index 000000000..3dfd23c98 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_USINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_USINT, g_nStringIdF_ULINT_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_ULINT_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_USINT.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_USINT.h new file mode 100644 index 000000000..a203f4fee --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_USINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_USINT_H_ +#define _F_ULINT_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_USINT){ + }; + + virtual ~FORTE_F_ULINT_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WORD.cpp new file mode 100644 index 000000000..49848788e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_ULINT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_WORD, g_nStringIdF_ULINT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_ULINT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WORD.h new file mode 100644 index 000000000..fd3ae59c6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_ULINT_TO_WORD_H_ +#define _F_ULINT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_WORD){ + }; + + virtual ~FORTE_F_ULINT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WSTRING.cpp new file mode 100644 index 000000000..8c3499b36 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ULINT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ULINT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_ULINT_TO_WSTRING, g_nStringIdF_ULINT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdULINT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_ULINT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ULINT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ULINT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ULINT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ULINT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ULINT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ULINT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = ULINT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WSTRING.h new file mode 100644 index 000000000..13ee420bc --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/ULINT/F_ULINT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ULINT_TO_WSTRING_H_ +#define _F_ULINT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_ULINT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ULINT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ULINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ULINT_TO_WSTRING){ + }; + + virtual ~FORTE_F_ULINT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/USINT/CMakeLists.txt new file mode 100644 index 000000000..5ce5d4177 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# USINT_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_USINT_TO_BOOL) +forte_add_sourcefile_hcpp(F_USINT_TO_BYTE) +forte_add_sourcefile_hcpp(F_USINT_TO_DINT) +forte_add_sourcefile_hcpp(F_USINT_TO_DWORD) +forte_add_sourcefile_hcpp(F_USINT_TO_INT) +forte_add_sourcefile_hcpp(F_USINT_TO_SINT) +forte_add_sourcefile_hcpp(F_USINT_TO_UDINT) +forte_add_sourcefile_hcpp(F_USINT_TO_UINT) +forte_add_sourcefile_hcpp(F_USINT_TO_WORD) +forte_add_sourcefile_hcpp(F_USINT_TO_STRING) +forte_add_sourcefile_hcpp(F_USINT_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_USINT_TO_ULINT) + forte_add_sourcefile_hcpp(F_USINT_TO_LINT) + forte_add_sourcefile_hcpp(F_USINT_TO_LWORD) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_USINT_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_USINT_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_USINT_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BOOL.cpp new file mode 100644 index 000000000..55d66fa3f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_USINT_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_BOOL, g_nStringIdF_USINT_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_USINT_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BOOL.h new file mode 100644 index 000000000..9cb4137fa --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_USINT_TO_BOOL_H_ +#define _F_USINT_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_BOOL){ + }; + + virtual ~FORTE_F_USINT_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BYTE.cpp new file mode 100644 index 000000000..a163dcd3d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BYTE.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_BYTE, g_nStringIdF_USINT_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_USINT_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BYTE.h new file mode 100644 index 000000000..b63caa576 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_BYTE.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_BYTE_H_ +#define _F_USINT_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_BYTE){ + }; + + virtual ~FORTE_F_USINT_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DINT.cpp new file mode 100644 index 000000000..bf98eeb64 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_DINT, g_nStringIdF_USINT_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_USINT_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DINT.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DINT.h new file mode 100644 index 000000000..c46ba8f28 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_DINT_H_ +#define _F_USINT_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_DINT){ + }; + + virtual ~FORTE_F_USINT_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DWORD.cpp new file mode 100644 index 000000000..6c5ec0bd0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_DWORD, g_nStringIdF_USINT_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_USINT_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DWORD.h new file mode 100644 index 000000000..d206020e3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_DWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_DWORD_H_ +#define _F_USINT_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_DWORD){ + }; + + virtual ~FORTE_F_USINT_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_INT.cpp new file mode 100644 index 000000000..5055e3471 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_INT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_INT, g_nStringIdF_USINT_TO_INT) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_USINT_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_INT.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_INT.h new file mode 100644 index 000000000..5df58dcb4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_INT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_INT_H_ +#define _F_USINT_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_INT){ + }; + + virtual ~FORTE_F_USINT_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LINT.cpp new file mode 100644 index 000000000..4100876b3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_LINT, g_nStringIdF_USINT_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_USINT_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LINT.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LINT.h new file mode 100644 index 000000000..31f73379d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_LINT_H_ +#define _F_USINT_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_LINT){ + }; + + virtual ~FORTE_F_USINT_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LREAL.cpp new file mode 100644 index 000000000..f8414892d --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LREAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_LREAL, g_nStringIdF_USINT_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_USINT_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LREAL.h new file mode 100644 index 000000000..9510c0f1e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LREAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_LREAL_H_ +#define _F_USINT_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_LREAL){ + }; + + virtual ~FORTE_F_USINT_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LWORD.cpp new file mode 100644 index 000000000..eed5483e9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_LWORD, g_nStringIdF_USINT_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_USINT_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LWORD.h new file mode 100644 index 000000000..d062aab3b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_LWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_LWORD_H_ +#define _F_USINT_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_LWORD){ + }; + + virtual ~FORTE_F_USINT_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_REAL.cpp new file mode 100644 index 000000000..43555566e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_REAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_REAL, g_nStringIdF_USINT_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_USINT_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_REAL.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_REAL.h new file mode 100644 index 000000000..724f6ac73 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_REAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_REAL_H_ +#define _F_USINT_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_REAL){ + }; + + virtual ~FORTE_F_USINT_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_SINT.cpp new file mode 100644 index 000000000..fa6de8094 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_SINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_SINT, g_nStringIdF_USINT_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_USINT_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_SINT.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_SINT.h new file mode 100644 index 000000000..33ad54bc0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_SINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_SINT_H_ +#define _F_USINT_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_SINT){ + }; + + virtual ~FORTE_F_USINT_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_STRING.cpp new file mode 100644 index 000000000..5f86c2e6e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_USINT_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_STRING, g_nStringIdF_USINT_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_USINT_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_STRING.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_STRING.h new file mode 100644 index 000000000..e3d406cac --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_USINT_TO_STRING_H_ +#define _F_USINT_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_STRING){ + }; + + virtual ~FORTE_F_USINT_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_TIME.cpp new file mode 100644 index 000000000..0c15899e3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_USINT_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_TIME, g_nStringIdF_USINT_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_USINT_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_TIME.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_TIME.h new file mode 100644 index 000000000..2b5b2cfe8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_USINT_TO_TIME_H_ +#define _F_USINT_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_TIME){ + }; + + virtual ~FORTE_F_USINT_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UDINT.cpp new file mode 100644 index 000000000..d7eec5a38 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UDINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_UDINT, g_nStringIdF_USINT_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_USINT_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UDINT.h new file mode 100644 index 000000000..2242bb3d4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UDINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_UDINT_H_ +#define _F_USINT_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_UDINT){ + }; + + virtual ~FORTE_F_USINT_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UINT.cpp new file mode 100644 index 000000000..4dfaaead6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_UINT, g_nStringIdF_USINT_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_USINT_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UINT.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UINT.h new file mode 100644 index 000000000..5cf069e31 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_UINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_UINT_H_ +#define _F_USINT_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_UINT){ + }; + + virtual ~FORTE_F_USINT_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_ULINT.cpp new file mode 100644 index 000000000..b57fc6bc8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_ULINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_ULINT, g_nStringIdF_USINT_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_USINT_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_ULINT.h new file mode 100644 index 000000000..f93dae12c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_ULINT.h @@ -0,0 +1,61 @@ +/************************************************************************* + /******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_ULINT_H_ +#define _F_USINT_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_ULINT){ + }; + + virtual ~FORTE_F_USINT_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WORD.cpp new file mode 100644 index 000000000..b410fa865 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_USINT_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_WORD, g_nStringIdF_USINT_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_USINT_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WORD.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WORD.h new file mode 100644 index 000000000..022654b1f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_USINT_TO_WORD_H_ +#define _F_USINT_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_WORD){ + }; + + virtual ~FORTE_F_USINT_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WSTRING.cpp new file mode 100644 index 000000000..358fd3424 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_USINT_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_USINT_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_USINT_TO_WSTRING, g_nStringIdF_USINT_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdUSINT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_USINT_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_USINT_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_USINT_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_USINT_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_USINT_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_USINT_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_USINT_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_USINT_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = USINT_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WSTRING.h new file mode 100644 index 000000000..57331db69 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/USINT/F_USINT_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_USINT_TO_WSTRING_H_ +#define _F_USINT_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_USINT_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_USINT_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_USINT &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_USINT_TO_WSTRING){ + }; + + virtual ~FORTE_F_USINT_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/WORD/CMakeLists.txt new file mode 100644 index 000000000..c44c45c3c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/CMakeLists.txt @@ -0,0 +1,43 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# WORD_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_WORD_TO_BOOL) +forte_add_sourcefile_hcpp(F_WORD_TO_BYTE) +forte_add_sourcefile_hcpp(F_WORD_TO_DINT) +forte_add_sourcefile_hcpp(F_WORD_TO_DWORD) +forte_add_sourcefile_hcpp(F_WORD_TO_INT) +forte_add_sourcefile_hcpp(F_WORD_TO_SINT) +forte_add_sourcefile_hcpp(F_WORD_TO_UDINT) +forte_add_sourcefile_hcpp(F_WORD_TO_UINT) +forte_add_sourcefile_hcpp(F_WORD_TO_USINT) +forte_add_sourcefile_hcpp(F_WORD_TO_STRING) +forte_add_sourcefile_hcpp(F_WORD_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_WORD_TO_LINT) + forte_add_sourcefile_hcpp(F_WORD_TO_LWORD) + forte_add_sourcefile_hcpp(F_WORD_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_WORD_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_WORD_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + +if(FORTE_USE_WSTRING_DATATYPE) + forte_add_sourcefile_hcpp(F_WORD_TO_WSTRING) +endif(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BOOL.cpp new file mode 100644 index 000000000..b137dcdbe --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BOOL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WORD_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_BOOL, g_nStringIdF_WORD_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_WORD_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BOOL.h new file mode 100644 index 000000000..30e8db1c0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WORD_TO_BOOL_H_ +#define _F_WORD_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_BOOL){ + }; + + virtual ~FORTE_F_WORD_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BYTE.cpp new file mode 100644 index 000000000..dbab91269 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BYTE.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_BYTE, g_nStringIdF_WORD_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_WORD_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BYTE.h new file mode 100644 index 000000000..595ef3fc9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_BYTE.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_BYTE_H_ +#define _F_WORD_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_BYTE){ + }; + + virtual ~FORTE_F_WORD_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DINT.cpp new file mode 100644 index 000000000..bea053003 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_DINT, g_nStringIdF_WORD_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_WORD_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DINT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DINT.h new file mode 100644 index 000000000..a5c9d838a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_DINT_H_ +#define _F_WORD_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_DINT){ + }; + + virtual ~FORTE_F_WORD_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DWORD.cpp new file mode 100644 index 000000000..655e3a14e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_DWORD, g_nStringIdF_WORD_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_WORD_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DWORD.h new file mode 100644 index 000000000..dd3e36894 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_DWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_DWORD_H_ +#define _F_WORD_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_DWORD){ + }; + + virtual ~FORTE_F_WORD_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_INT.cpp new file mode 100644 index 000000000..600b33bd5 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_INT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_INT, g_nStringIdF_WORD_TO_INT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_WORD_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_INT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_INT.h new file mode 100644 index 000000000..0b9c210ab --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_INT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_INT_H_ +#define _F_WORD_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_INT){ + }; + + virtual ~FORTE_F_WORD_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LINT.cpp new file mode 100644 index 000000000..68338ac44 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_LINT, g_nStringIdF_WORD_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_WORD_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LINT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LINT.h new file mode 100644 index 000000000..2047636b8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_LINT_H_ +#define _F_WORD_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_LINT){ + }; + + virtual ~FORTE_F_WORD_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LREAL.cpp new file mode 100644 index 000000000..7c008bcd3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LREAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_LREAL, g_nStringIdF_WORD_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_WORD_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LREAL.h new file mode 100644 index 000000000..c95a5295a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LREAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_LREAL_H_ +#define _F_WORD_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_LREAL){ + }; + + virtual ~FORTE_F_WORD_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LWORD.cpp new file mode 100644 index 000000000..7c9995524 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LWORD.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_LWORD, g_nStringIdF_WORD_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_WORD_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LWORD.h new file mode 100644 index 000000000..2d657cfbf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_LWORD.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_LWORD_H_ +#define _F_WORD_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_LWORD){ + }; + + virtual ~FORTE_F_WORD_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_REAL.cpp new file mode 100644 index 000000000..431f22ad6 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_REAL.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_REAL, g_nStringIdF_WORD_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_WORD_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_REAL.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_REAL.h new file mode 100644 index 000000000..92c5b6dea --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_REAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_REAL_H_ +#define _F_WORD_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_REAL){ + }; + + virtual ~FORTE_F_WORD_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_SINT.cpp new file mode 100644 index 000000000..c15e7eb32 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_SINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_SINT, g_nStringIdF_WORD_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_WORD_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_SINT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_SINT.h new file mode 100644 index 000000000..1aed1d329 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_SINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_SINT_H_ +#define _F_WORD_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_SINT){ + }; + + virtual ~FORTE_F_WORD_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_STRING.cpp new file mode 100644 index 000000000..05062b160 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_STRING.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WORD_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_STRING, g_nStringIdF_WORD_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_WORD_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_STRING.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_STRING.h new file mode 100644 index 000000000..46e0a4da4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WORD_TO_STRING_H_ +#define _F_WORD_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_STRING){ + }; + + virtual ~FORTE_F_WORD_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_TIME.cpp new file mode 100644 index 000000000..482e5ab5e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WORD_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_TIME, g_nStringIdF_WORD_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_WORD_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_TIME.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_TIME.h new file mode 100644 index 000000000..cf99432a2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WORD_TO_TIME_H_ +#define _F_WORD_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_TIME){ + }; + + virtual ~FORTE_F_WORD_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UDINT.cpp new file mode 100644 index 000000000..9bd641852 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UDINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_UDINT, g_nStringIdF_WORD_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_WORD_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UDINT.h new file mode 100644 index 000000000..091d56f2f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UDINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_UDINT_H_ +#define _F_WORD_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_UDINT){ + }; + + virtual ~FORTE_F_WORD_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UINT.cpp new file mode 100644 index 000000000..6ab2a3f5a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_UINT, g_nStringIdF_WORD_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_WORD_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UINT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UINT.h new file mode 100644 index 000000000..5a6e14e8b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_UINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_UINT_H_ +#define _F_WORD_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_UINT){ + }; + + virtual ~FORTE_F_WORD_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_ULINT.cpp new file mode 100644 index 000000000..76fd0d8fe --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_ULINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_ULINT, g_nStringIdF_WORD_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_WORD_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_ULINT.h new file mode 100644 index 000000000..f346f8e23 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_ULINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_ULINT_H_ +#define _F_WORD_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_ULINT){ + }; + + virtual ~FORTE_F_WORD_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_USINT.cpp new file mode 100644 index 000000000..b7fe77768 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_USINT.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_WORD_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_USINT, g_nStringIdF_WORD_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_WORD_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_USINT.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_USINT.h new file mode 100644 index 000000000..9a50e317a --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_USINT.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_WORD_TO_USINT_H_ +#define _F_WORD_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_USINT){ + }; + + virtual ~FORTE_F_WORD_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_WSTRING.cpp b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_WSTRING.cpp new file mode 100644 index 000000000..f5043c74f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_WSTRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WORD_TO_WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WORD_TO_WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WORD_TO_WSTRING, g_nStringIdF_WORD_TO_WSTRING) + +const CStringDictionary::TStringId FORTE_F_WORD_TO_WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_WSTRING::scm_anDataInputTypeIds[] = {g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WORD_TO_WSTRING::scm_anDataOutputTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 FORTE_F_WORD_TO_WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WORD_TO_WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WORD_TO_WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WORD_TO_WSTRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WORD_TO_WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WORD_TO_WSTRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WORD_TO_WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WORD_TO_WSTRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_WSTRING.h b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_WSTRING.h new file mode 100644 index 000000000..22833e1bd --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WORD/F_WORD_TO_WSTRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WORD_TO_WSTRING_H_ +#define _F_WORD_TO_WSTRING_H_ + +#include +#include +#include + +class FORTE_F_WORD_TO_WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WORD_TO_WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WORD &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WSTRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WORD_TO_WSTRING){ + }; + + virtual ~FORTE_F_WORD_TO_WSTRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/CMakeLists.txt b/src/modules/IEC61131-3/Conversion/WSTRING/CMakeLists.txt new file mode 100644 index 000000000..a3c5548f0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/CMakeLists.txt @@ -0,0 +1,40 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# WSTRING_TO_xxx Conversion +############################################################################# +forte_add_sourcefile_hcpp(F_WSTRING_TO_UINT) +forte_add_sourcefile_hcpp(F_WSTRING_TO_BOOL) +forte_add_sourcefile_hcpp(F_WSTRING_TO_BYTE) +forte_add_sourcefile_hcpp(F_WSTRING_TO_DINT) +forte_add_sourcefile_hcpp(F_WSTRING_TO_DWORD) +forte_add_sourcefile_hcpp(F_WSTRING_TO_INT) +forte_add_sourcefile_hcpp(F_WSTRING_TO_SINT) +forte_add_sourcefile_hcpp(F_WSTRING_TO_UDINT) +forte_add_sourcefile_hcpp(F_WSTRING_TO_USINT) +forte_add_sourcefile_hcpp(F_WSTRING_TO_WORD) +forte_add_sourcefile_hcpp(F_WSTRING_TO_STRING) +forte_add_sourcefile_hcpp(F_WSTRING_TO_TIME) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(F_WSTRING_TO_LINT) + forte_add_sourcefile_hcpp(F_WSTRING_TO_LWORD) + forte_add_sourcefile_hcpp(F_WSTRING_TO_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_WSTRING_TO_REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(F_WSTRING_TO_LREAL) +endif(FORTE_USE_LREAL_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BOOL.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BOOL.cpp new file mode 100644 index 000000000..d26b8e9dc --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BOOL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_BOOL, g_nStringIdF_WSTRING_TO_BOOL) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BOOL::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BOOL::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_F_WSTRING_TO_BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_BOOL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_BOOL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_BOOL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BOOL.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BOOL.h new file mode 100644 index 000000000..000e514ce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BOOL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_BOOL_H_ +#define _F_WSTRING_TO_BOOL_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_BOOL){ + }; + + virtual ~FORTE_F_WSTRING_TO_BOOL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BYTE.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BYTE.cpp new file mode 100644 index 000000000..57b301977 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BYTE.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_BYTE, g_nStringIdF_WSTRING_TO_BYTE) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BYTE::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BYTE::scm_anDataOutputTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 FORTE_F_WSTRING_TO_BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_BYTE::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_BYTE::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_BYTE(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BYTE.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BYTE.h new file mode 100644 index 000000000..89ed1615e --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_BYTE.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_BYTE_H_ +#define _F_WSTRING_TO_BYTE_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BYTE &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_BYTE){ + }; + + virtual ~FORTE_F_WSTRING_TO_BYTE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DINT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DINT.cpp new file mode 100644 index 000000000..21af7a0ee --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_DINT, g_nStringIdF_WSTRING_TO_DINT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DINT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DINT::scm_anDataOutputTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_DINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_DINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_DINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DINT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DINT.h new file mode 100644 index 000000000..294bcdcbf --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_DINT_H_ +#define _F_WSTRING_TO_DINT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_DINT){ + }; + + virtual ~FORTE_F_WSTRING_TO_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DWORD.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DWORD.cpp new file mode 100644 index 000000000..bcd9fa44b --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_DWORD, g_nStringIdF_WSTRING_TO_DWORD) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DWORD::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DWORD::scm_anDataOutputTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 FORTE_F_WSTRING_TO_DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_DWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_DWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_DWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DWORD.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DWORD.h new file mode 100644 index 000000000..1694ab9da --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_DWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_DWORD_H_ +#define _F_WSTRING_TO_DWORD_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_DWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_DWORD){ + }; + + virtual ~FORTE_F_WSTRING_TO_DWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_INT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_INT.cpp new file mode 100644 index 000000000..07bc1fba8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_INT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_INT, g_nStringIdF_WSTRING_TO_INT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_INT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_INT::scm_anDataOutputTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_INT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_INT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_INT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_INT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_INT.h new file mode 100644 index 000000000..55abf0143 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_INT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_INT_H_ +#define _F_WSTRING_TO_INT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_INT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_INT){ + }; + + virtual ~FORTE_F_WSTRING_TO_INT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LINT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LINT.cpp new file mode 100644 index 000000000..1838c1155 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_LINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_LINT, g_nStringIdF_WSTRING_TO_LINT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LINT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LINT::scm_anDataOutputTypeIds[] = {g_nStringIdLINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_LINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_LINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_LINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_LINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_LINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_LINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LINT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LINT.h new file mode 100644 index 000000000..9b233dfa9 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_LINT_H_ +#define _F_WSTRING_TO_LINT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_LINT){ + }; + + virtual ~FORTE_F_WSTRING_TO_LINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LREAL.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LREAL.cpp new file mode 100644 index 000000000..8e0cdbad3 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LREAL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_LREAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_LREAL, g_nStringIdF_WSTRING_TO_LREAL) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LREAL::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LREAL::scm_anDataOutputTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 FORTE_F_WSTRING_TO_LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_LREAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_LREAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_LREAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LREAL.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LREAL.h new file mode 100644 index 000000000..a4a7299da --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LREAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_LREAL_H_ +#define _F_WSTRING_TO_LREAL_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LREAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_LREAL){ + }; + + virtual ~FORTE_F_WSTRING_TO_LREAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LWORD.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LWORD.cpp new file mode 100644 index 000000000..974bb3ad2 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LWORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_LWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_LWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_LWORD, g_nStringIdF_WSTRING_TO_LWORD) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LWORD::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LWORD::scm_anDataOutputTypeIds[] = {g_nStringIdLWORD}; + +const TForteInt16 FORTE_F_WSTRING_TO_LWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_LWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_LWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_LWORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_LWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_LWORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_LWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_LWORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LWORD.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LWORD.h new file mode 100644 index 000000000..97b94ce88 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_LWORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_LWORD_H_ +#define _F_WSTRING_TO_LWORD_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_LWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_LWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_LWORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_LWORD){ + }; + + virtual ~FORTE_F_WSTRING_TO_LWORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_REAL.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_REAL.cpp new file mode 100644 index 000000000..17c14abe1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_REAL.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_REAL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_REAL, g_nStringIdF_WSTRING_TO_REAL) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_REAL::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_REAL::scm_anDataOutputTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 FORTE_F_WSTRING_TO_REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_REAL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_REAL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_REAL(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_REAL.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_REAL.h new file mode 100644 index 000000000..dae94df01 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_REAL.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_REAL_H_ +#define _F_WSTRING_TO_REAL_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_REAL){ + }; + + virtual ~FORTE_F_WSTRING_TO_REAL(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_SINT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_SINT.cpp new file mode 100644 index 000000000..93e91e555 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_SINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_SINT, g_nStringIdF_WSTRING_TO_SINT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_SINT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_SINT::scm_anDataOutputTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_SINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_SINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_SINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_SINT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_SINT.h new file mode 100644 index 000000000..5fadec198 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_SINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_SINT_H_ +#define _F_WSTRING_TO_SINT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_SINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_SINT){ + }; + + virtual ~FORTE_F_WSTRING_TO_SINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_STRING.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_STRING.cpp new file mode 100644 index 000000000..b7fbd46b0 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_STRING.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_STRING, g_nStringIdF_WSTRING_TO_STRING) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_STRING::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 FORTE_F_WSTRING_TO_STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_STRING::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_STRING::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_STRING(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_STRING.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_STRING.h new file mode 100644 index 000000000..971077200 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_STRING_H_ +#define _F_WSTRING_TO_STRING_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_STRING &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_STRING){ + }; + + virtual ~FORTE_F_WSTRING_TO_STRING(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_TIME.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_TIME.cpp new file mode 100644 index 000000000..0e3ba0fcb --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_TIME.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_TIME, g_nStringIdF_WSTRING_TO_TIME) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_TIME::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_TIME::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_F_WSTRING_TO_TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_TIME::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_TIME::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_TIME(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_TIME.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_TIME.h new file mode 100644 index 000000000..831ba126f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_TIME.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_TIME_H_ +#define _F_WSTRING_TO_TIME_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_TIME &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_TIME){ + }; + + virtual ~FORTE_F_WSTRING_TO_TIME(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UDINT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UDINT.cpp new file mode 100644 index 000000000..0fdd2e11c --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UDINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_UDINT, g_nStringIdF_WSTRING_TO_UDINT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UDINT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UDINT::scm_anDataOutputTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_UDINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_UDINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_UDINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UDINT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UDINT.h new file mode 100644 index 000000000..0dc67a4f7 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UDINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_UDINT_H_ +#define _F_WSTRING_TO_UDINT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UDINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_UDINT){ + }; + + virtual ~FORTE_F_WSTRING_TO_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UINT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UINT.cpp new file mode 100644 index 000000000..8c80440ce --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_UINT, g_nStringIdF_WSTRING_TO_UINT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UINT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UINT::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_UINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_UINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_UINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UINT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UINT.h new file mode 100644 index 000000000..96cf0c2af --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_UINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_UINT_H_ +#define _F_WSTRING_TO_UINT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_UINT){ + }; + + virtual ~FORTE_F_WSTRING_TO_UINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_ULINT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_ULINT.cpp new file mode 100644 index 000000000..1a8fa74c4 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_ULINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_ULINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_ULINT, g_nStringIdF_WSTRING_TO_ULINT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_ULINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_ULINT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_ULINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_ULINT::scm_anDataOutputTypeIds[] = {g_nStringIdULINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_ULINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_ULINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_ULINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_ULINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_ULINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_ULINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_ULINT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_ULINT.h new file mode 100644 index 000000000..a3b60ad9f --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_ULINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_ULINT_H_ +#define _F_WSTRING_TO_ULINT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ULINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_ULINT){ + }; + + virtual ~FORTE_F_WSTRING_TO_ULINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_USINT.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_USINT.cpp new file mode 100644 index 000000000..2e3ecc2d1 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_USINT.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_USINT, g_nStringIdF_WSTRING_TO_USINT) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_USINT::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_USINT::scm_anDataOutputTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 FORTE_F_WSTRING_TO_USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_USINT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_USINT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_USINT(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_USINT.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_USINT.h new file mode 100644 index 000000000..bac468359 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_USINT.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_USINT_H_ +#define _F_WSTRING_TO_USINT_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_USINT &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_USINT){ + }; + + virtual ~FORTE_F_WSTRING_TO_USINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_WORD.cpp b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_WORD.cpp new file mode 100644 index 000000000..7f7606332 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_WORD.cpp @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_WSTRING_TO_WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_WSTRING_TO_WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_WSTRING_TO_WORD, g_nStringIdF_WSTRING_TO_WORD) + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_WORD::scm_anDataInputTypeIds[] = {g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_WORD::scm_anDataOutputTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 FORTE_F_WSTRING_TO_WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_WSTRING_TO_WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_WSTRING_TO_WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_WSTRING_TO_WORD::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_WSTRING_TO_WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_WSTRING_TO_WORD::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_WSTRING_TO_WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = WSTRING_TO_WORD(IN()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_WORD.h b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_WORD.h new file mode 100644 index 000000000..4096ff6a8 --- /dev/null +++ b/src/modules/IEC61131-3/Conversion/WSTRING/F_WSTRING_TO_WORD.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_WSTRING_TO_WORD_H_ +#define _F_WSTRING_TO_WORD_H_ + +#include +#include +#include + +class FORTE_F_WSTRING_TO_WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_WSTRING_TO_WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_WSTRING &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_WORD &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_WSTRING_TO_WORD){ + }; + + virtual ~FORTE_F_WSTRING_TO_WORD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/CMakeLists.txt b/src/modules/IEC61131-3/Counters/CMakeLists.txt new file mode 100644 index 000000000..2d3f1df3d --- /dev/null +++ b/src/modules/IEC61131-3/Counters/CMakeLists.txt @@ -0,0 +1,31 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2012 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Counters +############################################################################# +forte_add_sourcefile_hcpp(FB_CTD_DINT) +forte_add_sourcefile_hcpp(FB_CTD_UDINT) +forte_add_sourcefile_hcpp(FB_CTD) +forte_add_sourcefile_hcpp(FB_CTUD_DINT) +forte_add_sourcefile_hcpp(FB_CTU_UDINT) +forte_add_sourcefile_hcpp(FB_CTU) +forte_add_sourcefile_hcpp(FB_CTU_DINT) +forte_add_sourcefile_hcpp(FB_CTUD) + +if(FORTE_USE_64BIT_DATATYPES) + forte_add_sourcefile_hcpp(FB_CTD_LINT) + forte_add_sourcefile_hcpp(FB_CTD_ULINT) + forte_add_sourcefile_hcpp(FB_CTU_LINT) + forte_add_sourcefile_hcpp(FB_CTU_ULINT) + forte_add_sourcefile_hcpp(FB_CTUD_LINT) + forte_add_sourcefile_hcpp(FB_CTUD_ULINT) +endif(FORTE_USE_64BIT_DATATYPES) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Counters/FB_CTD.cpp b/src/modules/IEC61131-3/Counters/FB_CTD.cpp new file mode 100644 index 000000000..a3e280bb2 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_CTD, g_nStringIdFB_CTD) + +const CStringDictionary::TStringId FB_CTD::scm_anDataInputNames[] = {g_nStringIdCD, g_nStringIdLD, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTD::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTD::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdINT}; +const CStringDictionary::TStringId FB_CTD::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdINT}; + +const TForteInt16 FB_CTD::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTD::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTD::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTD::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTD::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTD::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == LD()){ + CV() = PV(); + } + else if( (true == CD()) && (CV() > CIEC_INT::scm_nMinVal)){ + CV() = static_cast(CV() - 1); + } + Q() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} + diff --git a/src/modules/IEC61131-3/Counters/FB_CTD.h b/src/modules/IEC61131-3/Counters/FB_CTD.h new file mode 100644 index 000000000..fac9e2ede --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD.h @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTD_H_ +#define _FB_CTD_H_ + +#include +#include +#include +#include + +class FB_CTD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CD() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(1)); + } + CIEC_INT& PV() { + return *static_cast(getDI(2)); + } + + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_INT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTD){}; + virtual ~FB_CTD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_DINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTD_DINT.cpp new file mode 100644 index 000000000..23185c256 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_DINT.cpp @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTD_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTD_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_CTD_DINT, g_nStringIdFB_CTD_DINT) + +const CStringDictionary::TStringId FB_CTD_DINT::scm_anDataInputNames[] = {g_nStringIdCD, g_nStringIdLD, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTD_DINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTD_DINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDINT}; +const CStringDictionary::TStringId FB_CTD_DINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdDINT}; + +const TForteInt16 FB_CTD_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTD_DINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTD_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTD_DINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTD_DINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTD_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTD_DINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTD_DINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == LD()){ + CV() = PV(); + } + else if( (true == CD()) && (CV() > CIEC_DINT::scm_nMinVal)){ + CV() = CV() - 1; + } + Q() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_DINT.h b/src/modules/IEC61131-3/Counters/FB_CTD_DINT.h new file mode 100644 index 000000000..48ea93d1e --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_DINT.h @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTD_DINT_H_ +#define _FB_CTD_DINT_H_ + +#include +#include +#include +#include + +class FB_CTD_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTD_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CD() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(1)); + } + CIEC_DINT& PV() { + return *static_cast(getDI(2)); + } + + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_DINT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTD_DINT) {}; + virtual ~FB_CTD_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_LINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTD_LINT.cpp new file mode 100644 index 000000000..b9b8717e6 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_LINT.cpp @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTD_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTD_LINT_gen.cpp" +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_FB(FB_CTD_LINT, g_nStringIdFB_CTD_LINT) + +const CStringDictionary::TStringId FB_CTD_LINT::scm_anDataInputNames[] = {g_nStringIdCD, g_nStringIdLD, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTD_LINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTD_LINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLINT}; +const CStringDictionary::TStringId FB_CTD_LINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdLINT};; + +const TForteInt16 FB_CTD_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTD_LINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTD_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTD_LINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTD_LINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTD_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTD_LINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTD_LINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == LD()){ + CV() = PV(); + } + else if( (true == CD()) && (CV() > CIEC_LINT::scm_nMinVal)){ + CV() = CV() - 1; + } + Q() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} + +#endif diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_LINT.h b/src/modules/IEC61131-3/Counters/FB_CTD_LINT.h new file mode 100644 index 000000000..caba27ae2 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_LINT.h @@ -0,0 +1,72 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTD_LINT_H_ +#define _FB_CTD_LINT_H_ + +#include +#include +#include +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +class FB_CTD_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTD_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + + CIEC_BOOL& CD() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(1)); + } + CIEC_LINT& PV() { + return *static_cast(getDI(2)); + } + + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_LINT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTD_LINT){}; + virtual ~FB_CTD_LINT(){}; + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_UDINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTD_UDINT.cpp new file mode 100644 index 000000000..f6f505897 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_UDINT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTD_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTD_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_CTD_UDINT, g_nStringIdFB_CTD_UDINT) + +const CStringDictionary::TStringId FB_CTD_UDINT::scm_anDataInputNames[] = {g_nStringIdCD, g_nStringIdLD, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTD_UDINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTD_UDINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUDINT}; +const CStringDictionary::TStringId FB_CTD_UDINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdUDINT}; + +const TForteInt16 FB_CTD_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTD_UDINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTD_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTD_UDINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTD_UDINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTD_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTD_UDINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTD_UDINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == LD()){ + CV() = PV(); + } + else if( (true == CD()) && (CV() > CIEC_UDINT::scm_nMinVal)){ + CV() = CV() - 1; + } + Q() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_UDINT.h b/src/modules/IEC61131-3/Counters/FB_CTD_UDINT.h new file mode 100644 index 000000000..519a6d793 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_UDINT.h @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTD_UDINT_H_ +#define _FB_CTD_UDINT_H_ + +#include +#include +#include +#include +#include + +class FB_CTD_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTD_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CD() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(1)); + } + CIEC_UDINT& PV() { + return *static_cast(getDI(2)); + } + + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_UDINT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTD_UDINT){}; + virtual ~FB_CTD_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_ULINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTD_ULINT.cpp new file mode 100644 index 000000000..7c4638409 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_ULINT.cpp @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTD_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTD_ULINT_gen.cpp" +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_FB(FB_CTD_ULINT, g_nStringIdFB_CTD_ULINT) + +const CStringDictionary::TStringId FB_CTD_ULINT::scm_anDataInputNames[] = {g_nStringIdCD, g_nStringIdLD, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTD_ULINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTD_ULINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdULINT}; +const CStringDictionary::TStringId FB_CTD_ULINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdULINT}; + +const TForteInt16 FB_CTD_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTD_ULINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTD_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTD_ULINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTD_ULINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTD_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTD_ULINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTD_ULINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == LD()){ + CV() = PV(); + } + else if( (true == CD()) && (CV() > CIEC_ULINT::scm_nMinVal)){ + CV() = CV() - 1; + } + Q() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} + +#endif diff --git a/src/modules/IEC61131-3/Counters/FB_CTD_ULINT.h b/src/modules/IEC61131-3/Counters/FB_CTD_ULINT.h new file mode 100644 index 000000000..feb58f684 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTD_ULINT.h @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTD_ULINT_H_ +#define _FB_CTD_ULINT_H_ + +#include +#include +#include +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +class FB_CTD_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTD_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CD() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(1)); + } + CIEC_ULINT& PV() { + return *static_cast(getDI(2)); + } + + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_ULINT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTD_ULINT){}; + virtual ~FB_CTD_ULINT(){}; + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTU.cpp b/src/modules/IEC61131-3/Counters/FB_CTU.cpp new file mode 100644 index 000000000..11d6510e9 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTU.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTU_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_CTU, g_nStringIdFB_CTU) + +const CStringDictionary::TStringId FB_CTU::scm_anDataInputNames[] = {g_nStringIdCU, g_nStringIdR, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTU::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTU::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdINT}; +const CStringDictionary::TStringId FB_CTU::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdINT}; + +const TForteInt16 FB_CTU::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTU::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTU::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTU::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTU::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTU::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTU::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTU::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == R()){ + CV() = 0; + } + else if( (true == CU()) && (CV() < CIEC_INT::scm_nMaxVal)){ + CV() = static_cast(CV() + 1); + } + Q() = (CV() >= PV()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Counters/FB_CTU.h b/src/modules/IEC61131-3/Counters/FB_CTU.h new file mode 100644 index 000000000..3709678bc --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTU_H_ +#define _FB_CTU_H_ + +#include +#include +#include +#include + +class FB_CTU: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTU) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(1)); + } + CIEC_INT& PV() { + return *static_cast(getDI(2)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_INT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTU){}; + virtual ~FB_CTU(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD.cpp b/src/modules/IEC61131-3/Counters/FB_CTUD.cpp new file mode 100644 index 000000000..1414df70f --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTUD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTUD_gen.cpp" +#endif +DEFINE_FIRMWARE_FB(FB_CTUD, g_nStringIdFB_CTUD) + +const CStringDictionary::TStringId FB_CTUD::scm_anDataInputNames[] = { g_nStringIdCU, g_nStringIdCD, g_nStringIdR, g_nStringIdLD, g_nStringIdPV }; + +const CStringDictionary::TStringId FB_CTUD::scm_anDataOutputNames[] = { g_nStringIdQU, g_nStringIdQD, g_nStringIdCV }; +const CStringDictionary::TStringId FB_CTUD::scm_aunDIDataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdINT }; +const CStringDictionary::TStringId FB_CTUD::scm_aunDODataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdINT }; + +const TForteInt16 FB_CTUD::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FB_CTUD::scm_anEIWith[] = { 1, 4, 3, 0, 2, 255 }; +const CStringDictionary::TStringId FB_CTUD::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const TDataIOID FB_CTUD::scm_anEOWith[] = { 0, 2, 1, 255 }; +const TForteInt16 FB_CTUD::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FB_CTUD::scm_anEventOutputNames[] = { g_nStringIdCNF }; + +const SFBInterfaceSpec FB_CTUD::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_aunDIDataTypeIds, 3, scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 }; + +void FB_CTUD::executeEvent(int pa_nEIID) { + if (pa_nEIID == scm_nEventREQID) { + if (true == R()) { + CV() = 0; + } + else { + if (true == LD()) { + CV() = PV(); + } + else { + if (!(CU() && CD())) { + if ((CU() && (CV() < CIEC_INT::scm_nMaxVal))) { + CV() = static_cast(CV() + 1); + } + else { + if ((CD() && (CV() > CIEC_INT::scm_nMinVal))) { + CV() = static_cast(CV() - 1); + } + } + } + } + } + QU() = (CV() >= PV()); + QD() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD.h b/src/modules/IEC61131-3/Counters/FB_CTUD.h new file mode 100644 index 000000000..42b7f9f77 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTUD_H_ +#define _FB_CTUD_H_ + +#include +#include +#include +#include + +class FB_CTUD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTUD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,5,3, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& CD() { + return *static_cast(getDI(1)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(2)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(3)); + } + CIEC_INT& PV() { + return *static_cast(getDI(4)); + } + + CIEC_BOOL& QU() { + return *static_cast(getDO(0)); + } + CIEC_BOOL& QD() { + return *static_cast(getDO(1)); + } + CIEC_INT& CV() { + return *static_cast(getDO(2)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTUD){}; + virtual ~FB_CTUD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD_DINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTUD_DINT.cpp new file mode 100644 index 000000000..2100b9751 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD_DINT.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTUD_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTUD_DINT_gen.cpp" +#endif +DEFINE_FIRMWARE_FB(FB_CTUD_DINT, g_nStringIdFB_CTUD_DINT) + +const CStringDictionary::TStringId FB_CTUD_DINT::scm_anDataInputNames[] = { g_nStringIdCU, g_nStringIdCD, g_nStringIdR, g_nStringIdLD, g_nStringIdPV }; + +const CStringDictionary::TStringId FB_CTUD_DINT::scm_anDataOutputNames[] = { g_nStringIdQU, g_nStringIdQD, g_nStringIdCV }; +const CStringDictionary::TStringId FB_CTUD_DINT::scm_aunDIDataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDINT }; +const CStringDictionary::TStringId FB_CTUD_DINT::scm_aunDODataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDINT }; + +const TForteInt16 FB_CTUD_DINT::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FB_CTUD_DINT::scm_anEIWith[] = { 1, 4, 3, 0, 2, 255 }; +const CStringDictionary::TStringId FB_CTUD_DINT::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const TDataIOID FB_CTUD_DINT::scm_anEOWith[] = { 0, 2, 1, 255 }; +const TForteInt16 FB_CTUD_DINT::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FB_CTUD_DINT::scm_anEventOutputNames[] = { g_nStringIdCNF }; + +const SFBInterfaceSpec FB_CTUD_DINT::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_aunDIDataTypeIds, 3, scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 }; + +void FB_CTUD_DINT::executeEvent(int pa_nEIID) { + if (pa_nEIID == scm_nEventREQID) { + if (true == R()) { + CV() = 0; + } + else { + if (true == LD()) { + CV() = PV(); + } + else { + if (!(CU() && CD())) { + if ((CU() && (CV() < CIEC_DINT::scm_nMaxVal))) { + CV() = CV() + 1; + } + else { + if ((CD() && (CV() > CIEC_DINT::scm_nMinVal))) { + CV() = CV() - 1; + } + } + } + } + } + QU() = (CV() >= PV()); + QD() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD_DINT.h b/src/modules/IEC61131-3/Counters/FB_CTUD_DINT.h new file mode 100644 index 000000000..de8c042e4 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD_DINT.h @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTUD_DINT_H_ +#define _FB_CTUD_DINT_H_ + +#include +#include +#include +#include + +class FB_CTUD_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTUD_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,5,3, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& CD() { + return *static_cast(getDI(1)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(2)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(3)); + } + CIEC_DINT& PV() { + return *static_cast(getDI(4)); + } + + CIEC_BOOL& QU() { + return *static_cast(getDO(0)); + } + CIEC_BOOL& QD() { + return *static_cast(getDO(1)); + } + CIEC_DINT& CV() { + return *static_cast(getDO(2)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTUD_DINT){}; + virtual ~FB_CTUD_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD_LINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTUD_LINT.cpp new file mode 100644 index 000000000..bff7a2772 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD_LINT.cpp @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTUD_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTUD_LINT_gen.cpp" +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_FB(FB_CTUD_LINT, g_nStringIdFB_CTUD_LINT) + +const CStringDictionary::TStringId FB_CTUD_LINT::scm_anDataInputNames[] = { g_nStringIdCU, g_nStringIdCD, g_nStringIdR, g_nStringIdLD, g_nStringIdPV }; + +const CStringDictionary::TStringId FB_CTUD_LINT::scm_anDataOutputNames[] = { g_nStringIdQU, g_nStringIdQD, g_nStringIdCV }; +const CStringDictionary::TStringId FB_CTUD_LINT::scm_aunDIDataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLINT }; +const CStringDictionary::TStringId FB_CTUD_LINT::scm_aunDODataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLINT }; + +const TForteInt16 FB_CTUD_LINT::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FB_CTUD_LINT::scm_anEIWith[] = { 1, 4, 3, 0, 2, 255 }; +const CStringDictionary::TStringId FB_CTUD_LINT::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const TDataIOID FB_CTUD_LINT::scm_anEOWith[] = { 0, 2, 1, 255 }; +const TForteInt16 FB_CTUD_LINT::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FB_CTUD_LINT::scm_anEventOutputNames[] = { g_nStringIdCNF }; + +const SFBInterfaceSpec FB_CTUD_LINT::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_aunDIDataTypeIds, 3, scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 }; + +void FB_CTUD_LINT::executeEvent(int pa_nEIID) { + if (pa_nEIID == scm_nEventREQID) { + if (true == R()) { + CV() = 0; + } + else{ + if (true == LD()) { + CV() = PV(); + } + else { + if (!(CU() && CD())) { + if ((CU() && (CV() < CIEC_LINT::scm_nMaxVal))) { + CV() = CV() + 1; + } + else { + if ((CD() && (CV() > CIEC_LINT::scm_nMinVal))) { + CV() = CV() - 1; + } + } + } + } + } + QU() = (CV() >= PV()); + QD() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} + +#endif diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD_LINT.h b/src/modules/IEC61131-3/Counters/FB_CTUD_LINT.h new file mode 100644 index 000000000..fac09ec82 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD_LINT.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTUD_LINT_H_ +#define _FB_CTUD_LINT_H_ + +#include +#include +#include +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +class FB_CTUD_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTUD_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,5,3, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& CD() { + return *static_cast(getDI(1)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(2)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(3)); + } + CIEC_LINT& PV() { + return *static_cast(getDI(4)); + } + + CIEC_BOOL& QU() { + return *static_cast(getDO(0)); + } + CIEC_BOOL& QD() { + return *static_cast(getDO(1)); + } + CIEC_LINT& CV() { + return *static_cast(getDO(2)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTUD_LINT){}; + virtual ~FB_CTUD_LINT(){}; + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD_ULINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTUD_ULINT.cpp new file mode 100644 index 000000000..43b7cddc1 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD_ULINT.cpp @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTUD_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTUD_ULINT_gen.cpp" +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_FB(FB_CTUD_ULINT, g_nStringIdFB_CTUD_ULINT) + +const CStringDictionary::TStringId FB_CTUD_ULINT::scm_anDataInputNames[] = { g_nStringIdCU, g_nStringIdCD, g_nStringIdR, g_nStringIdLD, g_nStringIdPV }; + +const CStringDictionary::TStringId FB_CTUD_ULINT::scm_anDataOutputNames[] = { g_nStringIdQU, g_nStringIdQD, g_nStringIdCV }; +const CStringDictionary::TStringId FB_CTUD_ULINT::scm_aunDIDataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdULINT }; +const CStringDictionary::TStringId FB_CTUD_ULINT::scm_aunDODataTypeIds[] = { g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdULINT }; + +const TForteInt16 FB_CTUD_ULINT::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FB_CTUD_ULINT::scm_anEIWith[] = { 1, 4, 3, 0, 2, 255 }; +const CStringDictionary::TStringId FB_CTUD_ULINT::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const TDataIOID FB_CTUD_ULINT::scm_anEOWith[] = { 0, 2, 1, 255 }; +const TForteInt16 FB_CTUD_ULINT::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FB_CTUD_ULINT::scm_anEventOutputNames[] = { g_nStringIdCNF }; + +const SFBInterfaceSpec FB_CTUD_ULINT::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_aunDIDataTypeIds, 3, scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 }; + +void FB_CTUD_ULINT::executeEvent(int pa_nEIID) { + if (pa_nEIID == scm_nEventREQID) { + if (true == R()) { + CV() = 0; + } + else { + if (true == LD()) { + CV() = PV(); + } + else { + if (!(CU() && CD())) { + if ((CU() && (CV() < CIEC_ULINT::scm_nMaxVal))) { + CV() = CV() + 1; + } + else { + if ((CD() && (CV() > CIEC_ULINT::scm_nMinVal))) { + CV() = CV() - 1; + } + } + } + } + } + QU() = (CV() >= PV()); + QD() = (CV() <= 0); + sendOutputEvent(scm_nEventCNFID); + } +} +#endif diff --git a/src/modules/IEC61131-3/Counters/FB_CTUD_ULINT.h b/src/modules/IEC61131-3/Counters/FB_CTUD_ULINT.h new file mode 100644 index 000000000..9236448cc --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTUD_ULINT.h @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTUD_ULINT_H_ +#define _FB_CTUD_ULINT_H_ + +#include +#include +#include +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +class FB_CTUD_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTUD_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,5,3, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& CD() { + return *static_cast(getDI(1)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(2)); + } + CIEC_BOOL& LD() { + return *static_cast(getDI(3)); + } + CIEC_ULINT& PV() { + return *static_cast(getDI(4)); + } + + CIEC_BOOL& QU() { + return *static_cast(getDO(0)); + } + CIEC_BOOL& QD() { + return *static_cast(getDO(1)); + } + CIEC_ULINT& CV() { + return *static_cast(getDO(2)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTUD_ULINT){}; + virtual ~FB_CTUD_ULINT(){}; + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_DINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTU_DINT.cpp new file mode 100644 index 000000000..d9826dc36 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_DINT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoit, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTU_DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTU_DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_CTU_DINT, g_nStringIdFB_CTU_DINT) + +const CStringDictionary::TStringId FB_CTU_DINT::scm_anDataInputNames[] = {g_nStringIdCU, g_nStringIdR, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTU_DINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTU_DINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDINT}; +const CStringDictionary::TStringId FB_CTU_DINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdDINT}; + +const TForteInt16 FB_CTU_DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTU_DINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTU_DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTU_DINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTU_DINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTU_DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTU_DINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTU_DINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == R()){ + CV() = 0; + } + else if( (true == CU()) && (CV() < CIEC_DINT::scm_nMaxVal)){ + CV() = CV() + 1; + } + Q() = (CV() >= PV()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_DINT.h b/src/modules/IEC61131-3/Counters/FB_CTU_DINT.h new file mode 100644 index 000000000..e72d35728 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_DINT.h @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTU_DINT_H_ +#define _FB_CTU_DINT_H_ + +#include +#include +#include +#include + +class FB_CTU_DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTU_DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(1)); + } + CIEC_DINT& PV() { + return *static_cast(getDI(2)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_DINT& CV() { + return *static_cast(getDO(1)); + } + + +public: + FUNCTION_BLOCK_CTOR(FB_CTU_DINT){}; + virtual ~FB_CTU_DINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_LINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTU_LINT.cpp new file mode 100644 index 000000000..407c21935 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_LINT.cpp @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTU_LINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTU_LINT_gen.cpp" +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_FB(FB_CTU_LINT, g_nStringIdFB_CTU_LINT) + +const CStringDictionary::TStringId FB_CTU_LINT::scm_anDataInputNames[] = {g_nStringIdCU, g_nStringIdR, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTU_LINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTU_LINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLINT}; +const CStringDictionary::TStringId FB_CTU_LINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdLINT}; + +const TForteInt16 FB_CTU_LINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTU_LINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTU_LINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTU_LINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTU_LINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTU_LINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTU_LINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTU_LINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == R()){ + CV() = 0; + } + else if( (true == CU()) && (CV() < CIEC_LINT::scm_nMaxVal)){ + CV() = CV() + 1; + } + Q() = (CV() >= PV()); + sendOutputEvent(scm_nEventCNFID); + } +} + +#endif diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_LINT.h b/src/modules/IEC61131-3/Counters/FB_CTU_LINT.h new file mode 100644 index 000000000..e9161ed61 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_LINT.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTU_LINT_H_ +#define _FB_CTU_LINT_H_ + +#include +#include +#include +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +class FB_CTU_LINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTU_LINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(1)); + } + CIEC_LINT& PV() { + return *static_cast(getDI(2)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_LINT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTU_LINT) {}; + virtual ~FB_CTU_LINT(){}; + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_UDINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTU_UDINT.cpp new file mode 100644 index 000000000..42a229874 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_UDINT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTU_UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTU_UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_CTU_UDINT, g_nStringIdFB_CTU_UDINT) + +const CStringDictionary::TStringId FB_CTU_UDINT::scm_anDataInputNames[] = {g_nStringIdCU, g_nStringIdR, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTU_UDINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTU_UDINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUDINT}; +const CStringDictionary::TStringId FB_CTU_UDINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdUDINT}; + +const TForteInt16 FB_CTU_UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTU_UDINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTU_UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTU_UDINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTU_UDINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTU_UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTU_UDINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTU_UDINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == R()){ + CV() = 0; + } + else if( (true == CU()) && (CV() < CIEC_UDINT::scm_nMaxVal)){ + CV() = CV() + 1; + } + Q() = (CV() >= PV()); + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_UDINT.h b/src/modules/IEC61131-3/Counters/FB_CTU_UDINT.h new file mode 100644 index 000000000..df7884eb1 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_UDINT.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTU_UDINT_H_ +#define _FB_CTU_UDINT_H_ + +#include +#include +#include +#include + +class FB_CTU_UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTU_UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(1)); + } + CIEC_UDINT& PV() { + return *static_cast(getDI(2)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_UDINT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTU_UDINT){}; + virtual ~FB_CTU_UDINT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_ULINT.cpp b/src/modules/IEC61131-3/Counters/FB_CTU_ULINT.cpp new file mode 100644 index 000000000..f9b9bffeb --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_ULINT.cpp @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_CTU_ULINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_CTU_ULINT_gen.cpp" +#endif + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_FB(FB_CTU_ULINT, g_nStringIdFB_CTU_ULINT) + +const CStringDictionary::TStringId FB_CTU_ULINT::scm_anDataInputNames[] = {g_nStringIdCU, g_nStringIdR, g_nStringIdPV}; + +const CStringDictionary::TStringId FB_CTU_ULINT::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId FB_CTU_ULINT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdULINT}; +const CStringDictionary::TStringId FB_CTU_ULINT::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdULINT}; + +const TForteInt16 FB_CTU_ULINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_CTU_ULINT::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FB_CTU_ULINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_CTU_ULINT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_CTU_ULINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_CTU_ULINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_CTU_ULINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_CTU_ULINT::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if(true == R()){ + CV() = 0; + } + else if( (true == CU()) && (CV() < CIEC_ULINT::scm_nMaxVal)){ + CV() = CV() + 1; + } + Q() = (CV() >= PV()); + sendOutputEvent(scm_nEventCNFID); + } +} + +#endif diff --git a/src/modules/IEC61131-3/Counters/FB_CTU_ULINT.h b/src/modules/IEC61131-3/Counters/FB_CTU_ULINT.h new file mode 100644 index 000000000..3a89dc315 --- /dev/null +++ b/src/modules/IEC61131-3/Counters/FB_CTU_ULINT.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_CTU_ULINT_H_ +#define _FB_CTU_ULINT_H_ + +#include +#include +#include +#include + +#ifdef FORTE_USE_64BIT_DATATYPES + +class FB_CTU_ULINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_CTU_ULINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,3,2, 0); + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CU() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& R() { + return *static_cast(getDI(1)); + } + CIEC_ULINT& PV() { + return *static_cast(getDI(2)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_ULINT& CV() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_CTU_ULINT){}; + virtual ~FB_CTU_ULINT(){}; + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/EdgeDetection/CMakeLists.txt b/src/modules/IEC61131-3/EdgeDetection/CMakeLists.txt new file mode 100644 index 000000000..e70a0f3a5 --- /dev/null +++ b/src/modules/IEC61131-3/EdgeDetection/CMakeLists.txt @@ -0,0 +1,16 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2012 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# EdgeDetection +############################################################################# +forte_add_sourcefile_hcpp(FB_F_TRIG) +forte_add_sourcefile_hcpp(FB_R_TRIG) \ No newline at end of file diff --git a/src/modules/IEC61131-3/EdgeDetection/FB_F_TRIG.cpp b/src/modules/IEC61131-3/EdgeDetection/FB_F_TRIG.cpp new file mode 100644 index 000000000..d8cc751a0 --- /dev/null +++ b/src/modules/IEC61131-3/EdgeDetection/FB_F_TRIG.cpp @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_F_TRIG.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_F_TRIG_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_F_TRIG, g_nStringIdFB_F_TRIG) + +const CStringDictionary::TStringId FB_F_TRIG::scm_anDataInputNames[] = {g_nStringIdCLK}; + +const CStringDictionary::TStringId FB_F_TRIG::scm_anDataOutputNames[] = {g_nStringIdQ}; +const CStringDictionary::TStringId FB_F_TRIG::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; +const CStringDictionary::TStringId FB_F_TRIG::scm_aunDODataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FB_F_TRIG::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_F_TRIG::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FB_F_TRIG::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_F_TRIG::scm_anEOWith[] = {0, 255}; +const TForteInt16 FB_F_TRIG::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_F_TRIG::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_F_TRIG::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_F_TRIG::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + Q() = !CLK() && !M; + M = !CLK(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} diff --git a/src/modules/IEC61131-3/EdgeDetection/FB_F_TRIG.h b/src/modules/IEC61131-3/EdgeDetection/FB_F_TRIG.h new file mode 100644 index 000000000..d1ba7b518 --- /dev/null +++ b/src/modules/IEC61131-3/EdgeDetection/FB_F_TRIG.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_F_TRIG_H_ +#define _FB_F_TRIG_H_ + +#include +#include +#include + +class FB_F_TRIG: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_F_TRIG) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + CIEC_BOOL M; + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CLK() { + return *static_cast(getDI(0)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_F_TRIG){ + M = true; + }; + virtual ~FB_F_TRIG(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/EdgeDetection/FB_R_TRIG.cpp b/src/modules/IEC61131-3/EdgeDetection/FB_R_TRIG.cpp new file mode 100644 index 000000000..15867774a --- /dev/null +++ b/src/modules/IEC61131-3/EdgeDetection/FB_R_TRIG.cpp @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_R_TRIG.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_R_TRIG_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_R_TRIG, g_nStringIdFB_R_TRIG) + +const CStringDictionary::TStringId FB_R_TRIG::scm_anDataInputNames[] = {g_nStringIdCLK}; + +const CStringDictionary::TStringId FB_R_TRIG::scm_anDataOutputNames[] = {g_nStringIdQ}; +const CStringDictionary::TStringId FB_R_TRIG::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; +const CStringDictionary::TStringId FB_R_TRIG::scm_aunDODataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FB_R_TRIG::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_R_TRIG::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FB_R_TRIG::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_R_TRIG::scm_anEOWith[] = {0, 255}; +const TForteInt16 FB_R_TRIG::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_R_TRIG::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_R_TRIG::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_R_TRIG::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + Q() = CLK() && !M; + M = CLK(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + diff --git a/src/modules/IEC61131-3/EdgeDetection/FB_R_TRIG.h b/src/modules/IEC61131-3/EdgeDetection/FB_R_TRIG.h new file mode 100644 index 000000000..b246594aa --- /dev/null +++ b/src/modules/IEC61131-3/EdgeDetection/FB_R_TRIG.h @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_R_TRIG_H_ +#define _FB_R_TRIG_H_ + +#include +#include +#include + +class FB_R_TRIG: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_R_TRIG) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + CIEC_BOOL M; + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& CLK() { + return *static_cast(getDI(0)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_R_TRIG){}; + virtual ~FB_R_TRIG(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/CMakeLists.txt b/src/modules/IEC61131-3/Numerical/CMakeLists.txt new file mode 100644 index 000000000..722b31523 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/CMakeLists.txt @@ -0,0 +1,28 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Numerical +############################################################################# +forte_add_sourcefile_hcpp(F_ABS) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(F_SQRT) + forte_add_sourcefile_hcpp(F_LN) + forte_add_sourcefile_hcpp(F_LOG) + forte_add_sourcefile_hcpp(F_SIN) + forte_add_sourcefile_hcpp(F_COS) + forte_add_sourcefile_hcpp(F_TAN) + forte_add_sourcefile_hcpp(F_ASIN) + forte_add_sourcefile_hcpp(F_ACOS) + forte_add_sourcefile_hcpp(F_ATAN) + forte_add_sourcefile_hcpp(F_EXP) +endif(FORTE_USE_REAL_DATATYPE) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Numerical/F_ABS.cpp b/src/modules/IEC61131-3/Numerical/F_ABS.cpp new file mode 100644 index 000000000..2b375f787 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ABS.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ABS.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ABS_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_ABS, g_nStringIdF_ABS) + +const CStringDictionary::TStringId FORTE_F_ABS::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ABS::scm_anDataInputTypeIds[] = {g_nStringIdANY_NUM}; + +const CStringDictionary::TStringId FORTE_F_ABS::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ABS::scm_anDataOutputTypeIds[] = {g_nStringIdANY_NUM}; + +const TForteInt16 FORTE_F_ABS::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ABS::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ABS::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ABS::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ABS::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ABS::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ABS::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ABS::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyMagnitudeFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_ABS.h b/src/modules/IEC61131-3/Numerical/F_ABS.h new file mode 100644 index 000000000..6be760415 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ABS.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ABS_H_ +#define _F_ABS_H_ + +#include +#include + +class FORTE_F_ABS: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ABS) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_NUM &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_NUM &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ABS){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(ABS(oIn)); + } + + virtual ~FORTE_F_ABS(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_ACOS.cpp b/src/modules/IEC61131-3/Numerical/F_ACOS.cpp new file mode 100644 index 000000000..22b98fb04 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ACOS.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ACOS.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ACOS_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_ACOS, g_nStringIdF_ACOS) + +const CStringDictionary::TStringId FORTE_F_ACOS::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ACOS::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_ACOS::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ACOS::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_ACOS::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ACOS::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ACOS::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ACOS::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ACOS::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ACOS::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ACOS::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ACOS::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_ACOS.h b/src/modules/IEC61131-3/Numerical/F_ACOS.h new file mode 100644 index 000000000..352d1fb85 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ACOS.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ACOS_H_ +#define _F_ACOS_H_ + +#include +#include + +class FORTE_F_ACOS: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ACOS) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ACOS){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(ACOS(oIn)); + } + + virtual ~FORTE_F_ACOS(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_ASIN.cpp b/src/modules/IEC61131-3/Numerical/F_ASIN.cpp new file mode 100644 index 000000000..515a289ab --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ASIN.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ASIN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ASIN_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_ASIN, g_nStringIdF_ASIN) + +const CStringDictionary::TStringId FORTE_F_ASIN::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ASIN::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_ASIN::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ASIN::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_ASIN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ASIN::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ASIN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ASIN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ASIN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ASIN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ASIN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ASIN::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_ASIN.h b/src/modules/IEC61131-3/Numerical/F_ASIN.h new file mode 100644 index 000000000..a338584c2 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ASIN.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ASIN_H_ +#define _F_ASIN_H_ + +#include +#include + +class FORTE_F_ASIN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ASIN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ASIN){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(ASIN(oIn)); + } + + virtual ~FORTE_F_ASIN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_ATAN.cpp b/src/modules/IEC61131-3/Numerical/F_ATAN.cpp new file mode 100644 index 000000000..4024013b3 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ATAN.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_ATAN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_ATAN_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_ATAN, g_nStringIdF_ATAN) + +const CStringDictionary::TStringId FORTE_F_ATAN::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_ATAN::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_ATAN::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_ATAN::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_ATAN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_ATAN::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_ATAN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_ATAN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_ATAN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_ATAN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_ATAN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_ATAN::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_ATAN.h b/src/modules/IEC61131-3/Numerical/F_ATAN.h new file mode 100644 index 000000000..ca5fbc543 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_ATAN.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_ATAN_H_ +#define _F_ATAN_H_ + +#include +#include + +class FORTE_F_ATAN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_ATAN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_ATAN){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(ATAN(oIn)); + } + + virtual ~FORTE_F_ATAN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_COS.cpp b/src/modules/IEC61131-3/Numerical/F_COS.cpp new file mode 100644 index 000000000..4628b333a --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_COS.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_COS.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_COS_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_COS, g_nStringIdF_COS) + +const CStringDictionary::TStringId FORTE_F_COS::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_COS::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_COS::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_COS::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_COS::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_COS::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_COS::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_COS::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_COS::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_COS::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_COS::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_COS::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_COS.h b/src/modules/IEC61131-3/Numerical/F_COS.h new file mode 100644 index 000000000..9f3d272b6 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_COS.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_COS_H_ +#define _F_COS_H_ + +#include +#include + +class FORTE_F_COS: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_COS) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_COS){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(COS(oIn)); + } + + virtual ~FORTE_F_COS(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_EXP.cpp b/src/modules/IEC61131-3/Numerical/F_EXP.cpp new file mode 100644 index 000000000..3aca2887e --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_EXP.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_EXP.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_EXP_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_EXP, g_nStringIdF_EXP) + +const CStringDictionary::TStringId FORTE_F_EXP::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_EXP::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_EXP::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_EXP::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_EXP::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_EXP::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_EXP::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_EXP::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_EXP::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_EXP::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_EXP::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_EXP::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_EXP.h b/src/modules/IEC61131-3/Numerical/F_EXP.h new file mode 100644 index 000000000..07dc75fe2 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_EXP.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_EXP_H_ +#define _F_EXP_H_ + +#include +#include + +class FORTE_F_EXP: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_EXP) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_EXP){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(EXP(oIn)); + } + + virtual ~FORTE_F_EXP(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_LN.cpp b/src/modules/IEC61131-3/Numerical/F_LN.cpp new file mode 100644 index 000000000..39c8fd375 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_LN.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LN_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_LN, g_nStringIdF_LN) + +const CStringDictionary::TStringId FORTE_F_LN::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LN::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_LN::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LN::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_LN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LN::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LN::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_LN.h b/src/modules/IEC61131-3/Numerical/F_LN.h new file mode 100644 index 000000000..d3af6788f --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_LN.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LN_H_ +#define _F_LN_H_ + +#include +#include + +class FORTE_F_LN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LN){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(LN(oIn)); + } + + virtual ~FORTE_F_LN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_LOG.cpp b/src/modules/IEC61131-3/Numerical/F_LOG.cpp new file mode 100644 index 000000000..5de5db679 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_LOG.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_LOG.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LOG_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_LOG, g_nStringIdF_LOG) + +const CStringDictionary::TStringId FORTE_F_LOG::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_LOG::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_LOG::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_LOG::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_LOG::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_LOG::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_LOG::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_LOG::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_LOG::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_LOG::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_LOG::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_LOG::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_LOG.h b/src/modules/IEC61131-3/Numerical/F_LOG.h new file mode 100644 index 000000000..c916222a1 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_LOG.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_LOG_H_ +#define _F_LOG_H_ + +#include +#include + +class FORTE_F_LOG: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LOG) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_LOG){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(LOG(oIn)); + } + + virtual ~FORTE_F_LOG(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_SIN.cpp b/src/modules/IEC61131-3/Numerical/F_SIN.cpp new file mode 100644 index 000000000..ae58dcbe1 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_SIN.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SIN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SIN_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_SIN, g_nStringIdF_SIN) + +const CStringDictionary::TStringId FORTE_F_SIN::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SIN::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_SIN::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SIN::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_SIN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SIN::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SIN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SIN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SIN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SIN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SIN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SIN::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_SIN.h b/src/modules/IEC61131-3/Numerical/F_SIN.h new file mode 100644 index 000000000..8242dd51d --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_SIN.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SIN_H_ +#define _F_SIN_H_ + +#include +#include + +class FORTE_F_SIN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SIN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SIN){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(SIN(oIn)); + } + + virtual ~FORTE_F_SIN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_SQRT.cpp b/src/modules/IEC61131-3/Numerical/F_SQRT.cpp new file mode 100644 index 000000000..827d0a878 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_SQRT.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_SQRT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SQRT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_SQRT, g_nStringIdF_SQRT) + +const CStringDictionary::TStringId FORTE_F_SQRT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_SQRT::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_SQRT::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SQRT::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_SQRT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SQRT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_SQRT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SQRT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SQRT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SQRT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SQRT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SQRT::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_SQRT.h b/src/modules/IEC61131-3/Numerical/F_SQRT.h new file mode 100644 index 000000000..3ffd09f21 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_SQRT.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_SQRT_H_ +#define _F_SQRT_H_ + +#include +#include + +class FORTE_F_SQRT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SQRT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SQRT){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(SQRT(oIn)); + } + + virtual ~FORTE_F_SQRT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Numerical/F_TAN.cpp b/src/modules/IEC61131-3/Numerical/F_TAN.cpp new file mode 100644 index 000000000..0e103c4ef --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_TAN.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_TAN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_TAN_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_TAN, g_nStringIdF_TAN) + +const CStringDictionary::TStringId FORTE_F_TAN::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_F_TAN::scm_anDataInputTypeIds[] = {g_nStringIdANY_REAL}; + +const CStringDictionary::TStringId FORTE_F_TAN::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_TAN::scm_anDataOutputTypeIds[] = {g_nStringIdANY_REAL}; + +const TForteInt16 FORTE_F_TAN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_TAN::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_F_TAN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_TAN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_TAN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_TAN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_TAN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_TAN::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyRealFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Numerical/F_TAN.h b/src/modules/IEC61131-3/Numerical/F_TAN.h new file mode 100644 index 000000000..4abba7e80 --- /dev/null +++ b/src/modules/IEC61131-3/Numerical/F_TAN.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_TAN_H_ +#define _F_TAN_H_ + +#include +#include + +class FORTE_F_TAN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_TAN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_REAL &IN() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_REAL &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 1, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_TAN){ + }; + + template void calculateValue(){ + T oIn; + oIn.saveAssign(IN()); + OUT().saveAssign(TAN(oIn)); + } + + virtual ~FORTE_F_TAN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Selection/CMakeLists.txt b/src/modules/IEC61131-3/Selection/CMakeLists.txt new file mode 100644 index 000000000..0e79e8bf1 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/CMakeLists.txt @@ -0,0 +1,19 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2013 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Selection +############################################################################# +forte_add_sourcefile_hcpp(F_LIMIT) +forte_add_sourcefile_hcpp(F_MIN) +forte_add_sourcefile_hcpp(F_MAX) +forte_add_sourcefile_hcpp(F_SEL) +forte_add_sourcefile_hcpp(F_MUX_2) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Selection/F_LIMIT.cpp b/src/modules/IEC61131-3/Selection/F_LIMIT.cpp new file mode 100644 index 000000000..43fae8e05 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_LIMIT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_LIMIT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_LIMIT_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_LIMIT, g_nStringIdF_LIMIT) + +const CStringDictionary::TStringId FORTE_F_LIMIT::scm_anDataInputNames[] = { + g_nStringIdMN, g_nStringIdIN, g_nStringIdMX }; + +const CStringDictionary::TStringId FORTE_F_LIMIT::scm_anDataInputTypeIds[] = { + g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY, + g_nStringIdANY_ELEMENTARY }; + +const CStringDictionary::TStringId FORTE_F_LIMIT::scm_anDataOutputNames[] = { + g_nStringIdOUT }; + +const CStringDictionary::TStringId FORTE_F_LIMIT::scm_anDataOutputTypeIds[] = { + g_nStringIdANY_ELEMENTARY }; + +const TForteInt16 FORTE_F_LIMIT::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FORTE_F_LIMIT::scm_anEIWith[] = { 0, 2, 1, 255 }; +const CStringDictionary::TStringId FORTE_F_LIMIT::scm_anEventInputNames[] = { + g_nStringIdREQ }; + +const TDataIOID FORTE_F_LIMIT::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 FORTE_F_LIMIT::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FORTE_F_LIMIT::scm_anEventOutputNames[] = { + g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_F_LIMIT::scm_stFBInterfaceSpec = { 1, + scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, + scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, + scm_anDataInputNames, scm_anDataInputTypeIds, 1, scm_anDataOutputNames, + scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_F_LIMIT::executeEvent(int pa_nEIID) { + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +template<> +void FORTE_F_LIMIT::calculateValue(){ + //TODO fill this function +} +#endif diff --git a/src/modules/IEC61131-3/Selection/F_LIMIT.h b/src/modules/IEC61131-3/Selection/F_LIMIT.h new file mode 100644 index 000000000..af0f4c52d --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_LIMIT.h @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Matthias Plasch, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_LIMIT_H_ +#define _F_LIMIT_H_ + +#include +#include + +class FORTE_F_LIMIT : public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_LIMIT) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &MN(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_ANY_ELEMENTARY &IN(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_ANY_ELEMENTARY &MX(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_ELEMENTARY &OUT(){ + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0) + ; + + void executeEvent(int pa_nEIID); + + public: + FUNCTION_BLOCK_CTOR(FORTE_F_LIMIT){ + }; + + template void calculateValue(){ + T oMin; + T oMax; + + oMin.saveAssign(MN()); + oMax.saveAssign(MX()); + + OUT().saveAssign(LIMIT (oMin, static_cast (IN()), oMax)); + } + + template void calculateValueString(){ + //TODO fill this function + } + virtual ~FORTE_F_LIMIT(){}; +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/IEC61131-3/Selection/F_MAX.cpp b/src/modules/IEC61131-3/Selection/F_MAX.cpp new file mode 100644 index 000000000..da49c84f7 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_MAX.cpp @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_MAX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MAX_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_MAX, g_nStringIdF_MAX) + +const CStringDictionary::TStringId FORTE_F_MAX::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_MAX::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_MAX::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MAX::scm_anDataOutputTypeIds[] = {g_nStringIdANY_ELEMENTARY}; + +const TForteInt16 FORTE_F_MAX::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MAX::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_MAX::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MAX::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MAX::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_MAX::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MAX::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MAX::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + +#ifdef FORTE_USE_WSTRING_DATATYPE +template<> +void FORTE_F_MAX::calculateValue(){ + //TODO fill this function +} +#endif diff --git a/src/modules/IEC61131-3/Selection/F_MAX.h b/src/modules/IEC61131-3/Selection/F_MAX.h new file mode 100644 index 000000000..c45758a19 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_MAX.h @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Matthias Plasch, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_MAX_H_ +#define _F_MAX_H_ + +#include +#include + +class FORTE_F_MAX: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MAX) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_ELEMENTARY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_ELEMENTARY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MAX){ + }; + + template void calculateValue(){ + T oMin; + T oMax; + + oMin.saveAssign(IN1()); + oMax.saveAssign(IN2()); + + OUT().saveAssign(MAX (oMin, oMax)); + } + + template void calculateValueString(){ + //TODO fill this function + } + virtual ~FORTE_F_MAX(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Selection/F_MIN.cpp b/src/modules/IEC61131-3/Selection/F_MIN.cpp new file mode 100644 index 000000000..25bbf36f2 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_MIN.cpp @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_MIN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MIN_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_MIN, g_nStringIdF_MIN) + +const CStringDictionary::TStringId FORTE_F_MIN::scm_anDataInputNames[] = {g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_MIN::scm_anDataInputTypeIds[] = {g_nStringIdANY_ELEMENTARY, g_nStringIdANY_ELEMENTARY}; + +const CStringDictionary::TStringId FORTE_F_MIN::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MIN::scm_anDataOutputTypeIds[] = {g_nStringIdANY_ELEMENTARY}; + +const TForteInt16 FORTE_F_MIN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MIN::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_F_MIN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MIN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MIN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_MIN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MIN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MIN::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN1().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + +#ifdef FORTE_USE_WSTRING_DATATYPE +template<> +void FORTE_F_MIN::calculateValue(){ + //TODO fill this function +} +#endif + diff --git a/src/modules/IEC61131-3/Selection/F_MIN.h b/src/modules/IEC61131-3/Selection/F_MIN.h new file mode 100644 index 000000000..fb39ec0c0 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_MIN.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Matthias Plasch, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_MIN_H_ +#define _F_MIN_H_ + +#include +#include + +class FORTE_F_MIN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MIN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_ELEMENTARY &IN1() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY_ELEMENTARY &IN2() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY_ELEMENTARY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 1, 0); + + void executeEvent(int pa_nEIID); + + + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MIN){ + }; + + template void calculateValue(){ + T oMin; + T oMax; + + oMin.saveAssign(IN1()); + oMax.saveAssign(IN2()); + + OUT().saveAssign(MIN (oMin, oMax)); + } + + template void calculateValueString(){ + //TODO fill this function + } + + virtual ~FORTE_F_MIN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Selection/F_MUX_2.cpp b/src/modules/IEC61131-3/Selection/F_MUX_2.cpp new file mode 100644 index 000000000..b732845ef --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_MUX_2.cpp @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "F_MUX_2.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_MUX_2_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_F_MUX_2, g_nStringIdF_MUX_2) + +const CStringDictionary::TStringId FORTE_F_MUX_2::scm_anDataInputNames[] = {g_nStringIdK, g_nStringIdIN1, g_nStringIdIN2}; + +const CStringDictionary::TStringId FORTE_F_MUX_2::scm_anDataInputTypeIds[] = {g_nStringIdANY_INT, g_nStringIdANY, g_nStringIdANY}; + +const CStringDictionary::TStringId FORTE_F_MUX_2::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_MUX_2::scm_anDataOutputTypeIds[] = {g_nStringIdANY}; + +const TForteInt16 FORTE_F_MUX_2::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_MUX_2::scm_anEIWith[] = {1, 2, 0, 255}; +const CStringDictionary::TStringId FORTE_F_MUX_2::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_MUX_2::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_MUX_2::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_MUX_2::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_MUX_2::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_MUX_2::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + if(K().isSigned() && (K().getSignedValue() < 0 || K().getSignedValue() > 1)){ + DEVLOG_ERROR("value of input K is not between 0 and 1"); + }else{ + OUT().saveAssign(*static_cast(getDI( static_cast(K().getUnsignedValue() + 1)))); + sendOutputEvent(scm_nEventCNFID); + } + } +} + + + diff --git a/src/modules/IEC61131-3/Selection/F_MUX_2.h b/src/modules/IEC61131-3/Selection/F_MUX_2.h new file mode 100644 index 000000000..61c10246f --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_MUX_2.h @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _F_MUX_2_H_ +#define _F_MUX_2_H_ + +#include +#include +#include + +class FORTE_F_MUX_2: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_MUX_2) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY_INT &K() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY &IN1() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY &IN2() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_MUX_2){ + }; + + virtual ~FORTE_F_MUX_2(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Selection/F_SEL.cpp b/src/modules/IEC61131-3/Selection/F_SEL.cpp new file mode 100644 index 000000000..7316f1911 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_SEL.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "F_SEL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "F_SEL_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_F_SEL, g_nStringIdF_SEL) + +const CStringDictionary::TStringId FORTE_F_SEL::scm_anDataInputNames[] = {g_nStringIdG, g_nStringIdIN0, g_nStringIdIN1}; + +const CStringDictionary::TStringId FORTE_F_SEL::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdANY, g_nStringIdANY}; + +const CStringDictionary::TStringId FORTE_F_SEL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_F_SEL::scm_anDataOutputTypeIds[] = {g_nStringIdANY}; + +const TForteInt16 FORTE_F_SEL::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_F_SEL::scm_anEIWith[] = {0, 2, 1, 255}; +const CStringDictionary::TStringId FORTE_F_SEL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_F_SEL::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_F_SEL::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_F_SEL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_F_SEL::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_F_SEL::executeEvent(int pa_nEIID){ + if (scm_nEventREQID == pa_nEIID) { + anyElementaryFBHelper(IN0().getDataTypeID(), *this); + sendOutputEvent(scm_nEventCNFID); + } +} + + + diff --git a/src/modules/IEC61131-3/Selection/F_SEL.h b/src/modules/IEC61131-3/Selection/F_SEL.h new file mode 100644 index 000000000..24ed06f99 --- /dev/null +++ b/src/modules/IEC61131-3/Selection/F_SEL.h @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _F_SEL_H_ +#define _F_SEL_H_ + +#include +#include +#include + +class FORTE_F_SEL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_F_SEL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &G() { + return *static_cast(getDI(0)); + }; + + CIEC_ANY &IN0() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY &IN1() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_ANY &OUT() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_F_SEL){ + }; + + virtual ~FORTE_F_SEL(){}; + + template void calculateValue(){ + T oIn0; + T oIn1; + oIn0.saveAssign(IN0()); + oIn1.saveAssign(IN1()); + + OUT().saveAssign(SEL (G(), oIn0, oIn1)); + } + + template void calculateValueString(){ + calculateValue(); + } + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Timers/CMakeLists.txt b/src/modules/IEC61131-3/Timers/CMakeLists.txt new file mode 100644 index 000000000..5d4cff1ea --- /dev/null +++ b/src/modules/IEC61131-3/Timers/CMakeLists.txt @@ -0,0 +1,17 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2012 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Timers +############################################################################# +forte_add_sourcefile_hcpp(FB_TOF) +forte_add_sourcefile_hcpp(FB_TON) +forte_add_sourcefile_hcpp(FB_TP) \ No newline at end of file diff --git a/src/modules/IEC61131-3/Timers/FB_TOF.cpp b/src/modules/IEC61131-3/Timers/FB_TOF.cpp new file mode 100644 index 000000000..ad845c835 --- /dev/null +++ b/src/modules/IEC61131-3/Timers/FB_TOF.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_TOF.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_TOF_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_TOF, g_nStringIdFB_TOF) + +const CStringDictionary::TStringId FB_TOF::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdPT}; + +const CStringDictionary::TStringId FB_TOF::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdET}; +const CStringDictionary::TStringId FB_TOF::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME}; +const CStringDictionary::TStringId FB_TOF::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME}; + +const TForteInt16 FB_TOF::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_TOF::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FB_TOF::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_TOF::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_TOF::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_TOF::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_TOF::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 2, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_TOF::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + if(IN() == true){ + Q() = true; + ET() = 0; + fallingEdge = false; + notFirstRisingEdge = true; + start = 0; + } + else{ + if(true == notFirstRisingEdge){ + if(fallingEdge == false){ + fallingEdge = true; + start = TIME(); + } + else{ + count = TIME() - start; + if(PT() <= count){ + Q() = false; + ET() = PT(); + }else{ + ET() = count; + } + } + } + } + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Timers/FB_TOF.h b/src/modules/IEC61131-3/Timers/FB_TOF.h new file mode 100644 index 000000000..4ee2ed8e7 --- /dev/null +++ b/src/modules/IEC61131-3/Timers/FB_TOF.h @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_TOF_H_ +#define _FB_TOF_H_ + +#include +#include +#include "../../arch/timerha.h" +#include +#include + +class FB_TOF: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_TOF) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,2,2, 0); + + bool fallingEdge; + bool notFirstRisingEdge; + CIEC_TIME start; + CIEC_TIME count; + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& IN() { + return *static_cast(getDI(0)); + } + + CIEC_TIME& PT() { + return *static_cast(getDI(1)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + + CIEC_TIME& ET() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_TOF){}; + virtual ~FB_TOF(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Timers/FB_TON.cpp b/src/modules/IEC61131-3/Timers/FB_TON.cpp new file mode 100644 index 000000000..3d1307687 --- /dev/null +++ b/src/modules/IEC61131-3/Timers/FB_TON.cpp @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_TON.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_TON_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FB_TON, g_nStringIdFB_TON) + +const CStringDictionary::TStringId FB_TON::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdPT}; + +const CStringDictionary::TStringId FB_TON::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdET}; +const CStringDictionary::TStringId FB_TON::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME}; +const CStringDictionary::TStringId FB_TON::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME}; + +const TForteInt16 FB_TON::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_TON::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FB_TON::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_TON::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_TON::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_TON::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_TON::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 2, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_TON::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + if(IN() == false){ + Q() = false; + ET() = 0; + risingEdge = false; + start = 0; + } + else{ + if(risingEdge == false){ + risingEdge = true; + start = TIME(); + }else{ + count = TIME() - start; + if(PT() <= count){ + Q() = true; + ET() = PT(); + }else{ + ET() = count; + } + } + } + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Timers/FB_TON.h b/src/modules/IEC61131-3/Timers/FB_TON.h new file mode 100644 index 000000000..62f319d82 --- /dev/null +++ b/src/modules/IEC61131-3/Timers/FB_TON.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_TON_H_ +#define _FB_TON_H_ + +#include +#include +#include "../../arch/timerha.h" +#include +#include + +class FB_TON: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_TON) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,2,2, 0); + + bool risingEdge; + CIEC_TIME start; + CIEC_TIME count; + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& IN() { + return *static_cast(getDI(0)); + } + + CIEC_TIME& PT() { + return *static_cast(getDI(1)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + + CIEC_TIME& ET() { + return *static_cast(getDO(1)); + } + +public: + FUNCTION_BLOCK_CTOR(FB_TON){}; + virtual ~FB_TON(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/IEC61131-3/Timers/FB_TP.cpp b/src/modules/IEC61131-3/Timers/FB_TP.cpp new file mode 100644 index 000000000..dc1461089 --- /dev/null +++ b/src/modules/IEC61131-3/Timers/FB_TP.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "FB_TP.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "FB_TP_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FB_TP, g_nStringIdFB_TP) + +const CStringDictionary::TStringId FB_TP::scm_anDataInputNames[] = {g_nStringIdIN, g_nStringIdPT}; + +const CStringDictionary::TStringId FB_TP::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdET}; +const CStringDictionary::TStringId FB_TP::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME}; +const CStringDictionary::TStringId FB_TP::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME}; + +const TForteInt16 FB_TP::scm_anEIWithIndexes[] = {0}; +const TDataIOID FB_TP::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FB_TP::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FB_TP::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FB_TP::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId FB_TP::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FB_TP::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 2, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void FB_TP::executeEvent(int pa_nEIID){ + if(pa_nEIID == scm_nEventREQID){ + if (edgeFlag) { + if(ET() >= PT()){ + Q() = false; + edgeFlag = false; + DEVLOG_DEBUG("top\n"); + }else{ + ET() = TIME() - start; + DEVLOG_DEBUG("rising\n"); + } + } + else { + if(IN() == true && ET() == 0){ + Q() = true; + edgeFlag = true; + start = TIME(); + DEVLOG_DEBUG("start\n"); + } + else + if((false == IN()) && (ET()>0)) { + ET() = 0; + DEVLOG_DEBUG("reset\n"); + } + } + sendOutputEvent(scm_nEventCNFID); + } +} diff --git a/src/modules/IEC61131-3/Timers/FB_TP.h b/src/modules/IEC61131-3/Timers/FB_TP.h new file mode 100644 index 000000000..13152fd8d --- /dev/null +++ b/src/modules/IEC61131-3/Timers/FB_TP.h @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2009 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger, Alois Zoitl, Ingo Hengy + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _FB_TP_H_ +#define _FB_TP_H_ + +#include +#include +#include "../../arch/timerha.h" +#include +#include + +class FB_TP: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FB_TP) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,2,2, 0); + + bool edgeFlag; + CIEC_TIME start; + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& IN() { + return *static_cast(getDI(0)); + } + + CIEC_TIME& PT() { + return *static_cast(getDI(1)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + + CIEC_TIME& ET() { + return *static_cast(getDO(1)); + } +public: + FUNCTION_BLOCK_CTOR(FB_TP){}; + virtual ~FB_TP(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/BOOL2BOOL.cpp b/src/modules/convert/BOOL2BOOL.cpp new file mode 100644 index 000000000..c2ae0023d --- /dev/null +++ b/src/modules/convert/BOOL2BOOL.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, +S * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "BOOL2BOOL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "BOOL2BOOL_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(BOOL2BOOL, g_nStringIdBOOL2BOOL) + +const CStringDictionary::TStringId BOOL2BOOL::scm_anDataInputNames[] = {g_nStringIdIN}; +const CStringDictionary::TStringId BOOL2BOOL::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const CStringDictionary::TStringId BOOL2BOOL::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; +const CStringDictionary::TStringId BOOL2BOOL::scm_aunDODataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 BOOL2BOOL::scm_anEIWithIndexes[] = {0}; +const TDataIOID BOOL2BOOL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId BOOL2BOOL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID BOOL2BOOL::scm_anEOWith[] = {0, 255}; +const TForteInt16 BOOL2BOOL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId BOOL2BOOL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec BOOL2BOOL::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void BOOL2BOOL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +BOOL2BOOL::~BOOL2BOOL(){ +} + + + diff --git a/src/modules/convert/BOOL2BOOL.h b/src/modules/convert/BOOL2BOOL.h new file mode 100644 index 000000000..ef280ca3e --- /dev/null +++ b/src/modules/convert/BOOL2BOOL.h @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _BOOL2BOOL_H_ +#define _BOOL2BOOL_H_ + +#include +#include + + +class BOOL2BOOL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(BOOL2BOOL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + +CIEC_BOOL& IN() { + return *static_cast(getDI(0)); +} + +CIEC_BOOL& OUT() { + return *static_cast(getDO(0)); +} + +public: + FUNCTION_BLOCK_CTOR(BOOL2BOOL){}; + virtual ~BOOL2BOOL(); + + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/BYTE2BYTE.cpp b/src/modules/convert/BYTE2BYTE.cpp new file mode 100644 index 000000000..8bbf084ff --- /dev/null +++ b/src/modules/convert/BYTE2BYTE.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "BYTE2BYTE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "BYTE2BYTE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(BYTE2BYTE, g_nStringIdBYTE2BYTE) + +const CStringDictionary::TStringId BYTE2BYTE::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId BYTE2BYTE::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId BYTE2BYTE::scm_aunDIDataTypeIds[] = {g_nStringIdBYTE}; +const CStringDictionary::TStringId BYTE2BYTE::scm_aunDODataTypeIds[] = {g_nStringIdBYTE}; + +const TForteInt16 BYTE2BYTE::scm_anEIWithIndexes[] = {0}; +const TDataIOID BYTE2BYTE::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId BYTE2BYTE::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID BYTE2BYTE::scm_anEOWith[] = {0, 255}; +const TForteInt16 BYTE2BYTE::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId BYTE2BYTE::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec BYTE2BYTE::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void BYTE2BYTE::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +BYTE2BYTE::~BYTE2BYTE(){ +} + + + diff --git a/src/modules/convert/BYTE2BYTE.h b/src/modules/convert/BYTE2BYTE.h new file mode 100644 index 000000000..a352154bb --- /dev/null +++ b/src/modules/convert/BYTE2BYTE.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _BYTE2BYTE_H_ +#define _BYTE2BYTE_H_ + +#include +#include + + +class BYTE2BYTE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(BYTE2BYTE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_BYTE& IN() { + return *static_cast(getDI(0)); + } + + CIEC_BYTE& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(BYTE2BYTE){}; + virtual ~BYTE2BYTE(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/CMakeLists.txt b/src/modules/convert/CMakeLists.txt new file mode 100644 index 000000000..207cc72b0 --- /dev/null +++ b/src/modules/convert/CMakeLists.txt @@ -0,0 +1,29 @@ +#******************************************************************************* +# * Copyright (c) 2010, 2011 Profactor GmbH, ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Micheal Hofmann, Alois Zoitl +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +forte_add_module(CONVERT "Convert Function Blocks") + +############################################################################# +# Convert FB +############################################################################# +forte_add_sourcefile_hcpp( BOOL2BOOL BYTE2BYTE DINT2DINT DWORD2DWORD ) +forte_add_sourcefile_hcpp( INT2INT SINT2SINT ) +forte_add_sourcefile_hcpp( STRING2STRING TIME2TIME UINT2UINT UDINT2UDINT ) +forte_add_sourcefile_hcpp( USINT2USINT WORD2WORD WSTRING2WSTRING ) + +if(FORTE_USE_REAL_DATATYPE) + forte_add_sourcefile_hcpp(REAL2REAL) +endif(FORTE_USE_REAL_DATATYPE) + +if(FORTE_USE_LREAL_DATATYPE) + forte_add_sourcefile_hcpp(LREAL2LREAL) +endif(FORTE_USE_LREAL_DATATYPE) + diff --git a/src/modules/convert/DINT2DINT.cpp b/src/modules/convert/DINT2DINT.cpp new file mode 100644 index 000000000..89eeca6e4 --- /dev/null +++ b/src/modules/convert/DINT2DINT.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "DINT2DINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "DINT2DINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(DINT2DINT, g_nStringIdDINT2DINT) + +const CStringDictionary::TStringId DINT2DINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId DINT2DINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId DINT2DINT::scm_aunDIDataTypeIds[] = {g_nStringIdDINT}; +const CStringDictionary::TStringId DINT2DINT::scm_aunDODataTypeIds[] = {g_nStringIdDINT}; + +const TForteInt16 DINT2DINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID DINT2DINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId DINT2DINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID DINT2DINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 DINT2DINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId DINT2DINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec DINT2DINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void DINT2DINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + + +DINT2DINT::~DINT2DINT(){ +} + + + diff --git a/src/modules/convert/DINT2DINT.h b/src/modules/convert/DINT2DINT.h new file mode 100644 index 000000000..f3ee55a0e --- /dev/null +++ b/src/modules/convert/DINT2DINT.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _DINT2DINT_H_ +#define _DINT2DINT_H_ + +#include +#include + + +class DINT2DINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(DINT2DINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + + virtual void executeEvent(int pa_nEIID); + + CIEC_DINT& IN() { + return *static_cast(getDI(0)); + } + + CIEC_DINT& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(DINT2DINT){}; + virtual ~DINT2DINT(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/DWORD2DWORD.cpp b/src/modules/convert/DWORD2DWORD.cpp new file mode 100644 index 000000000..9c6ee13c2 --- /dev/null +++ b/src/modules/convert/DWORD2DWORD.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "DWORD2DWORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "DWORD2DWORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(DWORD2DWORD, g_nStringIdDWORD2DWORD) + + +const CStringDictionary::TStringId DWORD2DWORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId DWORD2DWORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId DWORD2DWORD::scm_aunDIDataTypeIds[] = {g_nStringIdDWORD}; +const CStringDictionary::TStringId DWORD2DWORD::scm_aunDODataTypeIds[] = {g_nStringIdDWORD}; + +const TForteInt16 DWORD2DWORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID DWORD2DWORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId DWORD2DWORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID DWORD2DWORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 DWORD2DWORD::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId DWORD2DWORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec DWORD2DWORD::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void DWORD2DWORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +DWORD2DWORD::~DWORD2DWORD(){ +} + + + diff --git a/src/modules/convert/DWORD2DWORD.h b/src/modules/convert/DWORD2DWORD.h new file mode 100644 index 000000000..76231b3fc --- /dev/null +++ b/src/modules/convert/DWORD2DWORD.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _DWORD2DWORD_H_ +#define _DWORD2DWORD_H_ + +#include +#include + + +class DWORD2DWORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(DWORD2DWORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_DWORD& IN() { + return *static_cast(getDI(0)); + } + + CIEC_DWORD& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(DWORD2DWORD){}; + virtual ~DWORD2DWORD(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/INT2INT.cpp b/src/modules/convert/INT2INT.cpp new file mode 100644 index 000000000..c1472ba98 --- /dev/null +++ b/src/modules/convert/INT2INT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "INT2INT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "INT2INT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(INT2INT, g_nStringIdINT2INT) + +const CStringDictionary::TStringId INT2INT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId INT2INT::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId INT2INT::scm_aunDIDataTypeIds[] = {g_nStringIdINT}; +const CStringDictionary::TStringId INT2INT::scm_aunDODataTypeIds[] = {g_nStringIdINT}; + +const TForteInt16 INT2INT::scm_anEIWithIndexes[] = {0}; +const TDataIOID INT2INT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId INT2INT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID INT2INT::scm_anEOWith[] = {0, 255}; +const TForteInt16 INT2INT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId INT2INT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec INT2INT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void INT2INT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +INT2INT::~INT2INT(){ +} + + + diff --git a/src/modules/convert/INT2INT.h b/src/modules/convert/INT2INT.h new file mode 100644 index 000000000..69aaab2ee --- /dev/null +++ b/src/modules/convert/INT2INT.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _INT2INT_H_ +#define _INT2INT_H_ + +#include +#include + + +class INT2INT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(INT2INT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_INT& IN() { + return *static_cast(getDI(0)); + } + + CIEC_INT& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(INT2INT){}; + virtual ~INT2INT(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/LREAL2LREAL.cpp b/src/modules/convert/LREAL2LREAL.cpp new file mode 100644 index 000000000..8bf75e817 --- /dev/null +++ b/src/modules/convert/LREAL2LREAL.cpp @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "LREAL2LREAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "LREAL2LREAL_gen.cpp" +#endif + +#ifdef FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + +DEFINE_FIRMWARE_FB(LREAL2LREAL, g_nStringIdLREAL2LREAL) + +const CStringDictionary::TStringId LREAL2LREAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId LREAL2LREAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId LREAL2LREAL::scm_aunDIDataTypeIds[] = {g_nStringIdLREAL}; +const CStringDictionary::TStringId LREAL2LREAL::scm_aunDODataTypeIds[] = {g_nStringIdLREAL}; + +const TForteInt16 LREAL2LREAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID LREAL2LREAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId LREAL2LREAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID LREAL2LREAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 LREAL2LREAL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId LREAL2LREAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec LREAL2LREAL::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void LREAL2LREAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +LREAL2LREAL::~LREAL2LREAL(){ +} + +#endif +#endif + diff --git a/src/modules/convert/LREAL2LREAL.h b/src/modules/convert/LREAL2LREAL.h new file mode 100644 index 000000000..9a8bbc4fe --- /dev/null +++ b/src/modules/convert/LREAL2LREAL.h @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _LREAL2LREAL_H_ +#define _LREAL2LREAL_H_ + +#include +#include + +#ifdef FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + +class LREAL2LREAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(LREAL2LREAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_LREAL& IN() { + return *static_cast(getDI(0)); + } + + CIEC_LREAL& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(LREAL2LREAL){}; + virtual ~LREAL2LREAL(); + +}; + +#endif +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/REAL2REAL.cpp b/src/modules/convert/REAL2REAL.cpp new file mode 100644 index 000000000..72a3a03fa --- /dev/null +++ b/src/modules/convert/REAL2REAL.cpp @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "REAL2REAL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "REAL2REAL_gen.cpp" +#endif + +#ifdef FORTE_USE_REAL_DATATYPE + +DEFINE_FIRMWARE_FB(REAL2REAL, g_nStringIdREAL2REAL) + +const CStringDictionary::TStringId REAL2REAL::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId REAL2REAL::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId REAL2REAL::scm_aunDIDataTypeIds[] = {g_nStringIdREAL}; +const CStringDictionary::TStringId REAL2REAL::scm_aunDODataTypeIds[] = {g_nStringIdREAL}; + +const TForteInt16 REAL2REAL::scm_anEIWithIndexes[] = {0}; +const TDataIOID REAL2REAL::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId REAL2REAL::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID REAL2REAL::scm_anEOWith[] = {0, 255}; +const TForteInt16 REAL2REAL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId REAL2REAL::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec REAL2REAL::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void REAL2REAL::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +REAL2REAL::~REAL2REAL(){ +} + +#endif + diff --git a/src/modules/convert/REAL2REAL.h b/src/modules/convert/REAL2REAL.h new file mode 100644 index 000000000..7f9de8d43 --- /dev/null +++ b/src/modules/convert/REAL2REAL.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _REAL2REAL_H_ +#define _REAL2REAL_H_ + +#include +#include + +#ifdef FORTE_USE_REAL_DATATYPE + +class REAL2REAL: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(REAL2REAL) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_REAL& IN() { + return *static_cast(getDI(0)); + } + + CIEC_REAL& OUT() { + return *static_cast(getDO(0)); + } + + +public: + FUNCTION_BLOCK_CTOR(REAL2REAL) {}; + virtual ~REAL2REAL(); + +}; + +#endif + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/SINT2SINT.cpp b/src/modules/convert/SINT2SINT.cpp new file mode 100644 index 000000000..a0ed43429 --- /dev/null +++ b/src/modules/convert/SINT2SINT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "SINT2SINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "SINT2SINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(SINT2SINT, g_nStringIdSINT2SINT) + +const CStringDictionary::TStringId SINT2SINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId SINT2SINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId SINT2SINT::scm_aunDIDataTypeIds[] = {g_nStringIdSINT}; +const CStringDictionary::TStringId SINT2SINT::scm_aunDODataTypeIds[] = {g_nStringIdSINT}; + +const TForteInt16 SINT2SINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID SINT2SINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId SINT2SINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID SINT2SINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 SINT2SINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId SINT2SINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec SINT2SINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void SINT2SINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +SINT2SINT::~SINT2SINT(){ +} + + + diff --git a/src/modules/convert/SINT2SINT.h b/src/modules/convert/SINT2SINT.h new file mode 100644 index 000000000..107f47ddc --- /dev/null +++ b/src/modules/convert/SINT2SINT.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SINT2SINT_H_ +#define _SINT2SINT_H_ + +#include +#include + + +class SINT2SINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(SINT2SINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_SINT& IN() { + return *static_cast(getDI(0)); + } + + CIEC_SINT& OUT() { + return *static_cast(getDO(0)); + } + + +public: + FUNCTION_BLOCK_CTOR(SINT2SINT){}; + virtual ~SINT2SINT(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/STRING2STRING.cpp b/src/modules/convert/STRING2STRING.cpp new file mode 100644 index 000000000..8edcad011 --- /dev/null +++ b/src/modules/convert/STRING2STRING.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "STRING2STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "STRING2STRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(STRING2STRING, g_nStringIdSTRING2STRING) + +const CStringDictionary::TStringId STRING2STRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId STRING2STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId STRING2STRING::scm_aunDIDataTypeIds[] = {g_nStringIdSTRING}; +const CStringDictionary::TStringId STRING2STRING::scm_aunDODataTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 STRING2STRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID STRING2STRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId STRING2STRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID STRING2STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 STRING2STRING::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId STRING2STRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec STRING2STRING::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void STRING2STRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +STRING2STRING::~STRING2STRING(){ +} + + + diff --git a/src/modules/convert/STRING2STRING.h b/src/modules/convert/STRING2STRING.h new file mode 100644 index 000000000..68ffd6b4c --- /dev/null +++ b/src/modules/convert/STRING2STRING.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _STRING2STRING_H_ +#define _STRING2STRING_H_ + +#include +#include + + +class STRING2STRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(STRING2STRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_STRING& IN() { + return *static_cast(getDI(0)); + } + + CIEC_STRING& OUT() { + return *static_cast(getDO(0)); + } + + +public: + FUNCTION_BLOCK_CTOR(STRING2STRING){}; + virtual ~STRING2STRING(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/TIME2TIME.cpp b/src/modules/convert/TIME2TIME.cpp new file mode 100644 index 000000000..60e21d62f --- /dev/null +++ b/src/modules/convert/TIME2TIME.cpp @@ -0,0 +1,59 @@ +/************************************************************************* + *** FORTE Library Element + *** + *** Name: TIME2TIME + *** Description: Basic Function Block Type + *** Version: + *** 1.0: 2006-11-14/TS - PROFACTOR GmbH - + *************************************************************************/ + +#include "TIME2TIME.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "TIME2TIME_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(TIME2TIME, g_nStringIdTIME2TIME) + +const CStringDictionary::TStringId TIME2TIME::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId TIME2TIME::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId TIME2TIME::scm_aunDIDataTypeIds[] = {g_nStringIdTIME}; +const CStringDictionary::TStringId TIME2TIME::scm_aunDODataTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 TIME2TIME::scm_anEIWithIndexes[] = {0}; +const TDataIOID TIME2TIME::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId TIME2TIME::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID TIME2TIME::scm_anEOWith[] = {0, 255}; +const TForteInt16 TIME2TIME::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId TIME2TIME::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec TIME2TIME::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void TIME2TIME::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +TIME2TIME::~TIME2TIME(){ +} + + + diff --git a/src/modules/convert/TIME2TIME.h b/src/modules/convert/TIME2TIME.h new file mode 100644 index 000000000..e1a4d2cb0 --- /dev/null +++ b/src/modules/convert/TIME2TIME.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _TIME2TIME_H_ +#define _TIME2TIME_H_ + +#include +#include + + +class TIME2TIME: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(TIME2TIME) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_TIME& IN() { + return *static_cast(getDI(0)); + } + + CIEC_TIME& OUT() { + return *static_cast(getDO(0)); + } + + +public: + FUNCTION_BLOCK_CTOR(TIME2TIME){}; + virtual ~TIME2TIME(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/UDINT2UDINT.cpp b/src/modules/convert/UDINT2UDINT.cpp new file mode 100644 index 000000000..ebe1a2271 --- /dev/null +++ b/src/modules/convert/UDINT2UDINT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "UDINT2UDINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "UDINT2UDINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(UDINT2UDINT, g_nStringIdUDINT2UDINT) + +const CStringDictionary::TStringId UDINT2UDINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId UDINT2UDINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId UDINT2UDINT::scm_aunDIDataTypeIds[] = {g_nStringIdUDINT}; +const CStringDictionary::TStringId UDINT2UDINT::scm_aunDODataTypeIds[] = {g_nStringIdUDINT}; + +const TForteInt16 UDINT2UDINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID UDINT2UDINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId UDINT2UDINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID UDINT2UDINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 UDINT2UDINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId UDINT2UDINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec UDINT2UDINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void UDINT2UDINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +UDINT2UDINT::~UDINT2UDINT(){ +} + + + diff --git a/src/modules/convert/UDINT2UDINT.h b/src/modules/convert/UDINT2UDINT.h new file mode 100644 index 000000000..c0426b2b9 --- /dev/null +++ b/src/modules/convert/UDINT2UDINT.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _UDINT2UDINT_H_ +#define _UDINT2UDINT_H_ + +#include +#include + + +class UDINT2UDINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(UDINT2UDINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_UDINT& IN() { + return *static_cast(getDI(0)); + } + + CIEC_UDINT& OUT() { + return *static_cast(getDO(0)); + } + + +public: + FUNCTION_BLOCK_CTOR(UDINT2UDINT) {}; + virtual ~UDINT2UDINT(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/UINT2UINT.cpp b/src/modules/convert/UINT2UINT.cpp new file mode 100644 index 000000000..420b66e90 --- /dev/null +++ b/src/modules/convert/UINT2UINT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "UINT2UINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "UINT2UINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(UINT2UINT, g_nStringIdUINT2UINT) + +const CStringDictionary::TStringId UINT2UINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId UINT2UINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId UINT2UINT::scm_aunDIDataTypeIds[] = {g_nStringIdUINT}; +const CStringDictionary::TStringId UINT2UINT::scm_aunDODataTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 UINT2UINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID UINT2UINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId UINT2UINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID UINT2UINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 UINT2UINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId UINT2UINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec UINT2UINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void UINT2UINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +UINT2UINT::~UINT2UINT(){ +} + + + diff --git a/src/modules/convert/UINT2UINT.h b/src/modules/convert/UINT2UINT.h new file mode 100644 index 000000000..039484e4d --- /dev/null +++ b/src/modules/convert/UINT2UINT.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _UINT2UINT_H_ +#define _UINT2UINT_H_ + +#include +#include + +class UINT2UINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(UINT2UINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_UINT& IN() { + return *static_cast(getDI(0)); + } + + CIEC_UINT& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(UINT2UINT){}; + virtual ~UINT2UINT(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/USINT2USINT.cpp b/src/modules/convert/USINT2USINT.cpp new file mode 100644 index 000000000..5c3a6e221 --- /dev/null +++ b/src/modules/convert/USINT2USINT.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "USINT2USINT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "USINT2USINT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(USINT2USINT, g_nStringIdUSINT2USINT) + +const CStringDictionary::TStringId USINT2USINT::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId USINT2USINT::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId USINT2USINT::scm_aunDIDataTypeIds[] = {g_nStringIdUSINT}; +const CStringDictionary::TStringId USINT2USINT::scm_aunDODataTypeIds[] = {g_nStringIdUSINT}; + +const TForteInt16 USINT2USINT::scm_anEIWithIndexes[] = {0}; +const TDataIOID USINT2USINT::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId USINT2USINT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID USINT2USINT::scm_anEOWith[] = {0, 255}; +const TForteInt16 USINT2USINT::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId USINT2USINT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec USINT2USINT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void USINT2USINT::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +USINT2USINT::~USINT2USINT(){ +} + + + diff --git a/src/modules/convert/USINT2USINT.h b/src/modules/convert/USINT2USINT.h new file mode 100644 index 000000000..51be7c38a --- /dev/null +++ b/src/modules/convert/USINT2USINT.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _USINT2USINT_H_ +#define _USINT2USINT_H_ + +#include +#include + +class USINT2USINT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(USINT2USINT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_USINT& IN() { + return *static_cast(getDI(0)); + } + + CIEC_USINT& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(USINT2USINT){}; + virtual ~USINT2USINT(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/WORD2WORD.cpp b/src/modules/convert/WORD2WORD.cpp new file mode 100644 index 000000000..dd10b4b1b --- /dev/null +++ b/src/modules/convert/WORD2WORD.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "WORD2WORD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "WORD2WORD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(WORD2WORD, g_nStringIdWORD2WORD) + +const CStringDictionary::TStringId WORD2WORD::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId WORD2WORD::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId WORD2WORD::scm_aunDIDataTypeIds[] = {g_nStringIdWORD}; +const CStringDictionary::TStringId WORD2WORD::scm_aunDODataTypeIds[] = {g_nStringIdWORD}; + +const TForteInt16 WORD2WORD::scm_anEIWithIndexes[] = {0}; +const TDataIOID WORD2WORD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId WORD2WORD::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID WORD2WORD::scm_anEOWith[] = {0, 255}; +const TForteInt16 WORD2WORD::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId WORD2WORD::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec WORD2WORD::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void WORD2WORD::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +WORD2WORD::~WORD2WORD(){ +} + + + diff --git a/src/modules/convert/WORD2WORD.h b/src/modules/convert/WORD2WORD.h new file mode 100644 index 000000000..233b4b923 --- /dev/null +++ b/src/modules/convert/WORD2WORD.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _WORD2WORD_H_ +#define _WORD2WORD_H_ + +#include +#include + +class WORD2WORD: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(WORD2WORD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_WORD& IN() { + return *static_cast(getDI(0)); + } + + CIEC_WORD& OUT() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(WORD2WORD){}; + virtual ~WORD2WORD(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/convert/WSTRING2WSTRING.cpp b/src/modules/convert/WSTRING2WSTRING.cpp new file mode 100644 index 000000000..c0d05dbff --- /dev/null +++ b/src/modules/convert/WSTRING2WSTRING.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "WSTRING2WSTRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "WSTRING2WSTRING_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(WSTRING2WSTRING, g_nStringIdWSTRING2WSTRING) + +const CStringDictionary::TStringId WSTRING2WSTRING::scm_anDataInputNames[] = {g_nStringIdIN}; + +const CStringDictionary::TStringId WSTRING2WSTRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId WSTRING2WSTRING::scm_aunDIDataTypeIds[] = {g_nStringIdWSTRING}; +const CStringDictionary::TStringId WSTRING2WSTRING::scm_aunDODataTypeIds[] = {g_nStringIdWSTRING}; + +const TForteInt16 WSTRING2WSTRING::scm_anEIWithIndexes[] = {0}; +const TDataIOID WSTRING2WSTRING::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId WSTRING2WSTRING::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID WSTRING2WSTRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 WSTRING2WSTRING::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId WSTRING2WSTRING::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec WSTRING2WSTRING::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void WSTRING2WSTRING::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + OUT() = IN(); + sendOutputEvent(scm_nEventCNFID); + } +} + +WSTRING2WSTRING::~WSTRING2WSTRING(){ +} + + + diff --git a/src/modules/convert/WSTRING2WSTRING.h b/src/modules/convert/WSTRING2WSTRING.h new file mode 100644 index 000000000..e955ab341 --- /dev/null +++ b/src/modules/convert/WSTRING2WSTRING.h @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _WSTRING2WSTRING_H_ +#define _WSTRING2WSTRING_H_ + +#include +#include + +class WSTRING2WSTRING: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(WSTRING2WSTRING) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_WSTRING& IN() { + return *static_cast(getDI(0)); + } + + CIEC_WSTRING& OUT() { + return *static_cast(getDO(0)); + } + + +public: + FUNCTION_BLOCK_CTOR(WSTRING2WSTRING){}; + virtual ~WSTRING2WSTRING(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/eclipseSCADA_SFP/CMakeLists.txt b/src/modules/eclipseSCADA_SFP/CMakeLists.txt new file mode 100644 index 000000000..1125738c0 --- /dev/null +++ b/src/modules/eclipseSCADA_SFP/CMakeLists.txt @@ -0,0 +1,44 @@ +#******************************************************************************* +# * Copyright (c) 2014 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +############################################################################# +# Interface to the EclipseSCADA SFP +############################################################################# + +forte_add_network_layer(EclipseSCADA_SFP OFF "sfp" CES_SFP_Layer essfplayer "Layer for providing and receiving data to EclipseSCADA") + +SET(FORTE_ECLIPSE_SCADA_SFP_SERVER_LIB_DIR "" CACHE PATH "Path to EclipseSCADA SFP Server library directory (leave empty for installed source code)") + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +if(FORTE_COM_EclipseSCADA_SFP) + forte_add_sourcefile_hcpp(essfphandler) + + + if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + if(EXISTS ${FORTE_ECLIPSE_SCADA_SFP_SERVER_LIB_DIR}) + forte_add_include_directories( ${FORTE_ECLIPSE_SCADA_SFP_SERVER_LIB_DIR}/include ) + forte_add_link_directories( ${FORTE_ECLIPSE_SCADA_SFP_SERVER_LIB_DIR}/posix/src/.lib ) + else(EXISTS ${FORTE_ECLIPSE_SCADA_SFP_SERVER_LIB_DIR}) + forte_add_include_directories( /usr/local/include/libeclipsescada-sfp-server-0.1 ) + forte_add_include_directories( /usr/include/libeclipsescada-sfp-server-0.1 ) + forte_add_include_directories( /usr/lib/libeclipsescada-sfp-server-0.1/include ) + endif(EXISTS ${FORTE_ECLIPSE_SCADA_SFP_SERVER_LIB_DIR}) + + forte_add_link_library( -leclipsescada-sfp-server-0.1) + forte_add_link_library( -levent) + + #elseif(FORTE_ARCHITECTURE_WIN32) + #TODO implement this for the other architectures accordingly see modlayer for an example + + endif("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + +endif(FORTE_COM_EclipseSCADA_SFP) \ No newline at end of file diff --git a/src/modules/eclipseSCADA_SFP/essfphandler.cpp b/src/modules/eclipseSCADA_SFP/essfphandler.cpp new file mode 100644 index 000000000..78b5cbf6a --- /dev/null +++ b/src/modules/eclipseSCADA_SFP/essfphandler.cpp @@ -0,0 +1,208 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "essfphandler.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace forte::com_infra; + + +DEFINE_SINGLETON(CEclipseSCADASFPHandler) + + +const uint16_t CEclipseSCADASFPHandler::scm_unServerPort; + +CEclipseSCADASFPHandler::CEclipseSCADASFPHandler(){ + mItemRegistry = sfp_registry_new(); + mEclipseSCADAServer = sfp_server_new(mItemRegistry); +} + +CEclipseSCADASFPHandler::~CEclipseSCADASFPHandler(){ + disableHandler(); + sfp_server_free(mEclipseSCADAServer); + sfp_registry_free(mItemRegistry); +} + +struct sfp_item *CEclipseSCADASFPHandler::registerDataPoint(const char *paDataPointId, const char* paDataPointComment){ + struct sfp_item *retVal; + if(!isAlive()){ + //thread is not running start it + start(); + } + retVal = sfp_registry_register_item(mItemRegistry, paDataPointId, paDataPointComment, 0); //TODO extract unit from pa_acDataPointComment + return retVal; +} + +void CEclipseSCADASFPHandler::unregisterDataPoint(struct sfp_item *patItem){ + sfp_registry_unregister_item(patItem); +} + +void CEclipseSCADASFPHandler::registerWriteCallBack(struct sfp_item *patItem, CComLayer *paLayer){ + sfp_item_set_write_handler(patItem, CEclipseSCADASFPHandler::handleCellWrite, static_cast(paLayer)); +} + +void CEclipseSCADASFPHandler::updateDataPoint(struct sfp_item *patItem, const CIEC_ANY &paDataPoint){ + switch (paDataPoint.getDataTypeID()){ + case CIEC_ANY::e_BOOL: + sfp_item_update_data_bool_now(patItem, ((CIEC_BOOL &) paDataPoint).operator bool()); + break; + case CIEC_ANY::e_SINT: + case CIEC_ANY::e_INT: + case CIEC_ANY::e_DINT: + case CIEC_ANY::e_USINT: + case CIEC_ANY::e_UINT: + case CIEC_ANY::e_BYTE: + case CIEC_ANY::e_WORD: + //Everything smaller or equal 32Bit will be handled here + sfp_item_update_data_int32_now(patItem, ((CIEC_DINT &) paDataPoint).operator TForteInt32()); + break; + case CIEC_ANY::e_LINT: + case CIEC_ANY::e_UDINT: + case CIEC_ANY::e_ULINT: + case CIEC_ANY::e_DWORD: + case CIEC_ANY::e_LWORD: + //Everything needing more than 32Bit signed integer will be handled here + sfp_item_update_data_int64_now(patItem, ((CIEC_LINT &) paDataPoint).operator TForteInt64()); + case CIEC_ANY::e_REAL: + sfp_item_update_data_double_now(patItem, (double)((CIEC_REAL &) paDataPoint).operator TForteFloat()); + break; + case CIEC_ANY::e_LREAL: + sfp_item_update_data_double_now(patItem, (double)((CIEC_LREAL &) paDataPoint).operator TForteDFloat()); + break; + case CIEC_ANY::e_STRING: + case CIEC_ANY::e_WSTRING: + //TODO think about string support in the new interface + //sfp_variant_set_string(&pa_rstDataPointItem.m_stValueBuf, ((CIEC_ANY_STRING &) paDataPoint).getValue()); + break; + //TODO think on how to handle these e_DATE, e_TIME_OF_DAY, e_DATE_AND_TIME, e_TIME + default: + break; + } +} + +bool CEclipseSCADASFPHandler::readBackDataPoint(const struct sfp_variant *paValue, CIEC_ANY &paDataPoint){ + bool retVal = true; + switch (paDataPoint.getDataTypeID()){ + case CIEC_ANY::e_BOOL: + if(VT_BOOLEAN == paValue->type){ + ((CIEC_BOOL &) paDataPoint) = (paValue->payload.val_boolean != 0 ); + }else{ + retVal = false; + } + break; + case CIEC_ANY::e_SINT: + case CIEC_ANY::e_INT: + case CIEC_ANY::e_DINT: + case CIEC_ANY::e_USINT: + case CIEC_ANY::e_UINT: + case CIEC_ANY::e_BYTE: + case CIEC_ANY::e_WORD: + //Everything smaller or equal 32Bit will be handled here + if(VT_INT32 == paValue->type){ + ((CIEC_DINT &) paDataPoint) = paValue->payload.val_int; + }else{ + retVal = false; + } + break; + case CIEC_ANY::e_LINT: + case CIEC_ANY::e_UDINT: + case CIEC_ANY::e_ULINT: + case CIEC_ANY::e_DWORD: + case CIEC_ANY::e_LWORD: + //Everything needing more than 32Bit signed integer will be handled here + if(VT_INT64 == paValue->type){ + ((CIEC_LINT &) paDataPoint) = paValue->payload.val_long; + }else{ + retVal = false; + } + case CIEC_ANY::e_REAL: + if(VT_DOUBLE == paValue->type){ + ((CIEC_REAL &) paDataPoint) = static_cast(paValue->payload.val_double); + }else{ + retVal = false; + } + break; + case CIEC_ANY::e_LREAL: + if(VT_DOUBLE == paValue->type){ + ((CIEC_LREAL &) paDataPoint) = paValue->payload.val_double; + }else{ + retVal = false; + } + break; + case CIEC_ANY::e_STRING: + case CIEC_ANY::e_WSTRING: + if(VT_BOOLEAN == paValue->type){ + ((CIEC_ANY_STRING &) paDataPoint) = paValue->payload.val_string; + }else{ + retVal = false; + } + break; + default: + //TODO think on how to handle these e_DATE, e_TIME_OF_DAY, e_DATE_AND_TIME, e_TIME + retVal = false; + break; + } + return retVal; +} + +void CEclipseSCADASFPHandler::enableHandler(void){ + start(); +} + +void CEclipseSCADASFPHandler::disableHandler(void){ + sfp_server_exit_loop(mEclipseSCADAServer); + end(); +} + +void CEclipseSCADASFPHandler::setPriority(int){ + //currently we are doing nothing here. + //TODO We should adjust the thread priority. +} + +int CEclipseSCADASFPHandler::getPriority(void) const{ + //the same as for setPriority + return 0; +} + +void CEclipseSCADASFPHandler::run(){ + sfp_server_run(mEclipseSCADAServer, scm_unServerPort); +} + +void CEclipseSCADASFPHandler::handleCellWrite(struct sfp_item * pa_pstItem, struct sfp_variant *pa_pstValue, int32_t pa_nOperationID, + struct sfp_strategy * pa_pstStrategy, + void (*handle_result)(struct sfp_strategy* strategy, int32_t operation_id, struct sfp_error_information* error), + void * pa_pvCtx){ + CComLayer *layer = static_cast(pa_pvCtx); + + EComResponse retVal = layer->recvData(static_cast(pa_pstValue), 0); + + if(e_ProcessDataOk == retVal){ + //only update data in item if data could be read + sfp_item_update_data(pa_pstItem, pa_pstValue, sfp_time_in_millis()); + } + + if(e_Nothing != retVal){ + getInstance().startNewEventChain(layer->getCommFB()); + } + +// sfp_error_information_new( +// + handle_result(pa_pstStrategy, pa_nOperationID, NULL ); +} + diff --git a/src/modules/eclipseSCADA_SFP/essfphandler.h b/src/modules/eclipseSCADA_SFP/essfphandler.h new file mode 100644 index 000000000..b2af0cb77 --- /dev/null +++ b/src/modules/eclipseSCADA_SFP/essfphandler.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef OPENSCADASERVERHANDLER_H_ +#define OPENSCADASERVERHANDLER_H_ + +#include +#include +#include +#include + +#include + + + +struct TOpenSCADAItem{ + struct sfp_item *m_pstItem; + struct sfp_variant m_stValueBuf; //FIXME check if the sfp_item's variant could directly be used +}; + + +class CEclipseSCADASFPHandler : public CExternalEventHandler, public CThread{ + DECLARE_SINGLETON(CEclipseSCADASFPHandler) + ; + + public: + + struct sfp_item *registerDataPoint(const char *paDataPointId, const char* paDataPointComment); + void unregisterDataPoint(struct sfp_item *patItem); + + void registerWriteCallBack(struct sfp_item *patItem, forte::com_infra::CComLayer *paLayer); + + static void updateDataPoint(struct sfp_item *patItem, const CIEC_ANY &paDataPoint); + static bool readBackDataPoint(const struct sfp_variant *paValue, CIEC_ANY &paDataPoint); + + /* functions needed for the external event handler interface */ + void enableHandler(void); + void disableHandler(void); + void setPriority(int pa_nPriority); + int getPriority(void) const; + + protected: + + private: + static void handleCellWrite(struct sfp_item * pa_pstItem, struct sfp_variant *pa_pstValue, int32_t pa_nOperationID, + struct sfp_strategy * pa_pstStrategy, + void (*handle_result)(struct sfp_strategy* strategy, int32_t operation_id, struct sfp_error_information* error), + void * pa_pvCtx); + + static const uint16_t scm_unServerPort = 9999; + + virtual void run(); + + struct sfp_registry *mItemRegistry; + struct sfp_server *mEclipseSCADAServer; + +}; + +#endif /* OPENSCADASERVERHANDLER_H_ */ diff --git a/src/modules/eclipseSCADA_SFP/essfplayer.cpp b/src/modules/eclipseSCADA_SFP/essfplayer.cpp new file mode 100644 index 000000000..a32686718 --- /dev/null +++ b/src/modules/eclipseSCADA_SFP/essfplayer.cpp @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "essfplayer.h" +#include "essfphandler.h" +#include + +using namespace forte::com_infra; + +const char CES_SFP_Layer::scmParameterSeperator; + +CES_SFP_Layer::CES_SFP_Layer(CComLayer* paUpperLayer, CCommFB* paComFB) : + CComLayer(paUpperLayer, paComFB), mSFPItem(0){ +} + +CES_SFP_Layer::~CES_SFP_Layer(){ + closeConnection(); +} + + +void CES_SFP_Layer::closeConnection(){ + if(0 != mSFPItem){ + int numData = (e_Subscriber == getCommFB()->getComServiceType()) ? + getCommFB()->getNumRD() : getCommFB()->getNumSD(); + + if(0 == numData){ + numData = 1; //remove the item used for the event transmition + } + + for(int i = 0; i < numData; i++){ + if(0 != mSFPItem[i]){ + CEclipseSCADASFPHandler::getInstance().unregisterDataPoint(mSFPItem[i]); + } + } + + delete[] mSFPItem; + mSFPItem = 0; + } +} + +EComResponse CES_SFP_Layer::sendData(void *paData, unsigned int paSize){ + EComResponse retVal = e_ProcessDataOk; + + if(0 == paSize){ + //TODO change to an update now with out the need for a new allocation + sfp_item_update_data_allocated(*mSFPItem, sfp_variant_new_null(), sfp_time_in_millis ()); + }else { + CIEC_ANY const *SDs(static_cast(paData)); + for(unsigned int i = 0; i < paSize; i++){ + CEclipseSCADASFPHandler::updateDataPoint(mSFPItem[i], SDs[i]); //TODO use common timestamp for all + } + } + return retVal; +} + +EComResponse CES_SFP_Layer::recvData(const void *paData, unsigned int ){ + mInterruptResp = e_ProcessDataOk; + const struct sfp_variant *value = static_cast(paData); + + if(0 == getCommFB()->getNumRD()){ + //we are a subscribe 0 + if(VT_NULL != value->type){ + mInterruptResp = e_ProcessDataRecvFaild; + } + }else{ + CIEC_ANY &RD1(*getCommFB()->getRDs()); + if(!CEclipseSCADASFPHandler::readBackDataPoint(value, RD1)){ + mInterruptResp = e_ProcessDataRecvFaild; + } + } + + getCommFB()->interruptCommFB(this); + return mInterruptResp; +} + +EComResponse CES_SFP_Layer::processInterrupt(){ + //we don't need to do anything here + return mInterruptResp; +} + +EComResponse CES_SFP_Layer::openConnection(char *paLayerParameter){ + int numData; + CIEC_ANY *dataArray; + + if(e_Subscriber == getCommFB()->getComServiceType()){ + numData = getCommFB()->getNumRD(); + dataArray = getCommFB()->getRDs(); + }else{ + numData = getCommFB()->getNumSD(); + dataArray = getCommFB()->getSDs(); + } + + EComResponse retVal = createItems(dataArray, numData, paLayerParameter); + + if(e_InitOk == retVal){ + if(e_Subscriber == getCommFB()->getComServiceType()){ + if(0 == numData){ + numData = 1; //register for the item used for the event transmition + } + + for(int i = 0; i < numData; i++){ + CEclipseSCADASFPHandler::getInstance().registerWriteCallBack(mSFPItem[i], this); + } + } + } + return retVal; +} + +EComResponse CES_SFP_Layer::createItems(CIEC_ANY *paDataArray, int paNumData, char *paLayerParameter){ + EComResponse retVal = e_InitOk; + + if(0 == paNumData){ + //handle pure event messages + mSFPItem = new sfp_item *[1]; + *mSFPItem = CEclipseSCADASFPHandler::getInstance().registerDataPoint(paLayerParameter, "Coment"); + if(0 != *mSFPItem){ + sfp_item_update_data_allocated(*mSFPItem, sfp_variant_new_null(), sfp_time_in_millis ()); + }else{ + retVal = e_InitInvalidId; + } + }else{ + mSFPItem = new sfp_item *[paNumData]; + memset(mSFPItem, 0, sizeof(sfp_item *) * paNumData); + char *nextParam; + + for(int i = 0; i < paNumData; i++){ + if(0 != paLayerParameter){ + nextParam = strchr(paLayerParameter, scmParameterSeperator); + if(0 != nextParam){ + *nextParam = '\0'; + nextParam++; + } + mSFPItem[i] = CEclipseSCADASFPHandler::getInstance().registerDataPoint(paLayerParameter, "Coment"); + + if(0 != mSFPItem[i]){ + //write the initial value to the SFP server so that the data type of the item gets set + CEclipseSCADASFPHandler::updateDataPoint(mSFPItem[i], paDataArray[i]); + }else { + retVal = e_InitInvalidId; + break; + } + }else{ + retVal = e_InitInvalidId; + break; + } + paLayerParameter = nextParam; + } + } + + return retVal; +} + diff --git a/src/modules/eclipseSCADA_SFP/essfplayer.h b/src/modules/eclipseSCADA_SFP/essfplayer.h new file mode 100644 index 000000000..5b538fff9 --- /dev/null +++ b/src/modules/eclipseSCADA_SFP/essfplayer.h @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef ESSFPLAYER_H_ +#define ESSFPLAYER_H_ + +#include +#include + +class CES_SFP_Layer : public forte::com_infra::CComLayer{ + public: + CES_SFP_Layer(forte::com_infra::CComLayer* paUpperLayer, forte::com_infra::CCommFB* paComFB); + virtual ~CES_SFP_Layer(); + + virtual void closeConnection(); + virtual forte::com_infra::EComResponse sendData(void *paData, unsigned int paSize); + virtual forte::com_infra::EComResponse recvData(const void *paData, unsigned int paSize); + virtual forte::com_infra::EComResponse processInterrupt(); + + private: + virtual forte::com_infra::EComResponse openConnection(char *paLayerParameter); + + forte::com_infra::EComResponse createItems(CIEC_ANY *paDataArray, int paNumData, char *paLayerParameter); + + + struct sfp_item **mSFPItem; //!< pointer to the list of items managed by the EclipseSCADA SFP stack + forte::com_infra::EComResponse mInterruptResp; + + static const char scmParameterSeperator = ';'; +}; + +#endif /* ESSFPLAYER_H_ */ diff --git a/src/modules/i2c_dev/CMakeLists.txt b/src/modules/i2c_dev/CMakeLists.txt new file mode 100644 index 000000000..b81ca87de --- /dev/null +++ b/src/modules/i2c_dev/CMakeLists.txt @@ -0,0 +1,28 @@ +#******************************************************************************* +# * Copyright (c) 2015 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Gerd Kainz, Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +forte_add_module(I2C-Dev "Interacting with GPIOs of Linux-based devices via I2C using i2c-dev") + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +####################################################### +# i2c-dev +####################################################### + + +forte_add_sourcefile_hcpp(../../stdfblib/io/IX) +forte_add_sourcefile_hcpp( ../../stdfblib/io/QX) +forte_add_sourcefile_hcpp(../../stdfblib/io/IW) +forte_add_sourcefile_hcpp( ../../stdfblib/io/QW) + + +forte_add_sourcefile_hcpp(processinterface) + diff --git a/src/modules/i2c_dev/processinterface.cpp b/src/modules/i2c_dev/processinterface.cpp new file mode 100644 index 000000000..b509ce459 --- /dev/null +++ b/src/modules/i2c_dev/processinterface.cpp @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "processinterface.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char * const CProcessInterface::scmInitDeinitOK = "OK"; +const char * const CProcessInterface::scmNotInitialised = "Not initialised"; + +CProcessInterface::CProcessInterface(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData) : + CProcessInterfaceBase(paSrcRes, paInterfaceSpec, paInstanceNameId, paFBConnData, paFBVarsData), mFd(-1), mDeviceAddress(-1), mValueAddress(-1){ +} + +CProcessInterface::~CProcessInterface(){ +} + +bool CProcessInterface::initialise(bool paInput){ + char path[scmBuffer]; + unsigned long funcs; + char * element; + int i2CAdapter; + + + strcpy(path, PARAMS().getValue()); + element = strtok(path, "."); + if(NULL == element){ + STATUS() = scmNotInitialised; + return false; + } + else{ + CIEC_INT param; + param.fromString(element); + i2CAdapter = param; + } + element = strtok(NULL, "."); + if(NULL == element){ + STATUS() = scmNotInitialised; + return false; + } + else{ + CIEC_INT param; + param.fromString(element); + mDeviceAddress = param; + } + element = strtok(NULL, "."); + if(NULL == element){ + STATUS() = scmNotInitialised; + return false; + } + else{ + CIEC_INT param; + param.fromString(element); + mValueAddress = param; + } + + snprintf(path, scmBuffer, "/dev/i2c-%d", i2CAdapter); + mFd = open(path, O_RDWR); + if(mFd < 0){ + STATUS() = scmNotInitialised; + return false; + } + + if(ioctl(mFd, I2C_FUNCS, &funcs) < 0){ + STATUS() = scmNotInitialised; + return false; + } + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = scmNotInitialised; + return false; + } + + STATUS() = scmInitDeinitOK; + return true; +} + +bool CProcessInterface::deinitialise(){ + close(mFd); + + STATUS() = scmInitDeinitOK; + return true; +} + +bool CProcessInterface::readPin(){ + int res; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = "Kann net lesen"; + return false; + } + + res = i2c_smbus_read_byte(mFd); + if(res < 0){ + STATUS() = "Kann net lesen"; + return false; + } + + IN_X() = (res & (1 << mValueAddress)) ? true : false; + STATUS() = "Konnte lesen"; + return true; +} + +bool CProcessInterface::writePin(){ + int res; + uint8_t byteValue; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + + byteValue = i2c_smbus_read_byte(mFd); + if(OUT_X()){ + byteValue = byteValue | (uint8_t) (1 << mValueAddress); + } + else{ + byteValue = byteValue & (uint8_t) (~(1 << mValueAddress)); + } + res = i2c_smbus_write_byte(mFd, byteValue); + if(res < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + STATUS() = "Konnte lesen"; + return true; +} + +bool CProcessInterface::readWord(){ + int res; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = "Kann net lesen"; + return false; + } + + res = i2c_smbus_read_word_data(mFd, (uint8_t) mValueAddress); + if(res < 0){ + STATUS() = "Kann net lesen"; + return false; + } + IN_W() = res; + STATUS() = "Konnte lesen"; + return true; +} + +bool CProcessInterface::writeWord(){ + int res; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + + res = i2c_smbus_write_word_data(mFd, mValueAddress, (uint16_t) OUT_W()); + if(res < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + STATUS() = "Konnte schreiben"; + return true; +} diff --git a/src/modules/i2c_dev/processinterface.h b/src/modules/i2c_dev/processinterface.h new file mode 100644 index 000000000..b69af3c57 --- /dev/null +++ b/src/modules/i2c_dev/processinterface.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _PROCESSINTERFACE_H_ +#define _PROCESSINTERFACE_H_ + +#include <../../stdfblib/io/processinterfacebase.h> +#include +#include +#include + +class CProcessInterface : public CProcessInterfaceBase{ + +public: + CProcessInterface(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, + const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData); + virtual ~CProcessInterface(); + +protected: + bool initialise(bool paInput); + bool deinitialise(); + bool writePin(); + bool readPin(); + bool writeWord(); + bool readWord(); + +private: + const static int scmBuffer = 100; + + int mFd; + int mDeviceAddress; + int mValueAddress; + + static const char * const scmInitDeinitOK; + static const char * const scmNotInitialised; +}; + +#endif /* _PROCESSINTERFACE_H_ */ diff --git a/src/modules/lms_ev3/CMakeLists.txt b/src/modules/lms_ev3/CMakeLists.txt new file mode 100644 index 000000000..528a61ea3 --- /dev/null +++ b/src/modules/lms_ev3/CMakeLists.txt @@ -0,0 +1,24 @@ +#******************************************************************************* +# * Copyright (c) 2015 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +forte_add_module(LMS_EV3 "I/O support for Lego Mindstorms EV3 using the ev3_dev operating system") + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +####################################################### +# LMS_EV3 +####################################################### + + +forte_add_sourcefile_hcpp(../../stdfblib/io/IX) +forte_add_sourcefile_hcpp( ../../stdfblib/io/QX) +forte_add_sourcefile_hcpp(processinterface) + diff --git a/src/modules/lms_ev3/processinterface.cpp b/src/modules/lms_ev3/processinterface.cpp new file mode 100644 index 000000000..b96d24d5a --- /dev/null +++ b/src/modules/lms_ev3/processinterface.cpp @@ -0,0 +1,130 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "processinterface.h" +#include + +const std::string CLMSEV3ProcessInterface::scmLEDId("led"); +const std::string CLMSEV3ProcessInterface::scmSensorID("Sensor"); + +CLMSEV3ProcessInterface::CLMSEV3ProcessInterface(CResource *paSrcRes, + const SFBInterfaceSpec *paInterfaceSpec, + const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, + TForteByte *paFBVarsData) : + CProcessInterfaceBase(paSrcRes, paInterfaceSpec, paInstanceNameId, paFBConnData, paFBVarsData){ + mFile.rdbuf()->pubsetbuf(NULL, 0); //disable buffer to avoid latency +} + +CLMSEV3ProcessInterface::~CLMSEV3ProcessInterface(){ +} + +bool CLMSEV3ProcessInterface::initialise(bool paInput){ + bool retVal = false; + std::vector paramsList(generateParameterList()); + + //TODO check length of vector + if(paInput){ + if(scmSensorID == paramsList.front().substr(0,scmSensorID.length())){ + retVal = setupSensor(paramsList.front()); + } + }else{ + if(scmLEDId == paramsList.front()){ + retVal = setupLEDOutput(paramsList); + } + } + + return retVal; +} + +bool CLMSEV3ProcessInterface::deinitialise(){ + if(mFile.is_open()){ + mFile.close(); + } + return true; +} + +bool CLMSEV3ProcessInterface::readPin(){ + bool retVal = false; + if(mFile.is_open()){ + char binData = 0; + mFile.clear(); + mFile.seekg(0, std::ios::beg); + mFile.read(&binData, 1); + //TODO check if reading worked + IN_X() = ('0' != binData) ? true : false; + retVal = true; + } + return retVal; +} + +bool CLMSEV3ProcessInterface::writePin(){ + bool retVal = false; + if(mFile.is_open()){ + int val = (false != OUT_X()) ? 255 : 0; //if true set the led to full glowing + mFile << val; + //TODO check if writing worked + retVal = true; + } + return retVal; +} + +std::vector CLMSEV3ProcessInterface::generateParameterList(){ + std::stringstream streamBuf(std::string(PARAMS().getValue())); + std::string segment; + std::vector retVal; + + while(std::getline(streamBuf, segment, '.')){ //seperate the PARAMS input by '.' for easier processing + retVal.push_back(segment); + } + return retVal; +} + +bool CLMSEV3ProcessInterface::setupLEDOutput(const std::vector &paParamList){ + bool retVal = false; + + std::string sysFileName("/sys/class/leds/ev3-" + paParamList[2]); + + sysFileName += ("red" == paParamList[1]) ? "0:" : "1:"; + sysFileName += paParamList[1]; + sysFileName += ":ev3dev/brightness"; + + mFile.open(sysFileName.c_str(), std::fstream::out); //TODO change this when fully switching to C++11 for LMS EV3 + + if(mFile.is_open()){ + retVal = writePin(); // initialize output with default value (i.e, should be false) + } + + return retVal; +} + +bool CLMSEV3ProcessInterface::setupSensor(const std::string &paParam){ + bool retVal = false; + + std::string sysFileName(getSensorBasePath(*(paParam.rbegin()))); + if(sysFileName.size()){ + sysFileName += "/value0"; //for now use the value file for getting the value. espeically for touch this seams to be the better option. Needs check for other sensors!! + mFile.open(sysFileName.c_str(), std::fstream::in); //TODO change this when fully switching to C++11 for LMS EV3 + if(mFile.is_open()){ + retVal = true; + } + } + return retVal; +} + +std::string CLMSEV3ProcessInterface::getSensorBasePath(char paSensorPortNum){ + std::string retVal; + if(('0' <= paSensorPortNum) && (paSensorPortNum < '5')){ + //todo search for the correct sensor port using the port_name file + retVal = "/sys/class/lego-sensor/sensor"; + retVal += paSensorPortNum; + } + return retVal; +} diff --git a/src/modules/lms_ev3/processinterface.h b/src/modules/lms_ev3/processinterface.h new file mode 100644 index 000000000..128e584e1 --- /dev/null +++ b/src/modules/lms_ev3/processinterface.h @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _PROCESSINTERFACE_H_ +#define _PROCESSINTERFACE_H_ + +#include <../../stdfblib/io/processinterfacebase.h> +#include +#include +#include + +class CLMSEV3ProcessInterface : public CProcessInterfaceBase{ + +public: + CLMSEV3ProcessInterface(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, + const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData); + virtual ~CLMSEV3ProcessInterface(); + +protected: + bool initialise(bool paInput); + bool deinitialise(); + bool writePin(); + bool readPin(); + +private: + + static const std::string scmLEDId; + static const std::string scmSensorID; + + static std::string getSensorBasePath(char paSensorPortNum); + + std::vector generateParameterList(); + + bool setupLEDOutput(const std::vector &paParamList); + bool setupSensor(const std::string &paParam); + + std::fstream mFile; //!< the file to be used for this process interface instance + +}; + +//tell the IX and QX FB that this is the process interface to be used +typedef CLMSEV3ProcessInterface CProcessInterface; + +#endif /* PROCESSINTERFACE_H_ */ diff --git a/src/modules/modbus/CMakeLists.txt b/src/modules/modbus/CMakeLists.txt new file mode 100644 index 000000000..d8cba4c88 --- /dev/null +++ b/src/modules/modbus/CMakeLists.txt @@ -0,0 +1,38 @@ +#******************************************************************************* +# * Copyright (c) 2012 -2014 AIT, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Modbus Com Layer +############################################################################# +forte_add_network_layer(MODBUS OFF "modbus" CModbusComLayer modbuslayer "Enable Modbus Com Layer") +SET(FORTE_COM_MODBUS_LIB_DIR "" CACHE PATH "Path to Modbus library directory (leave empty for installed source code)") + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +if(FORTE_COM_MODBUS) + forte_add_sourcefile_hcpp( modbushandler + modbusconnection + modbusclientconnection + modbuspoll + modbustimedevent ) + if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + if(EXISTS ${FORTE_COM_MODBUS_LIB_DIR}) + forte_add_include_directories( ${FORTE_COM_MODBUS_LIB_DIR}/include/modbus ) + forte_add_link_directories( ${FORTE_COM_MODBUS_LIB_DIR}/lib ) + else(EXISTS ${FORTE_COM_MODBUS_LIB_DIR}) + forte_add_include_directories( /usr/include/modbus ) + endif(EXISTS ${FORTE_COM_MODBUS_LIB_DIR}) + forte_add_link_library( libmodbus.so ) + elseif("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + forte_add_include_directories( ${FORTE_COM_MODBUS_LIB_DIR}/include ) + forte_add_link_directories( ${FORTE_COM_MODBUS_LIB_DIR}/lib ) + forte_add_link_library( libmodbus.lib ) + endif() +endif(FORTE_COM_MODBUS) diff --git a/src/modules/modbus/modbusclientconnection.cpp b/src/modules/modbus/modbusclientconnection.cpp new file mode 100644 index 000000000..4e12e144c --- /dev/null +++ b/src/modules/modbus/modbusclientconnection.cpp @@ -0,0 +1,221 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "modbusclientconnection.h" +#include "devlog.h" +#include "modbuspoll.h" + +#ifndef WIN32 +#include +#endif + +using namespace modbus_connection_event; + +/************************************* + * CModbusClientConnection class + *************************************/ + +CModbusClientConnection::CModbusClientConnection() : + CModbusConnection(), m_pModbusConnEvent(NULL), m_nNrOfPolls(0), m_nSlaveId(0xFF), m_unBufFillSize(0){ +} + +CModbusClientConnection::~CModbusClientConnection(){ + if (m_bConnected){ + disconnect(); + } + TModbusPollList::Iterator itEnd(m_lstPollList.end()); + for(TModbusPollList::Iterator itRunner = m_lstPollList.begin(); itRunner != itEnd; ++itRunner){ + delete *itRunner; + } + if (m_pModbusConnEvent != NULL){ + delete m_pModbusConnEvent; + } +} + +int CModbusClientConnection::readData(uint8_t *pa_pData){ + for(unsigned int i = 0; i < m_unBufFillSize; i++){ + pa_pData[i] = m_acRecvBuffer[i]; + } + + return (int) m_unBufFillSize; +} + +int CModbusClientConnection::writeData(uint16_t *pa_pData, unsigned int pa_nDataSize){ + unsigned int dataIndex = 0; + + TModbusSendList::Iterator itEnd = m_lstSendList.end(); + for (TModbusSendList::Iterator it = m_lstSendList.begin(); it!=itEnd; ++it) { + if (dataIndex + it->m_nNrAddresses > pa_nDataSize) { + break; + } + modbus_write_registers(m_pModbusConn, it->m_nStartAddress, it->m_nNrAddresses, &pa_pData[dataIndex]); + dataIndex += it->m_nNrAddresses; + } + + return (int)dataIndex; +} + +int CModbusClientConnection::connect(){ + CModbusConnection::connect(); + + if(m_nSlaveId != 0xFF){ + modbus_set_slave(m_pModbusConn, m_nSlaveId); + } + + m_pModbusConnEvent = new CModbusConnectionEvent(1000); + m_pModbusConnEvent->activate(); + + this->start(); + + return 0; +} + +void CModbusClientConnection::disconnect(){ + this->end(); + if (m_bConnected){ + modbus_close(m_pModbusConn); + m_bConnected = false; + } + CModbusConnection::disconnect(); +} + +void CModbusClientConnection::addNewPoll(TForteUInt32 pa_nPollInterval, unsigned int pa_nFunctionCode, unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses){ + CModbusPoll *newPoll = NULL; + + TModbusPollList::Iterator itEnd = m_lstPollList.end(); + for(TModbusPollList::Iterator it = m_lstPollList.begin(); it != itEnd; ++it){ + if(it->getUpdateInterval() == pa_nPollInterval && it->getFunctionCode() == pa_nFunctionCode){ + it->addPollAddresses(pa_nStartAddress, pa_nNrAddresses); + newPoll = *it; + break; + } + } + if(newPoll == NULL){ + m_lstPollList.push_back(new CModbusPoll(pa_nPollInterval, pa_nFunctionCode, pa_nStartAddress, pa_nNrAddresses)); + m_nNrOfPolls++; + m_anRecvBuffPosition[m_nNrOfPolls - 1] = m_unBufFillSize; + } + + // Count bytes + unsigned int nrBytes = 0; + switch (pa_nFunctionCode){ + case 1: + case 2: + nrBytes = pa_nNrAddresses; + break; + case 3: + case 4: + nrBytes = pa_nNrAddresses * 2; + break; + } + for(unsigned int i = m_unBufFillSize; i < m_unBufFillSize + nrBytes; i++){ + m_acRecvBuffer[i] = 0; + } + m_unBufFillSize += nrBytes; +} + +void CModbusClientConnection::addNewSend(unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses) { + SSendInformation sendInfo = {pa_nStartAddress, pa_nNrAddresses}; + + m_lstSendList.push_back(sendInfo); +} + +void CModbusClientConnection::setSlaveId(unsigned int pa_nSlaveId){ + m_nSlaveId = pa_nSlaveId; +} + +void CModbusClientConnection::run(){ + + while(isAlive()){ + if(m_bConnected){ + tryPolling(); + } + else{ + tryConnect(); + } + +#ifdef WIN32 + Sleep(1); +#else + usleep(1); +#endif + } +} + +void CModbusClientConnection::tryPolling(){ + unsigned int nrErrors = 0; + bool dataReturned = false; + + unsigned int index = 0; + TModbusPollList::Iterator itEnd(m_lstPollList.end()); + for(TModbusPollList::Iterator itPoll = m_lstPollList.begin(); itPoll != itEnd; ++itPoll, ++index){ + if(itPoll->readyToExecute()){ + int nrVals = itPoll->executeEvent(m_pModbusConn, (void*) &m_acRecvBuffer[m_anRecvBuffPosition[index]]); // retVal); + + if(nrVals < 0){ + DEVLOG_ERROR("Error reading input status :: %s\n", modbus_strerror(errno)); + itPoll->deactivate(); + + nrErrors++; + } + else if(nrVals > 0){ + dataReturned = true; + } + } + } + + if(dataReturned) + CModbusHandler::getInstance().executeComCallback(m_nComCallbackId); + + if(nrErrors == m_nNrOfPolls){ + m_bConnected = false; + m_pModbusConnEvent = new CModbusConnectionEvent(2000); + m_pModbusConnEvent->activate(); + } +} + +void CModbusClientConnection::tryConnect(){ + if(m_pModbusConnEvent != NULL){ + if(m_pModbusConnEvent->readyToExecute()){ + if(m_pModbusConnEvent->executeEvent(m_pModbusConn, NULL) < 0) + DEVLOG_ERROR("Connection to Modbus server failed: %s\n", modbus_strerror(errno)); + else{ + DEVLOG_INFO("Connection to Modbus server succeded\n"); + + delete m_pModbusConnEvent; + m_pModbusConnEvent = NULL; + + m_bConnected = true; + + // Start polling + TModbusPollList::Iterator itEnd(m_lstPollList.end()); + for(TModbusPollList::Iterator itPoll = m_lstPollList.begin(); itPoll != itEnd; ++itPoll){ + itPoll->activate(); + } + } + } + } +} + +/************************************* + * CModbusConnectionEvent class + *************************************/ +CModbusConnectionEvent::CModbusConnectionEvent(long pa_nReconnectInterval) : + CModbusTimedEvent(pa_nReconnectInterval){ +} + +int CModbusConnectionEvent::executeEvent(modbus_t *pa_pModbusConn, void *pa_pRetVal){ + (void)pa_pRetVal; // avoid warning + + restartTimer(); + + return modbus_connect(pa_pModbusConn); +} + diff --git a/src/modules/modbus/modbusclientconnection.h b/src/modules/modbus/modbusclientconnection.h new file mode 100644 index 000000000..487b6be84 --- /dev/null +++ b/src/modules/modbus/modbusclientconnection.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _MODBUSCLIENTCONNECTION_H_ +#define _MODBUSCLIENTCONNECTION_H_ + +#include "modbusconnection.h" +#include "modbustimedevent.h" +#include "fortelist.h" + +class CModbusPoll; + +namespace modbus_connection_event { + class CModbusConnectionEvent : public CModbusTimedEvent{ + public: + CModbusConnectionEvent(long pa_nReconnectInterval); //ReconnectInterval = 0 => only one connection try + ~CModbusConnectionEvent(){ + } + ; + + int executeEvent(modbus_t *pa_pModbusConn, void *pa_pRetVal); + }; +} + +class CModbusClientConnection : public CModbusConnection{ + public: + CModbusClientConnection(); + ~CModbusClientConnection(); + + int readData(uint8_t *pa_pData); + int writeData(uint16_t *pa_pData, unsigned int pa_nDataSize); + int connect(); + void disconnect(); + + void addNewPoll(TForteUInt32 pa_nPollInterval, unsigned int pa_nFunctionCode, unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses); + void addNewSend(unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses); + + void setSlaveId(unsigned int pa_nSlaveId); + + protected: + virtual void run(); + + private: + void tryConnect(); + void tryPolling(); + + struct SSendInformation { + unsigned int m_nStartAddress; + unsigned int m_nNrAddresses; + }; + + modbus_connection_event::CModbusConnectionEvent *m_pModbusConnEvent; + + typedef CSinglyLinkedList TModbusPollList; + TModbusPollList m_lstPollList; + + typedef CSinglyLinkedList TModbusSendList; + TModbusSendList m_lstSendList; + + unsigned int m_nNrOfPolls; + unsigned int m_anRecvBuffPosition[100]; + + unsigned int m_nSlaveId; + + uint8_t m_acRecvBuffer[cg_unIPLayerRecvBufferSize]; + unsigned int m_unBufFillSize; + +}; + +#endif diff --git a/src/modules/modbus/modbusconnection.cpp b/src/modules/modbus/modbusconnection.cpp new file mode 100644 index 000000000..d95e6c388 --- /dev/null +++ b/src/modules/modbus/modbusconnection.cpp @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "modbusconnection.h" + +CModbusConnection::CModbusConnection() : m_pModbusConn(NULL), m_bConnected(false), m_paIPAddress(NULL), m_chDevice(NULL){ +} + +CModbusConnection::~CModbusConnection(){ + modbus_free(m_pModbusConn); +} + +int CModbusConnection::connect(){ + if (m_paIPAddress != NULL) { + m_pModbusConn = modbus_new_tcp(m_paIPAddress, m_nPort); + } else if (m_chDevice != NULL) { + m_pModbusConn = modbus_new_rtu(m_chDevice, m_nBaud, m_cParity, m_nDataBit, m_nStopBit); + } else { + return -1; + } + + if(m_nResponseTimeout > 0){ + timeval responseTimeout; + responseTimeout.tv_sec = m_nResponseTimeout / 1000; + responseTimeout.tv_usec = (m_nResponseTimeout % 1000)*1000; + modbus_set_response_timeout(m_pModbusConn, &responseTimeout); + } + if(m_nByteTimeout > 0){ + timeval byteTimeout; + byteTimeout.tv_sec = m_nByteTimeout / 1000; + byteTimeout.tv_usec = (m_nByteTimeout % 1000)*1000; + modbus_set_byte_timeout(m_pModbusConn, &byteTimeout); + } + + return 0; +} + +void CModbusConnection::disconnect(){ + +} + +void CModbusConnection::setIPAddress(const char* pa_poIPAddress){ + m_paIPAddress = pa_poIPAddress; +} + +void CModbusConnection::setPort(unsigned int pa_nPort){ + m_nPort = pa_nPort; +} + +void CModbusConnection::setDevice(const char* pa_chDevice) { + m_chDevice = pa_chDevice; +} + +void CModbusConnection::setBaud(int pa_nBaud) { + m_nBaud = pa_nBaud; +} + +void CModbusConnection::setParity(char pa_cParity) { + m_cParity = pa_cParity; +} + +void CModbusConnection::setDataBit(int pa_nDataBit) { + m_nDataBit = pa_nDataBit; +} + +void CModbusConnection::setStopBit(int pa_nStopBit) { + m_nStopBit = pa_nStopBit; +} + +void CModbusConnection::setResponseTimeout(unsigned int pa_nResponseTimeout){ + m_nResponseTimeout = pa_nResponseTimeout; +} + +void CModbusConnection::setByteTimeout(unsigned int pa_nByteTimeout){ + m_nByteTimeout = pa_nByteTimeout; +} + +void CModbusConnection::setComCallback(forte::com_infra::CComLayer* pa_poModbusLayer){ + m_nComCallbackId = CModbusHandler::getInstance().addComCallback(pa_poModbusLayer); +} diff --git a/src/modules/modbus/modbusconnection.h b/src/modules/modbus/modbusconnection.h new file mode 100644 index 000000000..daac606a8 --- /dev/null +++ b/src/modules/modbus/modbusconnection.h @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _MODBUSCONNECTION_H_ +#define _MODBUSCONNECTION_H_ + +#include "thread.h" +#include +#include "modbushandler.h" +#include +#ifdef _WIN32 +#define IN +#define OUT +#endif +#include + +class CModbusConnection : public CThread{ + public: + CModbusConnection(); + ~CModbusConnection(); + + virtual int readData(uint8_t *pa_pData) = 0; + virtual int writeData(uint16_t *pa_pData, unsigned int pa_nDataSize) = 0; + virtual void run() = 0; + + /*! \brief Initializes Modbus connection + * + * Any classes derived from this class must call CModbusConnection::connect() in the beginning + * of their connect() function + */ + virtual int connect(); + /*! \brief De-initializes Modbus connection + * + * Any classes derived from this class should call CModbusConnection::connect() at the end + * of their disconnect() function + */ + virtual void disconnect(); + + void setIPAddress(const char* pa_poIPAddress); + void setPort(unsigned int pa_nPort); + + void setDevice(const char* pa_chDevice); + void setBaud(int pa_nBaud); + void setParity(char pa_cParity); + void setDataBit(int pa_nDataBit); + void setStopBit(int pa_nStopBit); + void setResponseTimeout(unsigned int pa_nResponseTimeout); + void setByteTimeout(unsigned int pa_nByteTimeout); + + void setComCallback(forte::com_infra::CComLayer* pa_poModbusLayer); + + protected: + modbus_t* m_pModbusConn; + CModbusHandler* m_pModbusHandler; + + CModbusHandler::TCallbackDescriptor m_nComCallbackId; + + bool m_bConnected; + + private: + const char* m_paIPAddress; + unsigned int m_nPort; + + const char* m_chDevice; + int m_nBaud; + char m_cParity; + int m_nDataBit; + int m_nStopBit; + + unsigned int m_nResponseTimeout; + unsigned int m_nByteTimeout; +}; + +#endif // _MODBUSCONNECTION_H_ diff --git a/src/modules/modbus/modbushandler.cpp b/src/modules/modbus/modbushandler.cpp new file mode 100644 index 000000000..eb634fba2 --- /dev/null +++ b/src/modules/modbus/modbushandler.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "modbushandler.h" +#include "devlog.h" +#include "../core/devexec.h" +#include +#include + +DEFINE_SINGLETON(CModbusHandler); + +CModbusHandler::TCallbackDescriptor CModbusHandler::m_nCallbackDescCount = 0; + +CModbusHandler::CModbusHandler(){ +} + +CModbusHandler::~CModbusHandler(){ + +} + +CModbusHandler::TCallbackDescriptor CModbusHandler::addComCallback(forte::com_infra::CComLayer* pa_pComCallback){ + CCriticalRegion criticalRegion(m_oSync); + m_nCallbackDescCount++; + TComContainer stNewNode = { m_nCallbackDescCount, pa_pComCallback }; + m_lstComCallbacks.push_back(stNewNode); + + return m_nCallbackDescCount; +} + +void CModbusHandler::removeComCallback(CModbusHandler::TCallbackDescriptor pa_nCallbackDesc){ + CCriticalRegion criticalRegion(m_oSync); + + TCallbackList::Iterator itRunner(m_lstComCallbacks.begin()); + + if(itRunner->m_nCallbackDesc == pa_nCallbackDesc){ + m_lstComCallbacks.pop_front(); + } + else{ + TCallbackList::Iterator itLastPos(itRunner); + TCallbackList::Iterator itEnd(m_lstComCallbacks.end()); + ++itRunner; + while(itRunner != itEnd){ + if(itRunner->m_nCallbackDesc == pa_nCallbackDesc){ + m_lstComCallbacks.eraseAfter(itLastPos); + break; + } + itLastPos = itRunner; + ++itRunner; + } + } +} + +void CModbusHandler::executeComCallback(CModbusHandler::TCallbackDescriptor pa_nCallbackDesc){ + m_oSync.lock(); + TCallbackList::Iterator itEnd(m_lstComCallbacks.end()); + TCallbackList::Iterator itCurrent(m_lstComCallbacks.begin()); + for(TCallbackList::Iterator itCallback = m_lstComCallbacks.begin(); itCallback != itEnd; ++itCallback){ + itCurrent = itCallback; + + if(itCurrent->m_nCallbackDesc == pa_nCallbackDesc){ + forte::com_infra::CComLayer *comLayer = itCurrent->m_pCallback; + m_oSync.unlock(); + if(forte::com_infra::e_Nothing != comLayer->recvData(0,0)){ + startNewEventChain(comLayer->getCommFB()); + } + m_oSync.lock(); + break; + } + } + m_oSync.unlock(); +} diff --git a/src/modules/modbus/modbushandler.h b/src/modules/modbus/modbushandler.h new file mode 100644 index 000000000..e7789afb6 --- /dev/null +++ b/src/modules/modbus/modbushandler.h @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2012 -2015 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _MODBUSHANDLER_H_ +#define _MODBUSHANDLER_H_ + +#include +#include "extevhan.h" +#include "singlet.h" +#include +#include +#include + +class CModbusHandler : public CExternalEventHandler{ + DECLARE_SINGLETON(CModbusHandler) + ; + public: + typedef int TCallbackDescriptor; + + void enableHandler(void){ + } + ; + void disableHandler(void){ + } + ; + + void setPriority(int){ + //currently we are doing nothing here. + //TODO We should adjust the thread priority. + } + + int getPriority(void) const{ + //the same as for setPriority + return 0; + } + + TCallbackDescriptor addComCallback(forte::com_infra::CComLayer* pa_pComCallback); + void removeComCallback(TCallbackDescriptor pa_nCallbackDesc); + + void executeComCallback(TCallbackDescriptor pa_nCallbackDesc); + + private: + struct TComContainer{ + TCallbackDescriptor m_nCallbackDesc; + forte::com_infra::CComLayer* m_pCallback; + }; + + typedef CSinglyLinkedList TCallbackList; + TCallbackList m_lstComCallbacks; + + CSyncObject m_oSync; + + static TCallbackDescriptor m_nCallbackDescCount; +}; + +#endif // _MODBUSHANDLER_H_ diff --git a/src/modules/modbus/modbuslayer.cpp b/src/modules/modbus/modbuslayer.cpp new file mode 100644 index 000000000..82fadffdb --- /dev/null +++ b/src/modules/modbus/modbuslayer.cpp @@ -0,0 +1,671 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Patrick Smejkal, Alois Zoitl, Martin Melik-Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "modbuslayer.h" +#include "../../arch/devlog.h" +#include "commfb.h" +#include "../../core/datatypes/forte_dint.h" +#include "modbusclientconnection.h" + +using namespace forte::com_infra; + +CModbusComLayer::CModbusComLayer(CComLayer* pa_poUpperLayer, CCommFB* pa_poComFB) : + CComLayer(pa_poUpperLayer, pa_poComFB){ + m_eConnectionState = e_Disconnected; +} + +CModbusComLayer::~CModbusComLayer(){ +} + +void CModbusComLayer::closeConnection(){ + //TODO + DEVLOG_INFO("CModbusLayer::closeConnection()\n"); + + if(m_pModbusConnection != NULL){ + m_pModbusConnection->disconnect(); + delete m_pModbusConnection; + } +} + +EComResponse CModbusComLayer::sendData(void *pa_pvData, unsigned int pa_unSize){ + EComResponse eRetVal = e_ProcessDataOk; + + if(m_eConnectionState == e_Connected){ + switch (m_poFb->getComServiceType()){ + case e_Server: + // todo + break; + case e_Client: { + TForteUInt16 *convertedData = new TForteUInt16[pa_unSize * 4]; + unsigned int sendLength = convertDataInput(pa_pvData, pa_unSize, convertedData); + if(sendLength > 0){ + m_pModbusConnection->writeData(convertedData, sendLength); + } + delete[] convertedData; + break; + } + case e_Publisher: + // todo + break; + case e_Subscriber: + //do nothing as subscribers do not send data + break; + } + } + return eRetVal; +} + +unsigned int CModbusComLayer::convertDataInput(void *pa_poInData, unsigned int pa_nDataSize, TForteUInt16 *pa_poConvertedData){ + unsigned int outLength = 0; + + CIEC_ANY *apoSDs = (CIEC_ANY*) pa_poInData; + unsigned int nrSDs = pa_nDataSize; + + for(unsigned int i = 0; i < nrSDs; i++){ + CIEC_ANY *anyVal = &apoSDs[i]; + switch (apoSDs[i].getDataTypeID()){ + case CIEC_ANY::e_BOOL: // 8bit data types + { + TForteUInt16 out = (bool) *(CIEC_BOOL*) anyVal; + *(TForteUInt16*) (&pa_poConvertedData[outLength]) = out; + outLength += sizeof(TForteUInt16) / 2; + break; + } + case CIEC_ANY::e_SINT: { + TForteInt16 out = (TForteInt8) *(CIEC_SINT*) anyVal; + *(TForteInt16*) (&pa_poConvertedData[outLength]) = out; + outLength += sizeof(TForteInt16) / 2; + break; + } + case CIEC_ANY::e_USINT: { + TForteUInt16 out = (TForteUInt8) *(CIEC_USINT*) anyVal; + *(TForteUInt16*) (&pa_poConvertedData[outLength]) = out; + outLength += sizeof(TForteUInt16) / 2; + break; + } + case CIEC_ANY::e_BYTE: { + TForteUInt16 out = (TForteByte) *(CIEC_BYTE*) anyVal; + *(TForteUInt16*) (&pa_poConvertedData[outLength]) = out; + outLength += sizeof(TForteUInt16) / 2; + break; + } + case CIEC_ANY::e_INT: // 16bit data types + { + TForteInt16 out = (TForteInt16) *(CIEC_INT*) anyVal; + *(TForteInt16*) (&pa_poConvertedData[outLength]) = out; + outLength += sizeof(TForteInt16) / 2; + break; + } + case CIEC_ANY::e_UINT: { + TForteUInt16 out = (TForteUInt16) *(CIEC_UINT*) anyVal; + *(TForteUInt16*) (&pa_poConvertedData[outLength]) = out; + outLength += sizeof(TForteUInt16) / 2; + break; + } + case CIEC_ANY::e_WORD: { + TForteWord out = (TForteWord) *(CIEC_WORD*) anyVal; + *(TForteWord*) (&pa_poConvertedData[outLength]) = out; + outLength += sizeof(TForteWord) / 2; + break; + } + case CIEC_ANY::e_DINT: // 32bit data types + { + TForteInt32 out = (TForteInt32) *(CIEC_DINT*) anyVal; + *(TForteInt32*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteInt32)); + outLength += sizeof(TForteInt32) / 2; + break; + } + case CIEC_ANY::e_UDINT: { + TForteUInt32 out = (TForteUInt32) *(CIEC_UDINT*) anyVal; + *(TForteUInt32*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteUInt32)); + outLength += sizeof(TForteUInt32) / 2; + break; + } + case CIEC_ANY::e_DWORD: { + TForteDWord out = (TForteDWord) *(CIEC_DWORD*) anyVal; + *(TForteDWord*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteDWord)); + outLength += sizeof(TForteDWord) / 2; + break; + } + case CIEC_ANY::e_REAL: { + TForteFloat out = (TForteFloat) *(CIEC_REAL*) anyVal; + *(TForteFloat*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteFloat)); + outLength += sizeof(TForteFloat) / 2; + break; + } + case CIEC_ANY::e_LINT: // 64bit data types + { + TForteInt64 out = (TForteInt64) *(CIEC_LINT*) anyVal; + *(TForteInt64*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteInt64)); + outLength += sizeof(TForteInt64) / 2; + break; + } + case CIEC_ANY::e_ULINT: { + TForteUInt64 out = (TForteUInt64) *(CIEC_ULINT*) anyVal; + *(TForteUInt64*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteUInt64)); + outLength += sizeof(TForteUInt64) / 2; + break; + } + case CIEC_ANY::e_LWORD: { + TForteLWord out = (TForteLWord) *(CIEC_LWORD*) anyVal; + *(TForteLWord*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteLWord)); + outLength += sizeof(TForteLWord) / 2; + break; + } + case CIEC_ANY::e_LREAL: { + TForteDFloat out = (TForteDFloat) *(CIEC_LREAL*) anyVal; + *(TForteDFloat*) (&pa_poConvertedData[outLength]) = convertFBOutput((TForteByte*) &out, sizeof(TForteDFloat)); + outLength += sizeof(TForteDFloat) / 2; + break; + } + default: + break; + } + } + return outLength; +} + +EComResponse CModbusComLayer::processInterrupt(){ + if(e_ProcessDataOk == m_eInterruptResp){ + switch (m_eConnectionState){ + case e_Connected: { + CIEC_ANY *apoRDs = m_poFb->getRDs(); + unsigned int nrRDs = m_poFb->getNumRD(); + + unsigned int dataIndex = 0; + + for(unsigned int i = 0; i < nrRDs; i++){ + switch (apoRDs[i].getDataTypeID()){ + case CIEC_ANY::e_BOOL: + apoRDs[i].setValue(CIEC_BOOL(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(bool); + break; + case CIEC_ANY::e_SINT: + apoRDs[i].setValue(CIEC_SINT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteInt8); + break; + case CIEC_ANY::e_INT: + apoRDs[i].setValue(CIEC_INT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteInt16); + break; + case CIEC_ANY::e_DINT: + apoRDs[i].setValue(CIEC_DINT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteInt32); + break; + case CIEC_ANY::e_LINT: + apoRDs[i].setValue(CIEC_LINT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteInt64); + break; + case CIEC_ANY::e_USINT: + apoRDs[i].setValue(CIEC_USINT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteUInt8); + break; + case CIEC_ANY::e_UINT: + apoRDs[i].setValue(CIEC_UINT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteUInt16); + break; + case CIEC_ANY::e_UDINT: + apoRDs[i].setValue(CIEC_UDINT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteUInt32); + break; + case CIEC_ANY::e_ULINT: + apoRDs[i].setValue(CIEC_ULINT(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteUInt64); + break; + case CIEC_ANY::e_BYTE: + apoRDs[i].setValue(CIEC_BYTE(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteByte); + break; + case CIEC_ANY::e_WORD: + apoRDs[i].setValue(CIEC_WORD(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteWord); + break; + case CIEC_ANY::e_DWORD: + apoRDs[i].setValue(CIEC_DWORD(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteDWord); + break; + case CIEC_ANY::e_LWORD: + apoRDs[i].setValue(CIEC_LWORD(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteLWord); + break; + case CIEC_ANY::e_REAL: + apoRDs[i].setValue(CIEC_REAL(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteFloat); + break; + case CIEC_ANY::e_LREAL: + apoRDs[i].setValue(CIEC_LREAL(convertFBOutput(&m_acRecvBuffer[dataIndex], m_unBufFillSize - dataIndex))); + dataIndex += sizeof(TForteDFloat); + break; + default: + // TODO + break; + } + } + break; + } + case e_Disconnected: + case e_Listening: + case e_ConnectedAndListening: + default: + break; + } + } + else{ + if(e_InitTerminated == m_eInterruptResp){ + // todo: Move server into listening mode again, etc. + } + } + return m_eInterruptResp; +} + +EComResponse CModbusComLayer::recvData(const void *, unsigned int){ + m_eInterruptResp = e_Nothing; + + switch (m_eConnectionState){ + case e_Listening: + + //TODO accept incoming connection + + break; + case e_Connected: { + int nRetVal = 0; + switch (m_poFb->getComServiceType()){ + case e_Server: + //TODO + break; + case e_Client: + //TODO check if errors occured during polling in ModbusConnection + nRetVal = m_pModbusConnection->readData(&m_acRecvBuffer[0]); + break; + case e_Publisher: + //do nothing as publisher cannot receive data + break; + case e_Subscriber: + //do nothing since Modbus protocol cannot act as subscriber + break; + } + switch (nRetVal){ + case 0: + //TODO + break; + default: + //we successfully received data + m_unBufFillSize = nRetVal; + m_eInterruptResp = e_ProcessDataOk; + break; + } + m_poFb->interruptCommFB(this); + } + break; + case e_ConnectedAndListening: + case e_Disconnected: + default: + break; + } + return m_eInterruptResp; +} + +template +T CModbusComLayer::convertFBOutput(TForteByte *pa_acDataArray, unsigned int pa_nDataSize){ + T retVal; + unsigned int currentDataSize = sizeof(T); + + if(currentDataSize <= pa_nDataSize){ + if(currentDataSize > 2){ + // A data type with size greater than 16 bits is requested => + // we need to swap order of each 16 bit data package + + unsigned int nrUint16s = currentDataSize / 2; + TForteUInt16 *destAr = new TForteUInt16[nrUint16s]; + TForteUInt16 *sourceAr = (TForteUInt16*) pa_acDataArray; + + for(unsigned int i = 0; i < nrUint16s; i++) + destAr[i] = sourceAr[nrUint16s - 1 - i]; + + retVal = *((T*) destAr); + + delete[] destAr; + } + else{ + TForteByte *tempAr = new TForteByte[currentDataSize]; + for(unsigned int j = 0; j < currentDataSize; j++) + tempAr[j] = pa_acDataArray[j]; + + retVal = *((T*) tempAr); + delete[] tempAr; + } + } + else + retVal = 0; + + return retVal; +} + +EComResponse CModbusComLayer::openConnection(char *pa_acLayerParameter){ + EComResponse eRetVal = e_InitInvalidId; + switch (m_poFb->getComServiceType()){ + case e_Server: + //TODO open server connection + m_eConnectionState = e_Listening; + break; + case e_Client: { + STcpParams tcpParams; + SRtuParams rtuParams; + SCommonParams commonParams; + memset(&tcpParams, 0, sizeof(tcpParams)); + memset(&rtuParams, 0, sizeof(rtuParams)); + memset(&commonParams, 0, sizeof(commonParams)); + + int errCode = processClientParams(pa_acLayerParameter, &tcpParams, &rtuParams, &commonParams); + if(errCode != 0){ + DEVLOG_ERROR("CModbusComLayer:: Invalid input parameters\n"); + } + else{ + m_pModbusConnection = new CModbusClientConnection(); + if(strlen(tcpParams.m_acIp) > 0){ + m_pModbusConnection->setIPAddress(tcpParams.m_acIp); + m_pModbusConnection->setPort(tcpParams.m_nPort); + } + else if(strlen(rtuParams.m_acDevice) > 0){ + m_pModbusConnection->setDevice(rtuParams.m_acDevice); + m_pModbusConnection->setBaud(rtuParams.m_nBaud); + m_pModbusConnection->setParity(rtuParams.m_cParity); + m_pModbusConnection->setDataBit(rtuParams.m_nDataBit); + m_pModbusConnection->setStopBit(rtuParams.m_nStopBit); + } + m_pModbusConnection->setComCallback(this); + m_pModbusConnection->setResponseTimeout(commonParams.m_nResponseTimeout); + m_pModbusConnection->setByteTimeout(commonParams.m_nByteTimeout); + + ((CModbusClientConnection*) m_pModbusConnection)->setSlaveId(commonParams.m_nSlaveId); + + for(unsigned int i = 0; i < commonParams.m_nNrPolls; i++){ + ((CModbusClientConnection*) m_pModbusConnection)->addNewPoll(commonParams.m_nPollFrequency, commonParams.m_nFuncCode, commonParams.m_nReadStartAddress[i], commonParams.m_nReadNrAddresses[i]); + } + for(unsigned int i = 0; i < commonParams.m_nNrSends; i++){ + ((CModbusClientConnection*) m_pModbusConnection)->addNewSend(commonParams.m_nSendStartAddress[i], commonParams.m_nSendNrAddresses[i]); + } + + if(m_pModbusConnection->connect() < 0){ + return eRetVal; + } + m_eConnectionState = e_Connected; + eRetVal = e_InitOk; + } + } + break; + case e_Publisher: + //do nothing as modbus cannot be publisher + break; + case e_Subscriber: + //do nothing as modbus cannot be subscriber + break; + } + + return eRetVal; +} + +int CModbusComLayer::processClientParams(char* pa_acLayerParams, STcpParams* pa_pTcpParams, SRtuParams* pa_pRtuParams, SCommonParams* pa_pCommonParams){ + char *params = new char[strlen(pa_acLayerParams)]; + strcpy(params, pa_acLayerParams); + char *chrStorage; + + pa_pTcpParams->m_acIp[0] = '\0'; + pa_pRtuParams->m_acDevice[0] = '\0'; + + chrStorage = strchr(params, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + if(strcmp(params, "rtu") == 0 || strcmp(params, "RTU") == 0){ + // get rtu params + params = chrStorage; + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + strcpy(pa_pRtuParams->m_acDevice, params); + pa_pRtuParams->m_nBaud = (int) forte::core::util::strtol(chrStorage, 0, 10); + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + pa_pRtuParams->m_cParity = chrStorage[0]; + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + pa_pRtuParams->m_nDataBit = (int) forte::core::util::strtol(chrStorage, 0, 10); + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + pa_pRtuParams->m_nStopBit = (int) forte::core::util::strtol(chrStorage, 0, 10); + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + } + else{ + if(strcmp(params, "tcp") == 0 || strcmp(params, "tcp") == 0){ + params = chrStorage; + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + } + if(isIp(params)){ + // TCP connection + strcpy(pa_pTcpParams->m_acIp, params); + pa_pTcpParams->m_nPort = (unsigned int) forte::core::util::strtoul(chrStorage, 0, 10); + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + } + else{ + return -1; + } + } + // Get common parameters + + pa_pCommonParams->m_nPollFrequency = atol(chrStorage); + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + pa_pCommonParams->m_nFuncCode = (unsigned int) forte::core::util::strtoul(chrStorage, 0, 10); + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + // Search for optional parameter slave id + char *chrSlave = strchr(chrStorage, ':'); + if(chrSlave != NULL){ + chrSlave++; + if(strchr(chrSlave, ':') != NULL){ + pa_pCommonParams->m_nSlaveId = (unsigned int) forte::core::util::strtoul(chrStorage, 0, 10); + + chrStorage = chrSlave; + } + else{ + pa_pCommonParams->m_nSlaveId = 0xFF; + } + } + else{ + return -1; + } + + char *readAddresses = chrStorage; + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return -1; + *chrStorage = '\0'; + ++chrStorage; + + // Find read addresses + int paramLen = strlen(readAddresses); + int nrPolls = 0; + int strIndex = -1; + while(strIndex < paramLen - 1){ + strIndex = findNextStartAddress(readAddresses, ++strIndex); + if(strIndex < 0){ + break; + } + pa_pCommonParams->m_nReadStartAddress[nrPolls] = (unsigned int) forte::core::util::strtoul(const_cast(&readAddresses[strIndex]), 0, 10); + strIndex = findNextStopAddress(readAddresses, strIndex); + pa_pCommonParams->m_nReadNrAddresses[nrPolls] = (unsigned int) forte::core::util::strtoul(const_cast(&readAddresses[strIndex]), 0, 10) - pa_pCommonParams->m_nReadStartAddress[nrPolls] + 1; + nrPolls++; + } + pa_pCommonParams->m_nNrPolls = nrPolls; + + char *writeAddresses = chrStorage; + chrStorage = strchr(chrStorage, ':'); + if(chrStorage != 0){ + *chrStorage = '\0'; + ++chrStorage; + } + + // Find send addresses + paramLen = strlen(writeAddresses); + int nrSends = 0; + strIndex = -1; + while(strIndex < paramLen - 1){ + strIndex = findNextStartAddress(writeAddresses, ++strIndex); + if(strIndex < 0){ + break; + } + pa_pCommonParams->m_nSendStartAddress[nrSends] = (unsigned int) forte::core::util::strtoul(const_cast(&writeAddresses[strIndex]), 0, 10); + strIndex = findNextStopAddress(writeAddresses, strIndex); + pa_pCommonParams->m_nSendNrAddresses[nrSends] = (unsigned int) forte::core::util::strtoul(const_cast(&writeAddresses[strIndex]), 0, 10) - pa_pCommonParams->m_nSendStartAddress[nrSends] + 1; + nrSends++; + } + pa_pCommonParams->m_nNrSends = nrSends; + + // Find responseTimeout and byteTimeout + do{ + if(chrStorage == 0){ + break; + } + pa_pCommonParams->m_nResponseTimeout = (unsigned int) forte::core::util::strtoul(chrStorage, 0, 10); + + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0){ + break; + } + *chrStorage = '\0'; + ++chrStorage; + + pa_pCommonParams->m_nByteTimeout = (unsigned int) forte::core::util::strtoul(chrStorage, 0, 10); + } while(0); + + if(nrPolls == 0 && nrSends == 0) + return -1; + + return 0; +} + +int CModbusComLayer::findNextStartAddress(const char* pa_acParam, int pa_nStartIndex){ + if(pa_nStartIndex == 0){ + switch (pa_acParam[pa_nStartIndex]){ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return pa_nStartIndex; + } + } + + int strLength = strlen(&pa_acParam[pa_nStartIndex]); + const char *pch = strchr(&pa_acParam[pa_nStartIndex], ','); + + if(pch != NULL){ + if(pch - &pa_acParam[pa_nStartIndex] < strLength - 1) + return pch - &pa_acParam[0] + 1; + + } + + return -1; +} + +int CModbusComLayer::findNextStopAddress(const char* pa_acParam, int pa_nStartIndex){ + int strLength = strlen(&pa_acParam[pa_nStartIndex]); + const char *pchComma = strchr(&pa_acParam[pa_nStartIndex], ','); + const char *pchDot = strchr(&pa_acParam[pa_nStartIndex], '.'); + + if(pchComma != NULL && pchDot != NULL){ + if(pchDot < pchComma) + if(pchDot - &pa_acParam[pa_nStartIndex] < strLength - 2) + return pchDot - &pa_acParam[0] + 2; + } + else if(pchDot != NULL) + if(pchDot - &pa_acParam[pa_nStartIndex] < strLength - 2) + return pchDot - &pa_acParam[0] + 2; + + return pa_nStartIndex; +} + +bool CModbusComLayer::isIp(const char* pa_acIp){ + char* str = new char[strlen(pa_acIp)]; + strcpy(str, pa_acIp); + char* pch; + int nrPeriods = 0; + + pch = strtok(str, "."); + while(pch != NULL){ + nrPeriods++; + if(strlen(pch) > 3){ + return false; + } + for(unsigned int i = 0; i < strlen(pch); i++){ + if(!forte::core::util::isDigit(pch[i])){ + return false; + } + } + + pch = strtok(NULL, "."); + } + if(nrPeriods != 4){ + return false; + } + + return true; +} diff --git a/src/modules/modbus/modbuslayer.h b/src/modules/modbus/modbuslayer.h new file mode 100644 index 000000000..d3c83ab06 --- /dev/null +++ b/src/modules/modbus/modbuslayer.h @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2012 -2015 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef MODBUSCOMLAYER_H_ +#define MODBUSCOMLAYER_H_ + +#include +#include "comlayer.h" +#include + +class CModbusConnection; +class CIEC_ANY; + +namespace forte { + + namespace com_infra { + + class CModbusComLayer : public CComLayer{ + public: + CModbusComLayer(CComLayer* pa_poUpperLayer, CCommFB* pa_poComFB); + virtual ~CModbusComLayer(); + + EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); // top interface, called from top + EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + + EComResponse processInterrupt(); + + protected: + void closeConnection(); + + private: + struct STcpParams { + char m_acIp[15]; + unsigned int m_nPort; + }; + struct SRtuParams { + char m_acDevice[256]; + int m_nBaud; + char m_cParity; + int m_nDataBit; + int m_nStopBit; + }; + struct SCommonParams { + unsigned int m_nNrPolls; + unsigned int m_nNrSends; + long m_nPollFrequency; + unsigned int m_nFuncCode; + unsigned int m_nSlaveId; + unsigned int m_nReadStartAddress[100]; + unsigned int m_nReadNrAddresses[100]; + unsigned int m_nSendStartAddress[100]; + unsigned int m_nSendNrAddresses[100]; + unsigned int m_nResponseTimeout; + unsigned int m_nByteTimeout; + }; + + template + T convertFBOutput(TForteByte *pa_acDataArray, unsigned int pa_nDataSize); + + unsigned int convertDataInput(void *pa_poInData, unsigned int pa_nDataSize, TForteUInt16 *pa_poConvertedData); + + EComResponse openConnection(char *pa_acLayerParameter); + + //int processClientParams(char* pa_acLayerParams, char* pa_acIp, unsigned int &pa_nPort, long &pa_nPollFrequency, unsigned int &pa_nFuncCode, unsigned int &pa_nSlaveId, unsigned int *pa_nStartAddress, unsigned int *pa_nNrAddresses); + int processClientParams(char* pa_acLayerParams, STcpParams* pa_pTcpParams, SRtuParams* pa_pRtuParams, SCommonParams* pa_pCommonParams); + int findNextStartAddress(const char* pa_acString, int pa_nStartIndex); + int findNextStopAddress(const char* pa_acString, int pa_nStartIndex); + bool isIp(const char* pa_acIp); + + EComResponse m_eInterruptResp; + + CModbusConnection *m_pModbusConnection; + + TForteByte m_acRecvBuffer[cg_unIPLayerRecvBufferSize]; + unsigned int m_unBufFillSize; + }; + + } + +} + +#endif /* MODBUSCOMLAYER_H_ */ diff --git a/src/modules/modbus/modbuspoll.cpp b/src/modules/modbus/modbuspoll.cpp new file mode 100644 index 000000000..e13d8841a --- /dev/null +++ b/src/modules/modbus/modbuspoll.cpp @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "modbuspoll.h" + +#include + +#include + +CModbusPoll::CModbusPoll(TForteUInt32 pa_nPollInterval, unsigned int pa_nFunctionCode, unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses) : + CModbusTimedEvent(pa_nPollInterval){ + setFunctionCode(pa_nFunctionCode); + addPollAddresses(pa_nStartAddress, pa_nNrAddresses); +} + +CModbusPoll::~CModbusPoll(){ + CSinglyLinkedList::Iterator itEnd = m_lPolls.end(); + for(CSinglyLinkedList::Iterator it = m_lPolls.begin(); it != itEnd; ++it){ + delete *it; + } + m_lPolls.clearAll(); +} + +void CModbusPoll::addPollAddresses(unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses){ + m_lPolls.push_back(new SModbusPollData(pa_nStartAddress, pa_nNrAddresses)); +} + +int CModbusPoll::executeEvent(modbus_t *pa_pModbusConn, void *pa_pRetVal){ + restartTimer(); + + int nrVals = 0; + CSinglyLinkedList::Iterator itEnd = m_lPolls.end(); + for(CSinglyLinkedList::Iterator it = m_lPolls.begin(); it != itEnd; ++it){ + switch (m_nFunctionCode){ + case 1: + nrVals += modbus_read_bits(pa_pModbusConn, it->m_nStartAddress, it->m_nNrAddresses, &((uint8_t*) pa_pRetVal)[nrVals]); + break; + case 2: + nrVals += modbus_read_input_bits(pa_pModbusConn, it->m_nStartAddress, it->m_nNrAddresses, &((uint8_t*) pa_pRetVal)[nrVals]); + break; + case 3: + nrVals += modbus_read_registers(pa_pModbusConn, it->m_nStartAddress, it->m_nNrAddresses, &((uint16_t*) pa_pRetVal)[nrVals]); + break; + case 4: + nrVals += modbus_read_input_registers(pa_pModbusConn, it->m_nStartAddress, it->m_nNrAddresses, &((uint16_t*) pa_pRetVal)[nrVals]); + break; + default: + //TODO Error + break; + } + } + return nrVals; +} diff --git a/src/modules/modbus/modbuspoll.h b/src/modules/modbus/modbuspoll.h new file mode 100644 index 000000000..e74f47ab0 --- /dev/null +++ b/src/modules/modbus/modbuspoll.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef MODBUSPOLL_H_ +#define MODBUSPOLL_H_ + +#include "modbustimedevent.h" +#include + +class CModbusPoll : public CModbusTimedEvent{ + public: + CModbusPoll(TForteUInt32 pa_nPollInterval, unsigned int pa_nFunctionCode, unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses); + ~CModbusPoll(); + + int executeEvent(modbus_t *pa_pModbusConn, void *pa_pRetVal); + + void setFunctionCode(unsigned int pa_nFunctionCode){ + m_nFunctionCode = pa_nFunctionCode; + } + unsigned int getFunctionCode(){ + return m_nFunctionCode; + } + + void addPollAddresses(unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses); + + private: + + struct SModbusPollData{ + unsigned int m_nStartAddress; + unsigned int m_nNrAddresses; + + SModbusPollData(unsigned int pa_nStartAddress, unsigned int pa_nNrAddresses) : + m_nStartAddress(pa_nStartAddress), m_nNrAddresses(pa_nNrAddresses){ + } + ; + }; + + unsigned int m_nFunctionCode; + + CSinglyLinkedList m_lPolls; +}; + +#endif /* MODBUSPOLL_H_ */ diff --git a/src/modules/modbus/modbustimedevent.cpp b/src/modules/modbus/modbustimedevent.cpp new file mode 100644 index 000000000..a45f30037 --- /dev/null +++ b/src/modules/modbus/modbustimedevent.cpp @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "modbustimedevent.h" + +CModbusTimedEvent::CModbusTimedEvent(TForteUInt32 pa_nUpdateInterval) + : m_bIsStarted(false){ + m_nUpdateInterval = pa_nUpdateInterval; + m_oUpdateInterval += (m_nUpdateInterval * cg_nForteTicksPerSecond) / 1000; + + if(pa_nUpdateInterval == 0){ + m_bSingleShotEvent = true; + + activate(); + } + else + m_bSingleShotEvent = false; +} + +void CModbusTimedEvent::setUpdateInterval(TForteUInt32 pa_nUpdateInterval){ + m_nUpdateInterval = pa_nUpdateInterval; + SForteTime newTime; + newTime += (m_nUpdateInterval * cg_nForteTicksPerSecond) / 1000; + m_oUpdateInterval = newTime; +} + +void CModbusTimedEvent::activate(){ + m_oStartTime = CTimerHandler::sm_poFORTETimer->getForteTime(); + m_bIsStarted = true; +} + +void CModbusTimedEvent::deactivate(){ + m_bIsStarted = false; +} + +bool CModbusTimedEvent::readyToExecute(){ + SForteTime currentTime = CTimerHandler::sm_poFORTETimer->getForteTime(); + if (m_oUpdateInterval > currentTime) { + return false; + } + currentTime -= m_oUpdateInterval; + + if(isStarted() && (currentTime > m_oStartTime || currentTime == m_oStartTime)){ + return true; + } + + return false; +} + +void CModbusTimedEvent::restartTimer(){ + + activate(); +} diff --git a/src/modules/modbus/modbustimedevent.h b/src/modules/modbus/modbustimedevent.h new file mode 100644 index 000000000..2dbc6a734 --- /dev/null +++ b/src/modules/modbus/modbustimedevent.h @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _MODBUSTIMEDEVENT_H_ +#define _MODBUSTIMEDEVENT_H_ + +#include "timerha.h" +#include + +class CModbusTimedEvent{ + public: + CModbusTimedEvent(TForteUInt32 pa_nUpdateInterval); // UpdateInterval = 0 => single shot event + virtual ~CModbusTimedEvent(){ + } + + void setUpdateInterval(TForteUInt32 pa_nUpdateInterval); + TForteUInt32 getUpdateInterval() { + return m_nUpdateInterval; + } + + void activate(); + void deactivate(); + + bool isStarted() const { + return m_bIsStarted; + } + + bool readyToExecute(); + + // Classes impementing this should call restartTimer in executeEvent + virtual int executeEvent(modbus_t* pa_pModbusConn, void* pa_pRetVal) = 0; + + protected: + void restartTimer(); + + private: + SForteTime m_oStartTime; + SForteTime m_oUpdateInterval; + + TForteUInt32 m_nUpdateInterval; // Polling interval in milliseconds (0 => single shot event) + + bool m_bSingleShotEvent; + bool m_bIsStarted; +}; + +#endif // _MODBUSTIMEDEVENT_H_ diff --git a/src/modules/modbus/readme.txt b/src/modules/modbus/readme.txt new file mode 100644 index 000000000..e8b8b01f3 --- /dev/null +++ b/src/modules/modbus/readme.txt @@ -0,0 +1,39 @@ +Installation Instructions +The Modbus com interface need the libmodbus (http://libmodbus.org/) library to work. +Follow the steps below to set up your environment before compiling forte +1. libmodbus files should be placed in the following folder structure: + /include/modbus: include files + /lib: libmodbus.lib (windows) or libmodbus.so (posix) +2. When configuring forte project with CMake choose as FORTE_COM_MODBUS_LIB_DIR +3. forte.exe must be able to find the dynamic libmodbus library after build + - copy libmodbus.dll/so to folder with forte.exe or + - add libmodbus.dll/so to library include path + +Parameter Documentation +Modbus Client (TCP) +At the moment the Modbus client can only be used for reading values from a Modbus server. +modbus[(protocol:)ip:port:pollFreqency:functionCode:(slaveId):readAddresses:sendAddresses(:responseTimeout:byteTimeout)] + - protocol: tcp (tcp is default) + - ip: 127.0.0.1 etc + - port: default is 502 + - pollFrequency: polling frequency in milliseconds + - functionCode: 1 - Read Coils + 2 - Read Discrete Inputs + 3 - Read Holding Registers + 4 - Read Input Register + - slaveId (optional): the slave id used by the modbus server (0xFF is standard) + - readAddresses: addresses can be specified between 0-65535 + more than one address (max 100) can be specified using + + comma for separate addresses 0,2,65500 + + dots for interval 5..10 + + combination 0,5..10,2,65500 + - sendAddresses: addresses can be specified between 0-65535 + if data is only read sendAddresses should be left empty + more than one address (max 100) can be specified using + + comma for separate addresses 0,2,65500 + + dots for interval 5..10 + + combination 0,5..10,2,65500 + - responseTimeout (optional): timeout in milliseconds to wait for a response (500ms is default) + - byteTimeout (optional): timeout in milliseconds between two consecutive bytes (500ms is default) + +example: modbus[127.0.0.1:502:1000:3:1:0..3:] diff --git a/src/modules/mqtt_paho/CMakeLists.txt b/src/modules/mqtt_paho/CMakeLists.txt new file mode 100644 index 000000000..fb88bafed --- /dev/null +++ b/src/modules/mqtt_paho/CMakeLists.txt @@ -0,0 +1,35 @@ +############################################################################# +# Copyright (c) 2013, 2014 ACIN +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# Martin Melik Merkumians - initial API and implementation and/or initial documentation +############################################################################# + + +############################################################################# +# PAHO MQTT Com Layer +############################################################################# +forte_add_network_layer(PAHOMQTT OFF "mqtt" MQTTComLayer MQTTComLayer "Enable Paho MQTT Com Layer") +SET(FORTE_COM_PAHOMQTT_DIR "" CACHE PATH "Path to Paho MQTT src directory (leave empty for installed source code)") + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +if(FORTE_COM_PAHOMQTT) + forte_add_sourcefile_hcpp( MQTTComLayer MQTTParameterParser MQTTHandler ) + if(EXISTS ${FORTE_COM_PAHOMQTT_DIR}) + if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + forte_add_include_directories( ${FORTE_COM_PAHOMQTT_DIR}/src ) + forte_add_link_directories( ${FORTE_COM_PAHOMQTT_DIR}/build/output ) + forte_add_link_library( paho-mqtt3a.so paho-mqtt3as.so paho-mqtt3c.so paho-mqtt3cs.so) + elseif("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + #forte_add_include_directories( ${FORTE_COM_PAHOMQTT_DIR}/include ) + #forte_add_link_directories( ${FORTE_COM_PAHOMQTT_DIR}/lib ) + endif() + else(EXISTS ${FORTE_COM_PAHOMQTT_DIR}) + message("No Paho MQTT directory given") + endif(EXISTS ${FORTE_COM_PAHOMQTT_DIR}) +endif(FORTE_COM_PAHOMQTT) diff --git a/src/modules/mqtt_paho/MQTTComLayer.cpp b/src/modules/mqtt_paho/MQTTComLayer.cpp new file mode 100644 index 000000000..5d0a7252e --- /dev/null +++ b/src/modules/mqtt_paho/MQTTComLayer.cpp @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ + + +#include "MQTTComLayer.h" +#include "MQTTParameterParser.h" +#include "MQTTHandler.h" +#include "commfb.h" +#include + +#define QOS 1 + +using namespace forte::com_infra; + +MQTTComLayer::MQTTComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB) : CComLayer(pa_poUpperLayer, pa_poFB) { + // TODO Auto-generated constructor stub + +} + +MQTTComLayer::~MQTTComLayer() { + // TODO Auto-generated destructor stub +} + +EComResponse MQTTComLayer::sendData(void* pa_pvData, + unsigned int pa_unSize) { + + MQTTClient_deliveryToken token; + MQTTClient_message message = MQTTClient_message_initializer; + message.payload = pa_pvData; + message.payloadlen = pa_unSize; + message.qos = QOS; + message.retained = 0; + int errorCode = MQTTClient_publishMessage(MQTTHandler::getInstance().getClient(), mTopicName, &message, NULL); + if (0 != errorCode) { + return e_ProcessDataSendFailed; + } + //while(deliveredtoken != token); + return e_ProcessDataOk; +} + +EComResponse MQTTComLayer::recvData(const void* pa_pvData, + unsigned int pa_unSize) { + memcpy(dataBuffer, pa_pvData, pa_unSize); + bufferSize = pa_unSize; + m_eInterruptResp = e_ProcessDataOk; + m_poFb->interruptCommFB(this); + return m_eInterruptResp; + +} + +EComResponse MQTTComLayer::processInterrupt() { + if(e_ProcessDataOk == m_eInterruptResp) { + if((0 < bufferSize) && (0 != m_poTopLayer)) { + m_eInterruptResp = m_poTopLayer->recvData(dataBuffer, bufferSize); + bufferSize = 0; + //MQTTHandler::getInstance().mqttMessageProcessed(); + } + } + return m_eInterruptResp; +} + +void MQTTComLayer::closeConnection() { + MQTTHandler::getInstance().unregisterLayer(this); +} + +EComResponse MQTTComLayer::openConnection(char* pa_acLayerParameter) { + EComResponse eRetVal = e_InitTerminated; + MQTTParameterParser parser(pa_acLayerParameter); + parser.setSeparator(','); + parser.parseParameters(); + mTopicName = (char*)malloc(strlen(parser[Topic]) + 1); + mTopicName = strcpy(mTopicName, parser[Topic]); + if( MQTTHandler::eRegisterLayerSucceeded == + (MQTTHandler::getInstance()).registerLayer(parser[Address], parser[ClientID], this)) { + eRetVal = e_InitOk; + } + else eRetVal = e_InitInvalidId; + + switch (m_poFb->getComServiceType()){ + case e_Server: + // TODO: Not implemented yet + eRetVal = e_InitTerminated; + break; + case e_Client: + // TODO: Not implemented yet + eRetVal = e_InitTerminated; + break; + case e_Publisher: + //is handled via sendData + break; + case e_Subscriber: + MQTTClient_subscribe(MQTTHandler::getInstance().getClient(), mTopicName, QOS); + break; + } + + return eRetVal; +} + diff --git a/src/modules/mqtt_paho/MQTTComLayer.h b/src/modules/mqtt_paho/MQTTComLayer.h new file mode 100644 index 000000000..4fa76de69 --- /dev/null +++ b/src/modules/mqtt_paho/MQTTComLayer.h @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ + + +#ifndef MQTTCOMLAYER_H_ +#define MQTTCOMLAYER_H_ + +#include "comlayer.h" +extern "C" { + #include +} + +//fbdk[].mqtt[tcp://localhost:1883, ClientID, Topic] + +using namespace forte::com_infra; + +class MQTTComLayer: public forte::com_infra::CComLayer{ +public: + MQTTComLayer(CComLayer* pa_poUpperLayer, CCommFB * pa_poFB); + virtual ~MQTTComLayer(); + + EComResponse sendData(void* pa_pvData, unsigned int pa_unSize); + + EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + + EComResponse processInterrupt(); + + char const* getTopicName() { + return mTopicName; + } + + +protected: + void closeConnection(); + +private: + char* mTopicName; + + char dataBuffer[255]; + unsigned int bufferSize; + EComResponse m_eInterruptResp; + + EComResponse openConnection(char* pa_acLayerParameter); + + enum Parameters { + Address, + ClientID, + Topic + }; +}; + +#endif /* MQTTCOMLAYER_H_ */ diff --git a/src/modules/mqtt_paho/MQTTHandler.cpp b/src/modules/mqtt_paho/MQTTHandler.cpp new file mode 100644 index 000000000..7f334b955 --- /dev/null +++ b/src/modules/mqtt_paho/MQTTHandler.cpp @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ + + +#include +#include +#include +#include + +DEFINE_SINGLETON(MQTTHandler); + +MQTTClient_connectOptions MQTTHandler::clientConnectionOptions = +MQTTClient_connectOptions_initializer; + +CSyncObject MQTTHandler::mLockMessageDelivery = CSyncObject(); + +MQTTClient MQTTHandler::client = 0; +char* MQTTHandler::mClientId = 0; +char* MQTTHandler::mAddress = 0; + +MQTTHandler::MQTTHandler(){ + +} + +MQTTHandler::~MQTTHandler(){ + MQTTClient_disconnect(client, 10000); + MQTTClient_destroy(&client); +} + +int MQTTHandler::mqttMessageArrived(void* context, char* topicName, int topicLen, MQTTClient_message* message){ + //TODO: Check if handler allowed + + + if(0 != context){ + MQTTHandler *handler = static_cast(context); + + void* pPayLoad = message->payload; + unsigned int payLoadSize = static_cast(message->payloadlen); + + CCriticalRegion section(mLockMessageDelivery); //Start critical section proected the list + for(CSinglyLinkedList::Iterator it = handler->layers.begin(); it != handler->layers.end(); ++it){ + if(0 == strcmp((*it)->getTopicName(), topicName)){ + if(forte::com_infra::e_Nothing != (*it)->recvData(pPayLoad, payLoadSize)){ + handler->startNewEventChain((*it)->getCommFB()); + } + } + } + //End critical section + } + MQTTClient_freeMessage(&message); + MQTTClient_free(topicName); + + return 1; +} + +int MQTTHandler::registerLayer(char* paAddress, char* paClientId, MQTTComLayer* paLayer){ + + int rc; + if(client == 0){ + mClientId = paClientId; + mAddress = paAddress; + MQTTClient_create(&client, mAddress, mClientId, + MQTTCLIENT_PERSISTENCE_NONE, NULL); + clientConnectionOptions.keepAliveInterval = 20; + clientConnectionOptions.cleansession = 1; + rc = MQTTClient_setCallbacks(client, this, NULL, MQTTHandler::mqttMessageArrived, NULL); + if(rc != MQTTCLIENT_SUCCESS){ + return eConnectionFailed; + } + + rc = MQTTClient_connect(client, &clientConnectionOptions); + if(rc != MQTTCLIENT_SUCCESS){ + return eConnectionFailed; + } + } + else if((0 != strcmp(paClientId, mClientId)) || (0 != strcmp(paAddress, mAddress))){ + return eWrongClientID; + } + MQTTHandler::layers.push_back(paLayer); + return eRegisterLayerSucceeded; +} + +void MQTTHandler::unregisterLayer(MQTTComLayer* paLayer){ + //TODO: Implement unregister; search list and delete node +} + +void MQTTHandler::enableHandler(void){ + //TODO: Should also work empty +} + +void MQTTHandler::disableHandler(void){ + //TODO: Should also work empty +} + +void MQTTHandler::setPriority(int pa_nPriority){ + //TODO: Should also work empty +} + +int MQTTHandler::getPriority(void) const{ + return 0; +} diff --git a/src/modules/mqtt_paho/MQTTHandler.h b/src/modules/mqtt_paho/MQTTHandler.h new file mode 100644 index 000000000..564284f6e --- /dev/null +++ b/src/modules/mqtt_paho/MQTTHandler.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ + + +#ifndef MQTTHANDLER_H_ +#define MQTTHANDLER_H_ + +#include +#include +#include +#include +#include "sync.h" + +extern "C" { +#include +} + +class MQTTHandler : public CExternalEventHandler { + DECLARE_SINGLETON(MQTTHandler) +public: + enum RegisterLayerReturnCodes { + eRegisterLayerSucceeded, + eWrongClientID, + eConnectionFailed + }; + int registerLayer(char* paAddress, char* paClientId, MQTTComLayer* paLayer); + + void unregisterLayer(MQTTComLayer* paLayer); + + MQTTClient& getClient(void) { + return client; + } + + void mqttMessageProcessed(void); + + virtual void enableHandler(void); + /*!\brief Disable this event source + */ + virtual void disableHandler(void); + /*!\brief Sets the priority of the event source + * + * \param pa_nPriority new priority of the event source + */ + virtual void setPriority(int pa_nPriority); + /*!\brief Get the current priority of the event source + * + * \return current priority + */ + virtual int getPriority(void) const; + + static int mqttMessageArrived(void *context, char *topicName, int topicLen, MQTTClient_message *message); + +private: + static char* mClientId; + static char* mAddress; + + static CSyncObject mLockMessageDelivery; + + static MQTTClient client; + static MQTTClient_connectOptions clientConnectionOptions; + + CSinglyLinkedList layers; + + +}; + +#endif /* MQTTHANDLER_H_ */ diff --git a/src/modules/mqtt_paho/MQTTParameterParser.cpp b/src/modules/mqtt_paho/MQTTParameterParser.cpp new file mode 100644 index 000000000..dee23767e --- /dev/null +++ b/src/modules/mqtt_paho/MQTTParameterParser.cpp @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ + + +#include +#include +#include + +MQTTParameterParser::MQTTParameterParser(char* paParameters) : mParameters(paParameters) { + mCurrentParameter = 0; +} + +MQTTParameterParser::~MQTTParameterParser() { + // TODO Auto-generated destructor stub +} + +void MQTTParameterParser::setSeparator(char paSeparator) { + mSeparator = paSeparator; +} + +void MQTTParameterParser::parseParameters() { + parsePosition = mParameters; + for(int i = 0; i < mAmountOfParameters; ++i) { + moveToPositionOfFirstNonWhiteSpaceCharacter(); + saveStartPositionForParameterSubstring(i); + moveToPositionOfNextParameterSeparatorOrEndOfString(); + trimTrailingWhiteSpacesOfParameterSubstring(); + moveToNextParameterStart(); + } +} + +void MQTTParameterParser::moveToPositionOfFirstNonWhiteSpaceCharacter() { + while (0 != isspace(*parsePosition)) { + ++parsePosition; + } +} + +void MQTTParameterParser::saveStartPositionForParameterSubstring(int paParameterNumber) { + mParameterSeparators[paParameterNumber] = parsePosition; +} + +void MQTTParameterParser::moveToPositionOfNextParameterSeparatorOrEndOfString() { + while (mSeparator != *parsePosition && '\0' != *parsePosition) { + ++parsePosition; + } +} + +void MQTTParameterParser::trimTrailingWhiteSpacesOfParameterSubstring() { + char* backTraceCharacter = parsePosition; + *backTraceCharacter = ' '; + while( 0 != isspace(*backTraceCharacter) ) { + --backTraceCharacter; + } + backTraceCharacter++; + *backTraceCharacter = '\0'; +} + +void MQTTParameterParser::moveToNextParameterStart() { + ++parsePosition; +} + +void MQTTParameterParser::moveToNextParameter() { + mCurrentParameter < mAmountOfParameters ? ++mCurrentParameter: mCurrentParameter; +} + +char* MQTTParameterParser::getCurrentParameter() { + return mParameterSeparators[mCurrentParameter]; +} + +char* MQTTParameterParser::operator [](const int& index) { + return mParameterSeparators[index]; +} diff --git a/src/modules/mqtt_paho/MQTTParameterParser.h b/src/modules/mqtt_paho/MQTTParameterParser.h new file mode 100644 index 000000000..9ecaa5e1e --- /dev/null +++ b/src/modules/mqtt_paho/MQTTParameterParser.h @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2013, 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Martin Melik Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ + + +#ifndef MQTTPARAMETERPARSER_H_ +#define MQTTPARAMETERPARSER_H_ + +//mqtt[tcp://localhost:1883, ClientID, Topic] + +class MQTTParameterParser { +public: + MQTTParameterParser(char* paParameters); + virtual ~MQTTParameterParser(); + + void setSeparator(char paSeparator); + void parseParameters(); + void moveToNextParameter(); + char* getCurrentParameter(); + + char* operator[](int const& index); + + +private: + static int const mAmountOfParameters = 3; + int mCurrentParameter; + char* mParameterSeparators[mAmountOfParameters]; + char mSeparator; + char* const mParameters; + + char* parsePosition; + + void moveToPositionOfFirstNonWhiteSpaceCharacter(); + void saveStartPositionForParameterSubstring(int paParameterNumber); + void moveToPositionOfNextParameterSeparatorOrEndOfString(); + void trimTrailingWhiteSpacesOfParameterSubstring(); + void moveToNextParameterStart(); +}; + +#endif /* MQTTPARAMETERPARSER_H_ */ diff --git a/src/modules/opc/CMakeLists.txt b/src/modules/opc/CMakeLists.txt new file mode 100644 index 000000000..051ca4886 --- /dev/null +++ b/src/modules/opc/CMakeLists.txt @@ -0,0 +1,35 @@ +#******************************************************************************* +# * Copyright (c) 2012, 2015 AIT, ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# OPC Com Layer +############################################################################# + +forte_add_network_layer(OPC OFF "opc" COpcComLayer opccomlayer "Enable OPC communication") +SET(FORTE_COM_OPC_LIB_ROOT "" CACHE PATH "Path to OPC library root directory") +SET(FORTE_COM_OPC_BOOST_ROOT "" CACHE PATH "Path to Boost library root directory") + +if(FORTE_COM_OPC) + if("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + forte_add_sourcefile_hcpp( opcconnection opcconnectionhandler opceventhandler + opcconnectionimpl opcprocessvar Cmd_AddConnection + Cmd_AddOPCProcessVar Cmd_SetProcessVarValue ) + + forte_add_include_directories( ${FORTE_COM_OPC_BOOST_ROOT} ) + + forte_add_include_directories( ${FORTE_COM_OPC_LIB_ROOT}/include ) + forte_add_link_directories( ${FORTE_COM_OPC_LIB_ROOT}/lib ) + forte_add_link_library( OPCClientToolKit.lib ) + else() + # Generate error since OPC only works with Windows + MESSAGE(SEND_ERROR "Win32 has to be slected for FORTE_ARCHITECTURE for the OPC Com Layer") + endif() +endif(FORTE_COM_OPC) diff --git a/src/modules/opc/Cmd_AddConnection.cpp b/src/modules/opc/Cmd_AddConnection.cpp new file mode 100644 index 000000000..dc3c77c4b --- /dev/null +++ b/src/modules/opc/Cmd_AddConnection.cpp @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "Cmd_AddConnection.h" +#include "opcconnectionimpl.h" + +CCmd_AddConnection::CCmd_AddConnection(COpcConnectionImpl *pa_pConnection) : + m_pConnection(pa_pConnection){ +} + +CCmd_AddConnection::~CCmd_AddConnection(void){ +} + +void CCmd_AddConnection::runCommand(){ + m_pConnection->connect(); +} +const char* CCmd_AddConnection::getCommandName() const{ + return "Cmd_AddConnection"; +} diff --git a/src/modules/opc/Cmd_AddConnection.h b/src/modules/opc/Cmd_AddConnection.h new file mode 100644 index 000000000..1e4a4bf31 --- /dev/null +++ b/src/modules/opc/Cmd_AddConnection.h @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef CMDADDCONNECTION_H_ +#define CMDADDCONNECTION_H_ +#include "ICmd.h" + +class COpcConnectionImpl; + +class CCmd_AddConnection : public ICmd{ + public: + CCmd_AddConnection(COpcConnectionImpl *pa_pConnection); + virtual ~CCmd_AddConnection(); + + virtual void runCommand(); + virtual const char* getCommandName() const; + private: + COpcConnectionImpl* m_pConnection; +}; + +#endif // CMDADDCONNECTION_H_ diff --git a/src/modules/opc/Cmd_AddOPCProcessVar.cpp b/src/modules/opc/Cmd_AddOPCProcessVar.cpp new file mode 100644 index 000000000..44f7fc68c --- /dev/null +++ b/src/modules/opc/Cmd_AddOPCProcessVar.cpp @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "Cmd_AddOPCProcessVar.h" +#include "opcconnectionimpl.h" + +CCmd_AddOPCProcessVar::CCmd_AddOPCProcessVar(COpcConnectionImpl *pa_pConnection, COpcProcessVar* pa_pNewItem) : + m_pOpcConn(pa_pConnection), m_pNewProcessVar(pa_pNewItem){ +} + +CCmd_AddOPCProcessVar::~CCmd_AddOPCProcessVar(void){ +} + +void CCmd_AddOPCProcessVar::runCommand(){ + m_pOpcConn->addItem(m_pNewProcessVar); +} + +const char* CCmd_AddOPCProcessVar::getCommandName() const{ + return "Cmd_AddOPCProcessVar"; +} diff --git a/src/modules/opc/Cmd_AddOPCProcessVar.h b/src/modules/opc/Cmd_AddOPCProcessVar.h new file mode 100644 index 000000000..df6b3b5ca --- /dev/null +++ b/src/modules/opc/Cmd_AddOPCProcessVar.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef CMDADDPROCESSVAR_H_ +#define CMDADDPROCESSVAR_H_ +#include "ICmd.h" + +class COpcConnectionImpl; +class COpcProcessVar; + +class CCmd_AddOPCProcessVar : public ICmd{ + public: + CCmd_AddOPCProcessVar(COpcConnectionImpl *pa_pConnection, COpcProcessVar* pa_pNewItem); + virtual ~CCmd_AddOPCProcessVar(void); + + virtual void runCommand(); + virtual const char* getCommandName() const; + + private: + COpcConnectionImpl *m_pOpcConn; + COpcProcessVar* m_pNewProcessVar; +}; + +#endif //CMDADDPROCESSVAR_H_ diff --git a/src/modules/opc/Cmd_SetProcessVarValue.cpp b/src/modules/opc/Cmd_SetProcessVarValue.cpp new file mode 100644 index 000000000..ba61eddf9 --- /dev/null +++ b/src/modules/opc/Cmd_SetProcessVarValue.cpp @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "Cmd_SetProcessVarValue.h" + +#include "opcprocessvar.h" +#include "opcconnectionimpl.h" + +CCmd_SetProcessVarValue::CCmd_SetProcessVarValue(COpcProcessVar * pa_pOpcVar) : + m_pOpcVar(pa_pOpcVar){ +} + +CCmd_SetProcessVarValue::~CCmd_SetProcessVarValue(void){ +} + +void CCmd_SetProcessVarValue::runCommand(){ + m_pOpcVar->sendItemData(); +} +const char* CCmd_SetProcessVarValue::getCommandName() const{ + return "Cmd_SetProcessVarValue"; +} diff --git a/src/modules/opc/Cmd_SetProcessVarValue.h b/src/modules/opc/Cmd_SetProcessVarValue.h new file mode 100644 index 000000000..346c6270b --- /dev/null +++ b/src/modules/opc/Cmd_SetProcessVarValue.h @@ -0,0 +1,34 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef CMDSETPROCESSVARVALUE_H_ +#define CMDSETPROCESSVARVALUE_H_ + +#include "ICmd.h" + +#include +#include "Variant.h" + +class COpcProcessVar; +class COpcConnectionImpl; + +class CCmd_SetProcessVarValue : public ICmd{ + public: + CCmd_SetProcessVarValue(COpcProcessVar * pa_pOpcVar); + virtual ~CCmd_SetProcessVarValue(void); + + virtual void runCommand(); + virtual const char* getCommandName() const; + + private: + COpcProcessVar* m_pOpcVar; +}; + +#endif //CMDSETPROCESSVARVALUE_H_ diff --git a/src/modules/opc/ICmd.h b/src/modules/opc/ICmd.h new file mode 100644 index 000000000..78f2b55bf --- /dev/null +++ b/src/modules/opc/ICmd.h @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef ICMD_H_ +#define ICMD_H_ + +class ICmd{ + public: + ICmd(){ + } + ; + virtual ~ICmd(){ + } + ; + + virtual void runCommand() = 0; + virtual const char* getCommandName() const = 0; +}; + +#endif //ICMD_H_ diff --git a/src/modules/opc/Variant.h b/src/modules/opc/Variant.h new file mode 100644 index 000000000..82ee71972 --- /dev/null +++ b/src/modules/opc/Variant.h @@ -0,0 +1,340 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Werner Tremmel - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef VARIANTNEW_H_ +#define VARIANTNEW_H_ + +#include + +/*! \brief structure for simplified handling of the VARIANT + * + * The structure simplifies the handling of the VARIANT with numeric types. + */ + +#include +#include + +struct Variant : public VARIANT{ + public: + class VariantException : public std::exception{ + public: + VariantException(){ + } + virtual const char* what() throw (){ + return "VariantException: unknown variant type"; + } + }; + + ~Variant(){ + } + Variant(){ + } + + Variant(const _variant_t &value) : + VARIANT(value){ + } + Variant(const VARIANT &value) : + VARIANT(value){ + } + Variant(bool value){ + setbool(value); + } + explicit Variant(BOOL value){ + setbool(value != 0); + } + Variant(VARIANT_BOOL value){ + setbool(value != 0); + } + + template Variant(T value){ + set(value); + } + + template T get() const{ + switch (vt){ + case VT_I8: + return static_cast < T > (llVal); + case VT_I4: + return static_cast < T > (lVal); + case VT_I2: + return static_cast < T > (iVal); + case VT_I1: + return static_cast < T > (cVal); + case VT_UI8: + return static_cast < T > (ullVal); + case VT_UI4: + return static_cast < T > (ulVal); + case VT_UI2: + return static_cast < T > (uiVal); + case VT_UI1: + return static_cast < T > (bVal); + case VT_R8: + return static_cast < T > (dblVal); + case VT_R4: + return static_cast < T > (fltVal); + case VT_INT: + return static_cast < T > (intVal); + case VT_UINT: + return static_cast < T > (uintVal); + case VT_BOOL: + return boolVal != 0 ? static_cast < T > (1) : static_cast < T > (0); + + default: + throw VariantException(); + } + } + template<> std::string get() const{ + switch (vt){ + case VT_I8: + return boost::lexical_cast < std::string > (llVal); + case VT_I4: + return boost::lexical_cast < std::string > (lVal); + case VT_I2: + return boost::lexical_cast < std::string > (iVal); + case VT_I1: + return boost::lexical_cast < std::string > (cVal); + case VT_UI8: + return boost::lexical_cast < std::string > (ullVal); + case VT_UI4: + return boost::lexical_cast < std::string > (ulVal); + case VT_UI2: + return boost::lexical_cast < std::string > (uiVal); + case VT_UI1: + return boost::lexical_cast < std::string > (bVal); + case VT_R8: + return boost::lexical_cast < std::string > (dblVal); + case VT_R4: + return boost::lexical_cast < std::string > (fltVal); + case VT_INT: + return boost::lexical_cast < std::string > (intVal); + case VT_UINT: + return boost::lexical_cast < std::string > (uintVal); + case VT_BOOL: + return boolVal != 0 ? boost::lexical_cast < std::string > (true) : boost::lexical_cast < std::string > (false); + + default: + throw VariantException(); + } + } + template<> bool get() const{ + switch (vt){ + case VT_I8: + return llVal != 0 ? true : false; + case VT_I4: + return lVal != 0 ? true : false; + case VT_I2: + return iVal != 0 ? true : false; + case VT_I1: + return cVal != 0 ? true : false; + case VT_UI8: + return ullVal != 0 ? true : false; + case VT_UI4: + return ulVal != 0 ? true : false; + case VT_UI2: + return uiVal != 0 ? true : false; + case VT_UI1: + return bVal != 0 ? true : false; + case VT_R8: + return dblVal != 0 ? true : false; + case VT_R4: + return fltVal != 0 ? true : false; + case VT_INT: + return intVal != 0 ? true : false; + case VT_UINT: + return uintVal != 0 ? true : false; + case VT_BOOL: + return boolVal != 0 ? true : false; + + default: + throw VariantException(); + } + } + void setbool(bool value){ + boolVal = value ? 0xffff : 0; + vt = VT_BOOL; + } + template void set(T value){ + getField() = value; + vt = getType(); + } + template<> void set(bool value){ + setbool(value); + } + void setBOOL(BOOL value){ + setbool(value != 0); + } + void setVARIANT_BOOL(VARIANT_BOOL value){ + setbool(value != 0); + } + + template bool isType() const{ + return vt == getType(); + } + + bool isInteger() const{ + switch (vt){ + case VT_I8: + case VT_I4: + case VT_I2: + case VT_I1: + case VT_INT: + return true; + default: + return false; + } + } + bool isUnsignedInteger() const{ + switch (vt){ + case VT_UI8: + case VT_UI4: + case VT_UI2: + case VT_UI1: + case VT_UINT: + return true; + default: + return false; + } + } + bool isFloatingPoint() const{ + switch (vt){ + case VT_R8: + case VT_R4: + return true; + default: + return false; + } + } + + template VARTYPE getType() const{ + constraint(); + } + template<> VARTYPE getType() const{ + return VT_I8; + } + template<> VARTYPE getType() const{ + return VT_I4; + } + template<> VARTYPE getType() const{ + return VT_I2; + } + template<> VARTYPE getType() const{ + return VT_I1; + } + template<> VARTYPE getType() const{ + return VT_I1; + } + template<> VARTYPE getType() const{ + return VT_UI8; + } + template<> VARTYPE getType() const{ + return VT_UI4; + } + template<> VARTYPE getType() const{ + return VT_UI2; + } + template<> VARTYPE getType() const{ + return VT_UI1; + } + template<> VARTYPE getType() const{ + return VT_R4; + } + template<> VARTYPE getType() const{ + return VT_R8; + } + //template<> VARTYPE getType() const{ + // return VT_BOOL; + //} + template<> VARTYPE getType() const{ + return VT_INT; + } + template<> VARTYPE getType() const{ + return VT_UINT; + } + + template T &getField(){ + constraint(); + } + template<> LONGLONG &getField(){ + return llVal; + } + template<> LONG &getField(){ + return lVal; + } + template<> SHORT &getField(){ + return iVal; + } + template<> CHAR &getField(){ + return cVal; + } + template<> signed char &getField(){ + return (signed char&)cVal; + } + template<> ULONGLONG &getField(){ + return ullVal; + } + template<> ULONG &getField(){ + return ulVal; + } + template<> USHORT &getField(){ + return uiVal; + } + template<> BYTE &getField(){ + return bVal; + } + template<> float &getField(){ + return fltVal; + } + template<> double &getField(){ + return dblVal; + } + template<> INT &getField(){ + return intVal; + } + template<> UINT &getField(){ + return uintVal; + } + + bool operator==(const Variant &other) const{ + if(vt != other.vt) + return false; + ULONGLONG mask = ~0ul; + switch (vt){ + case VT_I4: + case VT_UI4: + case VT_INT: + case VT_UINT: + case VT_R4: + mask = 0xffffffffull; + break; + case VT_I2: + case VT_UI2: + case VT_BOOL: + mask = 0xffffull; + break; + case VT_I1: + case VT_UI1: + mask = 0xffull; + break; + } + return ((ullVal ^ other.ullVal) & mask) == 0; + } + + /*! \brief Compiler error, when used + * + * This is only here to throw a compiler error when used. So the unsupported types are caught by the compiler + * and not by the runtime system + */ + template static void constraint(){ + char a[2]; + a[1.2] = 0; + } +}; + +#endif //VARIANTNEW_H_ diff --git a/src/modules/opc/opccomlayer.cpp b/src/modules/opc/opccomlayer.cpp new file mode 100644 index 000000000..8e7ed1387 --- /dev/null +++ b/src/modules/opc/opccomlayer.cpp @@ -0,0 +1,467 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Patrick Smejkal, Alois Zoitl, Martin Melik-Merkumians - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "opccomlayer.h" +#include "../../arch/devlog.h" +#include "commfb.h" + +#include "opcconnection.h" +#include "opcconnectionhandler.h" +#include "Variant.h" +#include + +using namespace forte::com_infra; + +COpcComLayer::COpcComLayer(CComLayer* pa_poUpperLayer, CCommFB* pa_poComFB) : +CComLayer(pa_poUpperLayer, pa_poComFB), m_bLayerParamsOK(false), m_eInterruptResp(e_Nothing){ + m_acOpcGroupName = m_poFb->getInstanceName(); +} + +COpcComLayer::~COpcComLayer(){ +} + +void COpcComLayer::closeConnection(){ + DEVLOG_DEBUG("COpcComLayer::closeConnection() \n"); + COpcConnectionHandler::getInstance().removeOpcConnection(m_pOpcConnection->getHost(), m_pOpcConnection->getServerName(), m_acOpcGroupName); + + m_eConnectionState = e_Disconnected; +} + +EComResponse COpcComLayer::sendData(void *pa_pvData, unsigned int pa_unSize){ + EComResponse eRetVal = e_ProcessDataOk; + + if((0 != m_poFb)){ + if(m_pOpcConnection->isConnected()){ + switch (m_poFb->getComServiceType()){ + case e_Server: + //TODO + break; + case e_Client: { + convertInputData(pa_pvData, pa_unSize); + + TOpcProcessVarList::Iterator itEnd = m_lFBInputVars.end(); + for(TOpcProcessVarList::Iterator it = m_lFBInputVars.begin(); it != itEnd; ++it){ + if (it->getIsActive()) + m_pOpcConnection->send_sendItemData((*it)); + } + break; + } + case e_Publisher: + //do nothing as OPC cannot be publisher + break; + case e_Subscriber: + //do nothing as subscribers do not send data + break; + } + } + } + return eRetVal; +} + +EComResponse COpcComLayer::processInterrupt(){ + EComResponse eRet = e_Nothing; + EComResponse currentComResponse; + + { + CCriticalRegion criticalRegion(m_oSync); + TComResponseList::Iterator comIt(m_lComResponses.begin()); + currentComResponse = *comIt; + m_lComResponses.pop_front(); + } + + switch (currentComResponse){ + case e_ProcessDataOk: + switch (m_eConnectionState){ + case e_Connected: { + CIEC_ANY *apoRDs = m_poFb->getRDs(); + unsigned int nrRDs = m_poFb->getNumRD(); + + TOpcProcessVarList::Iterator itEnd = m_lFBOutputVars.end(); + TOpcProcessVarList::Iterator it = m_lFBOutputVars.begin(); + for(unsigned int i = 0; i < nrRDs && it != itEnd; i++, ++it){ + setOutputValue(&apoRDs[i], &it->updateValue()); + } + + break; + } + case e_Disconnected: + case e_Listening: + case e_ConnectedAndListening: + default: + break; + } + eRet = e_ProcessDataOk; + break; + case e_InitInvalidId: + eRet = e_InitInvalidId; + break; + case e_InitTerminated: + eRet = e_InitTerminated; + break; + } + + return eRet; +} + +EComResponse COpcComLayer::recvData(const void *, unsigned int){ + EComResponse eRet = e_Nothing; + + switch (m_poFb->getComServiceType()){ + case e_Server: + //TODO + break; + case e_Client: { + switch (m_pOpcConnection->getConnectionState()){ + case COpcConnection::e_Connected: + // Successfully connected --> adding OPC items + if(addOpcItems() < 0){ + //TODO + } + else + m_eConnectionState = e_Connected; + break; + case COpcConnection::e_ConnectionFailed: + { + CCriticalRegion criticalRegion(m_oSync); + m_lComResponses.push_back(e_InitTerminated); + } + m_poFb->interruptCommFB(this); + eRet = e_InitTerminated; + break; + case COpcConnection::e_ItemAddedOk: + //do nothing + break; + case COpcConnection::e_ItemAddedFailed: + { + CCriticalRegion criticalRegion(m_oSync); + m_lComResponses.push_back(e_InitTerminated); + } + m_poFb->interruptCommFB(this); + eRet = e_InitTerminated; + break; + case COpcConnection::e_DataReceived: { + int nRetVal = m_pOpcConnection->receiveData(m_acOpcGroupName, &m_lFBOutputVars); + if (nRetVal > 0) { + //we successfully received data + CCriticalRegion criticalRegion(m_oSync); + m_lComResponses.push_back(e_ProcessDataOk); + } + m_poFb->interruptCommFB(this); + eRet = e_ProcessDataOk; + break; + } + case COpcConnection::e_Disconnected: + //TODO error during connection try + break; + default: + break; + } + break; + } + case e_Publisher: + //do nothing as publisher cannot receive data + case e_Subscriber: + //do nothing as OPC cannot be subscribers + break; + } + + return eRet; +} + + EComResponse COpcComLayer::openConnection(char *pa_acLayerParameter){ + EComResponse eRetVal = e_InitInvalidId; + m_eConnectionState = e_Disconnected; + + switch (m_poFb->getComServiceType()){ + case e_Server: + //TODO + break; + case e_Client: + processClientParams(pa_acLayerParameter); + if(m_bLayerParamsOK){ + eRetVal = e_InitOk; + m_pOpcConnection = COpcConnectionHandler::getInstance().getOpcConnection(m_acHost, m_acServerName, m_acOpcGroupName, m_nUpdateRate, m_nDeadBand, this); + + m_pOpcConnection->send_connect(); + + COpcConnection::EOpcConnectionEvents connState = m_pOpcConnection->getConnectionState(); + if (connState == COpcConnection::e_Connected) { + m_eConnectionState = e_Connected; + addOpcItems(); + } + else if (connState == COpcConnection::e_ConnectionFailed) + eRetVal = e_InitTerminated; + } + break; + case e_Publisher: + //do nothing, OPC cannot be publisher + break; + case e_Subscriber: + //do nothing, OPC cannot be subscriber + break; + } + + return eRetVal; + } + + int COpcComLayer::addOpcItems(){ + int result = 0; + + // Add input items + TOpcProcessVarList::Iterator itEnd = m_lFBInputVars.end(); + for(TOpcProcessVarList::Iterator it = m_lFBInputVars.begin(); it != itEnd; ++it){ + result = m_pOpcConnection->send_addItem(*it); + } + + // Add output items + itEnd = m_lFBOutputVars.end(); + for(TOpcProcessVarList::Iterator it = m_lFBOutputVars.begin(); it != itEnd; ++it){ + result = m_pOpcConnection->send_addItem(*it); + } + + return result; + } + + void COpcComLayer::setOutputValue(CIEC_ANY *pa_pDataOut, Variant * pa_pValue){ + switch (pa_pDataOut->getDataTypeID()){ + case CIEC_ANY::e_BOOL: + pa_pDataOut->setValue(CIEC_BOOL(pa_pValue->get())); + break; + case CIEC_ANY::e_SINT: + pa_pDataOut->setValue(CIEC_SINT(pa_pValue->get())); + break; + case CIEC_ANY::e_INT: + pa_pDataOut->setValue(CIEC_INT(pa_pValue->get())); + break; + case CIEC_ANY::e_DINT: + pa_pDataOut->setValue(CIEC_DINT(pa_pValue->get())); + break; + case CIEC_ANY::e_LINT: + pa_pDataOut->setValue(CIEC_LINT(pa_pValue->get())); + break; + case CIEC_ANY::e_USINT: + pa_pDataOut->setValue(CIEC_USINT(pa_pValue->get())); + break; + case CIEC_ANY::e_UINT: + pa_pDataOut->setValue(CIEC_UINT(pa_pValue->get())); + break; + case CIEC_ANY::e_UDINT: + pa_pDataOut->setValue(CIEC_UDINT(pa_pValue->get())); + break; + case CIEC_ANY::e_ULINT: + pa_pDataOut->setValue(CIEC_ULINT(pa_pValue->get())); + break; + case CIEC_ANY::e_BYTE: + pa_pDataOut->setValue(CIEC_BYTE(pa_pValue->get())); + break; + case CIEC_ANY::e_WORD: + pa_pDataOut->setValue(CIEC_WORD(pa_pValue->get())); + break; + case CIEC_ANY::e_DWORD: + pa_pDataOut->setValue(CIEC_DWORD(pa_pValue->get())); + break; + case CIEC_ANY::e_LWORD: + pa_pDataOut->setValue(CIEC_LWORD(pa_pValue->get())); + break; + case CIEC_ANY::e_REAL: + pa_pDataOut->setValue(CIEC_REAL(pa_pValue->get())); + break; + case CIEC_ANY::e_LREAL: + pa_pDataOut->setValue(CIEC_LREAL(pa_pValue->get())); + break; + default: + //TODO + break; + } + } + + void COpcComLayer::processClientParams(char* pa_acLayerParams){ + + char *chrStorage; + char *chrHost; + char *chrServer; + char *temp; + + // Get Host + chrStorage = strchr(pa_acLayerParams, ':'); + if(chrStorage == 0) + return; + *chrStorage = '\0'; + ++chrStorage; + chrHost = (char*) malloc(strlen(pa_acLayerParams) + 1); + strcpy(chrHost, pa_acLayerParams); + if(strcmp(chrHost, "127.0.0.1") == 0 || strcmp(chrHost, "localhost") == 0) + m_acHost = ""; + else + m_acHost = chrHost; + + // Get server name + temp = chrStorage; + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return; + *chrStorage = '\0'; + ++chrStorage; + chrServer = (char*) malloc(strlen(temp) + 1); + strcpy(chrServer, temp); + m_acServerName = chrServer; + + // Get update rate + m_nUpdateRate = atol(chrStorage); + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return; + *chrStorage = '\0'; + ++chrStorage; + + // Get dead band + m_nDeadBand = (float) atof(chrStorage); + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return; + *chrStorage = '\0'; + ++chrStorage; + + // Get FB input items + char * inputItems = chrStorage; + chrStorage = strchr(chrStorage, ':'); + if(chrStorage == 0) + return; + *chrStorage = '\0'; + ++chrStorage; + int nrItems = 0; + char *pch; + pch = strtok(inputItems, ","); + while(pch != NULL){ + char *itemName = (char*) malloc(strlen(pch) + 1); + strcpy(itemName, pch); + m_lFBInputVars.push_back(new COpcProcessVar(m_acOpcGroupName, itemName, COpcProcessVar::e_FBInput)); + nrItems++; + pch = strtok(NULL, ","); + } + + // Get FB output items + pch = strtok(chrStorage, ","); + while(pch != NULL){ + char *itemName = (char*) malloc(strlen(pch) + 1); + strcpy(itemName, pch); + m_lFBOutputVars.push_back(new COpcProcessVar(m_acOpcGroupName, itemName, COpcProcessVar::e_FBOutput)); + nrItems++; + + pch = strtok(NULL, ","); + } + + if(nrItems > 0) + m_bLayerParamsOK = true; + + } + + void COpcComLayer::convertInputData(void *pa_pData, unsigned int pa_nSize){ + CIEC_ANY *apoSDs = (CIEC_ANY*) pa_pData; + unsigned int nrSDs = pa_nSize; + unsigned int sdIndex = 0; + + TOpcProcessVarList::Iterator it_var = m_lFBInputVars.begin(); + TOpcProcessVarList::Iterator itEnd = m_lFBInputVars.end(); + + while(sdIndex < nrSDs && it_var != itEnd){ + CIEC_ANY *dataIn = &apoSDs[sdIndex]; + Variant newVariant; + unsigned int valueSize = 0; + + valueSize = getInputValueSize(dataIn, &newVariant); + it_var->setNewValue(newVariant); + + ++it_var; + ++sdIndex; + } + + } + + template + void COpcComLayer::getInputValue(void * pa_pData, Variant * pa_pNewValue){ + T* vData = (T*) pa_pData; + T data = vData[0]; + + pa_pNewValue->set(data); + } + + unsigned int COpcComLayer::getInputValueSize(CIEC_ANY* pa_pData, Variant * pa_pNewValue){ + switch (pa_pData->getDataTypeID()){ + case CIEC_ANY::e_BOOL: + pa_pNewValue->set((bool) *(dynamic_cast(pa_pData))); + return sizeof(bool); + break; + case CIEC_ANY::e_SINT: + pa_pNewValue->set((CHAR) *(dynamic_cast(pa_pData))); + return sizeof(TForteInt8); + break; + case CIEC_ANY::e_INT: { + CIEC_INT* tempInt = dynamic_cast(pa_pData); + TForteInt16 forteInt = (TForteInt16) (*tempInt); + pa_pNewValue->set(forteInt); + return sizeof(TForteInt16); + break; + } + case CIEC_ANY::e_DINT: + pa_pNewValue->set((TForteInt32) *(dynamic_cast(pa_pData))); + return sizeof(TForteInt32); + break; + case CIEC_ANY::e_LINT: + pa_pNewValue->set((TForteInt64) *(dynamic_cast(pa_pData))); + return sizeof(TForteInt64); + break; + case CIEC_ANY::e_USINT: + pa_pNewValue->set((TForteUInt8) *(dynamic_cast(pa_pData))); + return sizeof(TForteUInt8); + break; + case CIEC_ANY::e_UINT: + pa_pNewValue->set((TForteUInt16) *(dynamic_cast(pa_pData))); + return sizeof(TForteUInt16); + break; + case CIEC_ANY::e_UDINT: + pa_pNewValue->set((TForteUInt32) *(dynamic_cast(pa_pData))); + return sizeof(TForteUInt32); + break; + case CIEC_ANY::e_ULINT: + pa_pNewValue->set((TForteUInt64) *(dynamic_cast(pa_pData))); + return sizeof(TForteUInt64); + break; + case CIEC_ANY::e_BYTE: + pa_pNewValue->set((TForteByte) *(dynamic_cast(pa_pData))); + return sizeof(TForteByte); + break; + case CIEC_ANY::e_WORD: + pa_pNewValue->set((TForteWord) *(dynamic_cast(pa_pData))); + return sizeof(TForteWord); + break; + case CIEC_ANY::e_DWORD: + pa_pNewValue->set((TForteDWord) *(dynamic_cast(pa_pData))); + return sizeof(TForteDWord); + break; + case CIEC_ANY::e_LWORD: + pa_pNewValue->set((TForteLWord) *(dynamic_cast(pa_pData))); + return sizeof(TForteLWord); + break; + case CIEC_ANY::e_REAL: + pa_pNewValue->set((TForteFloat) *(dynamic_cast(pa_pData))); + return sizeof(TForteFloat); + break; + case CIEC_ANY::e_LREAL: + pa_pNewValue->set((TForteDFloat) *(dynamic_cast(pa_pData))); + return sizeof(TForteDFloat); + break; + default: + //TODO + break; + } + + return 0; + } diff --git a/src/modules/opc/opccomlayer.h b/src/modules/opc/opccomlayer.h new file mode 100644 index 000000000..9cc2073d3 --- /dev/null +++ b/src/modules/opc/opccomlayer.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2012 -2015 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef OPCCOMLAYER_H_ +#define OPCCOMLAYER_H_ + +#include +#include "comlayer.h" +#include "opcprocessvar.h" + +class CIEC_ANY; +class COpcConnection; +struct Variant; + +namespace forte { + + namespace com_infra { + + class COpcComLayer : public CComLayer{ + public: + COpcComLayer(CComLayer* pa_poUpperLayer, CCommFB* pa_poComFB); + virtual ~COpcComLayer(); + + EComResponse sendData(void *pa_pvData, unsigned int pa_unSize); // top interface, called from top + EComResponse recvData(const void *pa_pvData, unsigned int pa_unSize); + EComResponse processInterrupt(); + + protected: + void closeConnection(); + + private: + EComResponse openConnection(char *pa_acLayerParameter); + int addOpcItems(); + void setOutputValue(CIEC_ANY *pa_pDataOut, Variant * pa_pValue); + void processClientParams(char* pa_acLayerParams); + void convertInputData(void *pa_pData, unsigned int pa_nSize); + + unsigned int getInputValueSize(CIEC_ANY* pa_pData, Variant * pa_pNewValue); + + template + void getInputValue(void * pa_pData, Variant * pa_pNewValue); + + const char* m_acHost; + const char* m_acServerName; + long m_nUpdateRate; + float m_nDeadBand; + const char* m_acOpcGroupName; + + bool m_bLayerParamsOK; + + COpcConnection *m_pOpcConnection; + + typedef CSinglyLinkedList TOpcProcessVarList; + TOpcProcessVarList m_lFBOutputVars; + TOpcProcessVarList m_lFBInputVars; + + EComResponse m_eInterruptResp; + typedef CSinglyLinkedList TComResponseList; + TComResponseList m_lComResponses; + + CSyncObject m_oSync; + }; + + } + +} + +#endif /* OPCCOMLAYER_H_ */ diff --git a/src/modules/opc/opcconnection.cpp b/src/modules/opc/opcconnection.cpp new file mode 100644 index 000000000..b46d4a021 --- /dev/null +++ b/src/modules/opc/opcconnection.cpp @@ -0,0 +1,266 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "opcconnection.h" +#include "opcconnectionimpl.h" +#include "opceventhandler.h" +#include "opcprocessvar.h" +#include "Cmd_AddConnection.h" +#include "Cmd_AddOPCProcessVar.h" +#include "Cmd_SetProcessVarValue.h" + +using namespace forte::com_infra; + +COpcConnection::COpcConnection(const char *pa_acHost, const char *pa_acServerName) : + m_acHost(pa_acHost), m_acServerName(pa_acServerName), m_bIsConnected(false), m_nGroupCount(0), m_eConnectionEvent(e_Disconnected), m_bBlockingConnect(false){ + m_pOpcConnectionImpl = new COpcConnectionImpl(pa_acHost, pa_acServerName, this); +} + +COpcConnection::~COpcConnection(){ + delete m_pOpcConnectionImpl; +} + +void COpcConnection::addGroup(const char* pa_acGroupName, unsigned long pa_nReqUpdateRate, float pa_nDeadBand, CComLayer* pa_pComCallback){ + m_oSync.lock(); + m_lOpcGroupMapList.push_back(new SOpcGroupMap(pa_acGroupName, COpcEventHandler::getInstance().addComCallback(pa_pComCallback))); + m_oSync.unlock(); + + m_pOpcConnectionImpl->addGroup(pa_acGroupName, pa_nReqUpdateRate, pa_nDeadBand); + + m_nGroupCount++; +} + +void COpcConnection::removeGroup(const char* pa_acGroupName){ + m_oSync.lock(); + TOpcGroupMapList::Iterator itDelete = m_lOpcGroupMapList.begin(); + TOpcGroupMapList::Iterator it_group = m_lOpcGroupMapList.begin(); + TOpcGroupMapList::Iterator itEnd_group = m_lOpcGroupMapList.end(); + + if(it_group != itEnd_group){ + if(strcmp(it_group->m_acGroupName, pa_acGroupName) == 0){ + m_lOpcGroupMapList.pop_front(); + m_nGroupCount--; + m_oSync.unlock(); + return; + } + ++it_group; + while(it_group != itEnd_group){ + if(strcmp(it_group->m_acGroupName, pa_acGroupName) == 0){ + m_lOpcGroupMapList.eraseAfter(itDelete); + m_nGroupCount--; + m_oSync.unlock(); + return; + } + + ++itDelete; + ++it_group; + } + } + + m_oSync.unlock(); +} + +int COpcConnection::send_connect(){ + switch (m_eConnectionEvent){ + case e_Disconnected: + m_eConnectionEvent = e_Connecting; + COpcEventHandler::getInstance().sendCommand(new CCmd_AddConnection(m_pOpcConnectionImpl)); + return 0; + case e_Connecting: + return 0; + default: // all other connection states + return 1; + } +} + +int COpcConnection::send_connect(bool pa_bBlocking){ + m_bBlockingConnect = pa_bBlocking; + if(pa_bBlocking && !m_bIsConnected){ + m_pOpcConnectionImpl->connect(); + return 1; + } + + return send_connect(); +} + +int COpcConnection::send_addItem(COpcProcessVar* pa_pNewItem){ + m_oSync.lock(); + TOpcGroupMapList::Iterator itEnd_group = m_lOpcGroupMapList.end(); + for(TOpcGroupMapList::Iterator it_group = m_lOpcGroupMapList.begin(); it_group != itEnd_group; ++it_group){ + if(strcmp(it_group->m_acGroupName, pa_pNewItem->getItemGroupName()) == 0){ + if(pa_pNewItem->getItemFunction() == COpcProcessVar::e_FBOutput){ + + //check if item already added + TItemDataList::Iterator itEnd_item = (*it_group)->m_lReadItemsList.end(); + for(TItemDataList::Iterator it_item = (*it_group)->m_lReadItemsList.begin(); it_item != itEnd_item; ++it_item){ + if(strcmp(it_item->m_acItemName, pa_pNewItem->getItemName()) == 0){ + m_oSync.unlock(); + return 1; + } + } + + it_group->m_lReadItemsList.push_back(new SOpcItemData(pa_pNewItem->getItemName())); + break; + + } + else if(pa_pNewItem->getItemFunction() == COpcProcessVar::e_FBInput){ + //check if item already added + TItemDataList::Iterator itEnd_item = (*it_group)->m_lWriteItemsList.end(); + for(TItemDataList::Iterator it_item = (*it_group)->m_lWriteItemsList.begin(); it_item != itEnd_item; ++it_item){ + if(strcmp(it_item->m_acItemName, pa_pNewItem->getItemName()) == 0){ + m_oSync.unlock(); + return 1; + } + } + + it_group->m_lWriteItemsList.push_back(new SOpcItemData(pa_pNewItem->getItemName())); + break; + + } + } + } + m_oSync.unlock(); + + if(m_eConnectionEvent == e_Connected){ + COpcEventHandler::getInstance().sendCommand(new CCmd_AddOPCProcessVar(m_pOpcConnectionImpl, pa_pNewItem)); + + return 0; + } + + return -1; +} + +int COpcConnection::send_sendItemData(COpcProcessVar* pa_pItem){ + if (pa_pItem->getIsActive()) + COpcEventHandler::getInstance().sendCommand(new CCmd_SetProcessVarValue(pa_pItem)); + + return 0; +} + +void COpcConnection::response_connect(bool pa_bConnectionState){ + m_bIsConnected = pa_bConnectionState; + if(pa_bConnectionState) + m_eConnectionEvent = e_Connected; + else + m_eConnectionEvent = e_ConnectionFailed; + //m_eConnectionEvent = e_Disconnected; + + if(!m_bBlockingConnect){ + m_oSync.lock(); + + TOpcGroupMapList::Iterator itEnd = m_lOpcGroupMapList.end(); + for(TOpcGroupMapList::Iterator it = m_lOpcGroupMapList.begin(); it != itEnd; ++it){ + COpcEventHandler::getInstance().executeComCallback((*it)->m_nCallbackDesc); + } + + m_oSync.unlock(); + } +} + +void COpcConnection::response_dataReceived(const char *pa_acGroupName, TItemDataList & pa_lItemDataList){ + // Loop through OpcGroups + m_oSync.lock(); + TOpcGroupMapList::Iterator itEnd_group = m_lOpcGroupMapList.end(); + for(TOpcGroupMapList::Iterator it_group = m_lOpcGroupMapList.begin(); it_group != itEnd_group; ++it_group){ + + if(strcmp(it_group->m_acGroupName, pa_acGroupName) == 0){ + + // Loop through OpcItems in OpcGroup + TItemDataList::Iterator itEnd_item = (*it_group)->m_lReadItemsList.end(); + for(TItemDataList::Iterator it_item = (*it_group)->m_lReadItemsList.begin(); it_item != itEnd_item; ++it_item){ + + // Loop through OpcItems in ItemDataList + TItemDataList::Iterator itEnd_newItem = pa_lItemDataList.end(); + TItemDataList::Iterator itErase = pa_lItemDataList.begin(); + for(TItemDataList::Iterator it_newItem = pa_lItemDataList.begin(); it_newItem != itEnd_newItem; ++it_newItem){ + + if(strcmp(it_newItem->m_acItemName, it_item->m_acItemName) == 0){ + it_item->m_oItemData = it_newItem->m_oItemData; + + if(it_newItem == pa_lItemDataList.begin()) + pa_lItemDataList.pop_front(); + else + pa_lItemDataList.eraseAfter(itErase); + + break; + } + + if(it_newItem != pa_lItemDataList.begin()) + ++itErase; + } + if(pa_lItemDataList.isEmpty()) + break; + } + + // Change state + m_eConnectionEvent = e_DataReceived; + + // Notify Com Layer + COpcEventHandler::getInstance().executeComCallback(it_group->m_nCallbackDesc); + break; + } + } + m_oSync.unlock(); +} + +void COpcConnection::response_itemAdded(COpcProcessVar* pa_pOpcItem){ + // Loop through OpcGroups + m_oSync.lock(); + TOpcGroupMapList::Iterator itEnd_group = m_lOpcGroupMapList.end(); + for(TOpcGroupMapList::Iterator it_group = m_lOpcGroupMapList.begin(); it_group != itEnd_group; ++it_group){ + if(strcmp(it_group->m_acGroupName, pa_pOpcItem->getItemGroupName()) == 0){ + // Change state + if (pa_pOpcItem->getIsActive()) + m_eConnectionEvent = e_ItemAddedOk; + else + m_eConnectionEvent = e_ItemAddedFailed; + + // Notify Com Layer + COpcEventHandler::getInstance().executeComCallback(it_group->m_nCallbackDesc); + break; + } + } + m_oSync.unlock(); +} + +int COpcConnection::receiveData(const char* pa_acGroupName, TOpcProcessVarList * pa_lOpcProcessVarList){ + int nrData = 0; + // TODO Case when lists do not match in size + + m_oSync.lock(); + TOpcGroupMapList::Iterator itEnd_group = m_lOpcGroupMapList.end(); + for(TOpcGroupMapList::Iterator it_group = m_lOpcGroupMapList.begin(); it_group != itEnd_group; ++it_group){ + + if(strcmp(it_group->m_acGroupName, pa_acGroupName) == 0){ + + TItemDataList::Iterator itEnd_item = it_group->m_lReadItemsList.end(); + TItemDataList::Iterator it_item = it_group->m_lReadItemsList.begin(); + + TOpcProcessVarList::Iterator itEnd_procVar = pa_lOpcProcessVarList->end(); + TOpcProcessVarList::Iterator it_procVar = pa_lOpcProcessVarList->begin(); + + while(it_procVar != itEnd_procVar && it_item != itEnd_item){ + + it_procVar->setNewValue(it_item->m_oItemData); + + nrData++; + + ++it_procVar; + ++it_item; + } + + break; + } + + } + m_oSync.unlock(); + return nrData; +} + diff --git a/src/modules/opc/opcconnection.h b/src/modules/opc/opcconnection.h new file mode 100644 index 000000000..0c9e99120 --- /dev/null +++ b/src/modules/opc/opcconnection.h @@ -0,0 +1,125 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef OPCCONNECTION_H_ +#define OPCCONNECTION_H_ + +#include "comlayer.h" +#include "fortelist.h" +#include "sync.h" +#include "windows.h" +#include "Variant.h" + +class COpcConnectionImpl; +class COpcProcessVar; + +struct SOpcItemData{ + const char* m_acItemName; + Variant m_oItemData; + + SOpcItemData(const char* pa_acItemName) : + m_acItemName(pa_acItemName){ + m_oItemData.set(0); + } + SOpcItemData(const char* pa_acItemName, Variant pa_oItemData) : + m_acItemName(pa_acItemName), m_oItemData(pa_oItemData){ + } +}; +typedef CSinglyLinkedList TItemDataList; + +class COpcConnection{ + public: + + COpcConnection(const char *pa_acHost, const char *pa_acServerName); + ~COpcConnection(); + + /*** Functions for OpcConnectionHandler ****************************************/ + void addGroup(const char* pa_acGroupName, unsigned long pa_nReqUpdateRate, float pa_nDeadBand, forte::com_infra::CComLayer* pa_pComCallback); + void removeGroup(const char* pa_acGroupName); + /*** END ***********************************************************************/ + + /*** Functions for OpcComLayer *************************************************/ + int send_connect(); + int send_connect(bool pa_bBlocking); + int send_addItem(COpcProcessVar* pa_pNewItem); + int send_sendItemData(COpcProcessVar* pa_pItem); + + typedef CSinglyLinkedList TOpcProcessVarList; + int receiveData(const char* pa_acGroupName, TOpcProcessVarList * pa_lOpcProcessVarList); + + bool isConnected() const { + return m_bIsConnected; + } + /*** END ***********************************************************************/ + + /*** Functions for OpcConnectionImpl *******************************************/ + void response_connect(bool pa_bConnectionState); + void response_dataReceived(const char *pa_acGroupName, TItemDataList & pa_lItemDataList); + void response_itemAdded(COpcProcessVar* pa_pOpcItem); + /*** END ***********************************************************************/ + + /*** Common Functions **********************************************************/ + enum EOpcConnectionEvents{ + e_Disconnected, e_Connecting, e_ConnectionFailed, e_Connected, e_ItemAddedOk, e_ItemAddedFailed, e_DataReceived + }; + + const char* getHost() const { + return m_acHost; + } + + const char* getServerName() const { + return m_acServerName; + } + + unsigned int getGroupCount() const { + return m_nGroupCount; + } + + EOpcConnectionEvents getConnectionState() const { + return m_eConnectionEvent; + } + + /*** END ***********************************************************************/ + + private: + struct SOpcGroupMap{ + const char* m_acGroupName; + int m_nCallbackDesc; + TItemDataList m_lReadItemsList; + TItemDataList m_lWriteItemsList; + + SOpcGroupMap(const char* pa_acGroupName, int pa_nCallbackDesc) : + m_acGroupName(pa_acGroupName), m_nCallbackDesc(pa_nCallbackDesc){ + } + }; + + typedef CSinglyLinkedList TOpcGroupMapList; + TOpcGroupMapList m_lOpcGroupMapList; + + unsigned int m_nGroupCount; + + COpcConnectionImpl *m_pOpcConnectionImpl; + + EOpcConnectionEvents m_eConnectionEvent; + + const char* m_acHost; + const char* m_acServerName; + const char* m_acGroupName; + unsigned long m_nReqUpdateRate; + unsigned long m_nRealUpdateRate; + float m_nDeadBand; + + bool m_bIsConnected; + bool m_bBlockingConnect; + + CSyncObject m_oSync; +}; + +#endif // OPCCONNECTION_H_ diff --git a/src/modules/opc/opcconnectionhandler.cpp b/src/modules/opc/opcconnectionhandler.cpp new file mode 100644 index 000000000..a35b54773 --- /dev/null +++ b/src/modules/opc/opcconnectionhandler.cpp @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "opcconnectionhandler.h" +#include "opcconnection.h" + +using namespace forte::com_infra; + +DEFINE_SINGLETON(COpcConnectionHandler); + +COpcConnectionHandler::COpcConnectionHandler(){ + +} + +COpcConnectionHandler::~COpcConnectionHandler(){ + TOpcConnectionList::Iterator itEnd = m_lOpcConnectionList.end(); + for(TOpcConnectionList::Iterator it = m_lOpcConnectionList.begin(); it != itEnd; ++it){ + delete (*it); + } +} + +COpcConnection* COpcConnectionHandler::getOpcConnection(const char *pa_acHost, const char *pa_acServerName, const char* pa_acGroupName, unsigned long pa_nReqUpdateRate, float pa_nDeadBand, CComLayer* pa_pComCallback){ + + COpcConnection *newConnection = findOpcConnection(pa_acHost, pa_acServerName); + if(newConnection == NULL){ + newConnection = new COpcConnection(pa_acHost, pa_acServerName); + + m_lOpcConnectionList.push_back(newConnection); + } + + newConnection->addGroup(pa_acGroupName, pa_nReqUpdateRate, pa_nDeadBand, pa_pComCallback); + + return newConnection; +} + +void COpcConnectionHandler::removeOpcConnection(const char *pa_acHost, const char *pa_acServerName, const char* pa_acGroupName){ + COpcConnection *existingCon = findOpcConnection(pa_acHost, pa_acServerName); + if(existingCon != NULL){ + existingCon->removeGroup(pa_acGroupName); + + if(existingCon->getGroupCount() == 0) + deleteOpcConnection(pa_acHost, pa_acServerName); + } +} + +COpcConnection* COpcConnectionHandler::findOpcConnection(const char* pa_acHost, const char* pa_acServerName){ + TOpcConnectionList::Iterator itEnd = m_lOpcConnectionList.end(); + for(TOpcConnectionList::Iterator it = m_lOpcConnectionList.begin(); it != itEnd; ++it){ + if(strcmp(it->getHost(), pa_acHost) == 0 && strcmp(it->getServerName(), pa_acServerName) == 0) + return (*it); + } + + return NULL; +} + +void COpcConnectionHandler::deleteOpcConnection(const char* pa_acHost, const char* pa_acServerName){ + TOpcConnectionList::Iterator itDelete = m_lOpcConnectionList.begin(); + TOpcConnectionList::Iterator it = m_lOpcConnectionList.begin(); + TOpcConnectionList::Iterator itEnd = m_lOpcConnectionList.end(); + + if(it != itEnd){ + if(strcmp(it->getHost(), pa_acHost) == 0 && strcmp(it->getServerName(), pa_acServerName)){ + m_lOpcConnectionList.pop_front(); + return; + } + ++it; + while(it != itEnd){ + if(strcmp(it->getHost(), pa_acHost) == 0 && strcmp(it->getServerName(), pa_acServerName)){ + m_lOpcConnectionList.eraseAfter(itDelete); + return; + } + + ++itDelete; + ++it; + } + } +} diff --git a/src/modules/opc/opcconnectionhandler.h b/src/modules/opc/opcconnectionhandler.h new file mode 100644 index 000000000..060d5e244 --- /dev/null +++ b/src/modules/opc/opcconnectionhandler.h @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2012 -2014 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef OPCCONNECTIONHANDLER_H_ +#define OPCCONNECTIONHANDLER_H_ + +#include "singlet.h" +#include "fortelist.h" +#include +#include + +class COpcConnection; + +class COpcConnectionHandler{ + DECLARE_SINGLETON(COpcConnectionHandler) + ; + public: + /*! \brief returns existing or creates new OpcConnection + * + * If a connection to the specified server already exist a pointer to this is returned. Otherwise a + * new connection is created. The returned connection includes the group with the specified settings. + */ + COpcConnection* getOpcConnection(const char *pa_acHost, const char *pa_acServerName, const char* pa_acGroupName, unsigned long pa_nReqUpdateRate, float pa_nDeadBand, forte::com_infra::CComLayer* pa_pComCallback); + + void removeOpcConnection(const char *pa_acHost, const char *pa_acServerName, const char* pa_acGroupName); + + private: + COpcConnection* findOpcConnection(const char* pa_acHost, const char* pa_acServerName); + void deleteOpcConnection(const char* pa_acHost, const char* pa_acServerName); + + typedef CSinglyLinkedList TOpcConnectionList; + TOpcConnectionList m_lOpcConnectionList; + +}; + +#endif // OPCCONNECTIONHANDLER_H_ diff --git a/src/modules/opc/opcconnectionimpl.cpp b/src/modules/opc/opcconnectionimpl.cpp new file mode 100644 index 000000000..e4d28fe4a --- /dev/null +++ b/src/modules/opc/opcconnectionimpl.cpp @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "opcconnectionimpl.h" + +#include "opceventhandler.h" +#include "opcconnection.h" +#include "opcprocessvar.h" + +#include "OPCClient.h" +#include "OPCHost.h" +#include "OPCServer.h" +#include "OPCGroup.h" +#include "OPCItem.h" + +COpcConnectionImpl::COpcConnectionImpl(const char *pa_acHost, const char *pa_acServerName, COpcConnection* pa_pOpcConn) : + m_acHost(pa_acHost), m_acServerName(pa_acServerName), m_pOpcConn(pa_pOpcConn){ +} + +COpcConnectionImpl::~COpcConnectionImpl(){ +} + +void COpcConnectionImpl::connect(){ + try{ + + COPCClient::init(); + + m_pOpcHost = COPCClient::makeHost(m_acHost); + + m_pOpcServer = m_pOpcHost->connectDAServer(m_acServerName); + } catch (OPCException e){ + m_pOpcConn->response_connect(false); + return; + } + + m_pOpcConn->response_connect(true); +} + +void COpcConnectionImpl::addItem(COpcProcessVar* pa_pNewItem){ + COPCGroup* itemGroup = getOpcGroup(pa_pNewItem->getItemGroupName(), pa_pNewItem->getItemFunction()); + + ATL::CString itemName(pa_pNewItem->getItemName()); + try{ + COPCItem* newItem = itemGroup->addItem(itemName, true); + pa_pNewItem->setOpcItem(newItem); + pa_pNewItem->setIsActive(true); + } catch (OPCException e){ + pa_pNewItem->setIsActive(false); + } + m_pOpcConn->response_itemAdded(pa_pNewItem); +} + +void COpcConnectionImpl::addGroup(const char* pa_acGroupName, unsigned long pa_nReqUpdateRate, float pa_nDeadBand){ + m_lOpcGroupSettingsList.push_back(new SOpcGroupSettings(pa_acGroupName, pa_nReqUpdateRate, pa_nDeadBand)); +} + +int COpcConnectionImpl::sendItemData(COpcProcessVar* pa_pNewItem){ + return 0; +} + +void COpcConnectionImpl::OnDataChange(COPCGroup & group, CAtlMap & changes){ + + TItemDataList itemList; + for(POSITION pos = changes.GetStartPosition(); pos != NULL;){ + OPCItemData *itemData = changes.GetValueAt(pos); + COPCItem *item = changes.GetNextKey(pos); + + itemList.push_back(new SOpcItemData((LPCTSTR) (item->getName()), itemData->vDataValue)); + } + + const char *c_groupName = (const char*) group.getName(); + + int position = 0; + const char * subStrRead = strstr(c_groupName, "_read"); + if(subStrRead != NULL) + position = subStrRead - c_groupName; + else{ + //TODO Should not happen error + } + + char * groupName = (char*) malloc(position + 1); + strncpy(groupName, c_groupName, position); + groupName[position] = '\0'; + + m_pOpcConn->response_dataReceived(groupName, itemList); + + free(groupName); +} + +COPCGroup* COpcConnectionImpl::getOpcGroup(const char* pa_acGroupName, COpcProcessVar::EOpcProcessVarFunctions pa_eFunction){ + COPCGroup *retGroup = NULL; + + TOpcGroupSettingsList::Iterator itEnd = m_lOpcGroupSettingsList.end(); + for(TOpcGroupSettingsList::Iterator it = m_lOpcGroupSettingsList.begin(); it != itEnd; ++it){ + if(strcmp(it->m_acGroupName, pa_acGroupName) == 0){ + if(pa_eFunction == COpcProcessVar::e_FBOutput){ + if(!(it->m_bReadGroupAdded)){ + char *groupName = (char*) malloc(strlen(pa_acGroupName) + 5 + 1); + strcpy(groupName, pa_acGroupName); + strcat(groupName, "_read"); + try{ + it->m_pOpcGroupRead = retGroup = m_pOpcServer->makeGroup(groupName, true, it->m_nReqUpdateRate, it->m_nRevisedUpdateRate, it->m_nDeadBand); + it->m_pOpcGroupRead->enableAsynch(*this); + it->m_bReadGroupAdded = true; + } catch (OPCException e){ + // TODO + } + free(groupName); + } + else + retGroup = it->m_pOpcGroupRead; + } + else if(pa_eFunction == COpcProcessVar::e_FBInput){ + if(!(it->m_bWriteGroupAdded)){ + char *groupName = (char*) malloc(strlen(pa_acGroupName) + 6 + 1); + strcpy(groupName, pa_acGroupName); + strcat(groupName, "_write"); + try{ + it->m_pOpcGroupWrite = retGroup = m_pOpcServer->makeGroup(groupName, true, it->m_nReqUpdateRate, it->m_nRevisedUpdateRate, it->m_nDeadBand); + it->m_bWriteGroupAdded = true; + } catch (OPCException e){ + // TODO + } + free(groupName); + } + else + retGroup = it->m_pOpcGroupWrite; + } + + break; + } + } + + return retGroup; +} diff --git a/src/modules/opc/opcconnectionimpl.h b/src/modules/opc/opcconnectionimpl.h new file mode 100644 index 000000000..5b458282b --- /dev/null +++ b/src/modules/opc/opcconnectionimpl.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2012, 2015 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef OPCCONNECTIONIMPL_H_ +#define OPCCONNECTIONIMPL_H_ + +#include "fortelist.h" + +#include "opcprocessvar.h" + +// Includes from OPC library +#include "windows.h" +#include "opcda.h" +#include "OPCClient.h" + +class COpcConnection; + +class COpcConnectionImpl : public IAsynchDataCallback{ + public: + COpcConnectionImpl(const char *pa_acHost, const char *pa_acServerName, COpcConnection* pa_pOpcConn); + ~COpcConnectionImpl(); + + void connect(); + void addItem(COpcProcessVar* pa_pNewItem); + void addGroup(const char* pa_acGroupName, unsigned long pa_nReqUpdateRate, float pa_nDeadBand); + + int sendItemData(COpcProcessVar* pa_pNewItem); + int receiveData(const char* pa_acRecvBuffer); + + const char* getHost(){ + return m_acHost; + } + const char* getServerName(){ + return m_acServerName; + } + + virtual void OnDataChange(COPCGroup & group, CAtlMap & changes); + + private: + COPCGroup* getOpcGroup(const char *pa_acGroupName, COpcProcessVar::EOpcProcessVarFunctions pa_eFunction); + + struct SOpcGroupSettings{ + COPCGroup* m_pOpcGroupRead; + COPCGroup* m_pOpcGroupWrite; + const char* m_acGroupName; + unsigned long m_nReqUpdateRate; + unsigned long m_nRevisedUpdateRate; + float m_nDeadBand; + bool m_bReadGroupAdded; + bool m_bWriteGroupAdded; + + SOpcGroupSettings(const char* pa_acGroupName, unsigned long pa_nReqUpdateRate, float pa_nDeadBand) : + m_acGroupName(pa_acGroupName), m_nReqUpdateRate(pa_nReqUpdateRate), m_nDeadBand(pa_nDeadBand), m_bReadGroupAdded(false), m_bWriteGroupAdded(false){ + } + }; + + typedef CSinglyLinkedList TOpcGroupSettingsList; + TOpcGroupSettingsList m_lOpcGroupSettingsList; + + COpcConnection* m_pOpcConn; + + COPCHost* m_pOpcHost; + COPCServer *m_pOpcServer; + + const char* m_acHost; + const char* m_acServerName; + const char* m_acGroupName; + unsigned long m_nReqUpdateRate; + unsigned long m_nRealUpdateRate; + float m_nDeadBand; +}; + +#endif // OPCCONNECTIONIMPL_H_ diff --git a/src/modules/opc/opceventhandler.cpp b/src/modules/opc/opceventhandler.cpp new file mode 100644 index 000000000..8abe7a90a --- /dev/null +++ b/src/modules/opc/opceventhandler.cpp @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2014 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "opceventhandler.h" +#include "../core/devexec.h" +#include "devlog.h" +#include + +#include + +DEFINE_SINGLETON(COpcEventHandler); + +COpcEventHandler::TCallbackDescriptor COpcEventHandler::m_nCallbackDescCount = 0; + +COpcEventHandler::COpcEventHandler(){ + this->start(); + // Sleep to allow new thread to start + Sleep(100); +} + +COpcEventHandler::~COpcEventHandler(){ + this->end(); +} + +void COpcEventHandler::sendCommand(ICmd *pa_pCmd){ + m_oSync.lock(); + m_lCommandQueue.push_back(pa_pCmd); + m_oSync.unlock(); +} + +void COpcEventHandler::run(){ + HRESULT result = CoInitializeEx(NULL, COINIT_MULTITHREADED); + + if(result == S_OK){ + while(isAlive()){ + ICmd* nextCommand = getNextCommand(); + if(nextCommand != NULL) + nextCommand->runCommand(); + + MSG msg; + while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){ + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + + CoUninitialize(); +} + +COpcEventHandler::TCallbackDescriptor COpcEventHandler::addComCallback(forte::com_infra::CComLayer* pa_pComCallback){ + m_oSync.lock(); + m_nCallbackDescCount++; + TComContainer stNewNode = { m_nCallbackDescCount, pa_pComCallback }; + m_lstComCallbacks.push_back(stNewNode); + m_oSync.unlock(); + + return m_nCallbackDescCount; +} + +void COpcEventHandler::removeComCallback(COpcEventHandler::TCallbackDescriptor pa_nCallbackDesc){ + m_oSync.lock(); + + TCallbackList::Iterator itRunner(m_lstComCallbacks.begin()); + + if(itRunner->m_nCallbackDesc == pa_nCallbackDesc){ + m_lstComCallbacks.pop_front(); + } + else{ + TCallbackList::Iterator itLastPos(itRunner); + TCallbackList::Iterator itEnd(m_lstComCallbacks.end()); + ++itRunner; + while(itRunner != itEnd){ + if(itRunner->m_nCallbackDesc == pa_nCallbackDesc){ + m_lstComCallbacks.eraseAfter(itLastPos); + break; + } + itLastPos = itRunner; + ++itRunner; + } + } + m_oSync.unlock(); +} + +void COpcEventHandler::executeComCallback(COpcEventHandler::TCallbackDescriptor pa_nCallbackDesc){ + m_oSync.lock(); + TCallbackList::Iterator itEnd(m_lstComCallbacks.end()); + for(TCallbackList::Iterator itCallback = m_lstComCallbacks.begin(); itCallback != itEnd; ++itCallback){ + if(itCallback->m_nCallbackDesc == pa_nCallbackDesc){ + //FIX + TComContainer comCon = (*itCallback); + m_oSync.unlock(); + if(forte::com_infra::e_Nothing != comCon.m_pCallback->recvData(0,0)){ + startNewEventChain(comCon.m_pCallback->getCommFB()); + } + m_oSync.lock(); + break; + } + } + m_oSync.unlock(); +} + +ICmd* COpcEventHandler::getNextCommand(){ + ICmd* command; + + m_oSync.lock(); + TCommandQueue::Iterator itBegin = m_lCommandQueue.begin(); + if(itBegin != m_lCommandQueue.end()){ + command = (*itBegin); + m_lCommandQueue.pop_front(); + } + else + command = NULL; + m_oSync.unlock(); + + return command; +} diff --git a/src/modules/opc/opceventhandler.h b/src/modules/opc/opceventhandler.h new file mode 100644 index 000000000..ef5b9bedb --- /dev/null +++ b/src/modules/opc/opceventhandler.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2012, 2015 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef OPCEVENTHANDLER_H_ +#define OPCEVENTHANDLER_H_ + +#include "extevhan.h" +#include "thread.h" +#include "singlet.h" +#include "fortelist.h" +#include "sync.h" +#include "comlayer.h" + +#include "ICmd.h" + +class COpcEventHandler : public CExternalEventHandler, private CThread{ + DECLARE_SINGLETON(COpcEventHandler) + ; + public: + typedef int TCallbackDescriptor; + + void sendCommand(ICmd *pa_pCmd); + + TCallbackDescriptor addComCallback(forte::com_infra::CComLayer* pa_pComCallback); + void removeComCallback(TCallbackDescriptor pa_nCallbackDesc); + + void executeComCallback(TCallbackDescriptor pa_nCallbackDesc); + + /* functions needed for the external event handler interface */ + void enableHandler(void){ + start(); + } + + void disableHandler(void){ + end(); + } + + void setPriority(int){ + //currently we are doing nothing here. + //TODO We should adjust the thread priority. + } + + int getPriority(void) const{ + //the same as for setPriority + return 0; + } + + protected: + virtual void run(void); + + private: + ICmd* getNextCommand(); + + struct TComContainer{ + TCallbackDescriptor m_nCallbackDesc; + forte::com_infra::CComLayer* m_pCallback; + }; + + typedef CSinglyLinkedList TCallbackList; + TCallbackList m_lstComCallbacks; + + static TCallbackDescriptor m_nCallbackDescCount; + + CSyncObject m_oSync; + + typedef CSinglyLinkedList TCommandQueue; + TCommandQueue m_lCommandQueue; +}; + +#endif // OPCEVENTHANDLER_H_ diff --git a/src/modules/opc/opcprocessvar.cpp b/src/modules/opc/opcprocessvar.cpp new file mode 100644 index 000000000..9f4f7449f --- /dev/null +++ b/src/modules/opc/opcprocessvar.cpp @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "opcprocessvar.h" +#include "OPCGroup.h" +#include "OPCItem.h" + +COpcProcessVar::COpcProcessVar(const char* pa_acItemGroupName, const char* pa_acItemName, EOpcProcessVarFunctions pa_eFunction) : + m_acItemGroupName(pa_acItemGroupName), m_acItemName(pa_acItemName), m_eFunction(pa_eFunction), m_bActive(false){ + m_oCurrentValue.set(0); +} + +void COpcProcessVar::sendItemData(){ + try{ + if (getIsActive()) + m_pOpcItem->writeSync(updateValue()); + } catch (OPCException e){ + setIsActive(false); + } +} + +void COpcProcessVar::setNewValue(Variant pa_oNewValue){ + m_oSync.lock(); + m_lNewValueQueue.push_back(pa_oNewValue); + m_oSync.unlock(); +} + +Variant COpcProcessVar::peekNewValue(){ + Variant retVal; + + m_oSync.lock(); + TVariantList::Iterator itBegin = m_lNewValueQueue.begin(); + if(itBegin != m_lNewValueQueue.end()){ + retVal = (*itBegin); + } + else + retVal = m_oCurrentValue; + + m_oSync.unlock(); + + return retVal; +} + +Variant COpcProcessVar::updateValue(){ + Variant retVal; + + m_oSync.lock(); + TVariantList::Iterator itBegin = m_lNewValueQueue.begin(); + TVariantList::Iterator itEnd = m_lNewValueQueue.end(); + if(itBegin != m_lNewValueQueue.end()){ + m_oCurrentValue = retVal = (*itBegin); + m_lNewValueQueue.pop_front(); + } + else + retVal = m_oCurrentValue; + + m_oSync.unlock(); + + return retVal; +} diff --git a/src/modules/opc/opcprocessvar.h b/src/modules/opc/opcprocessvar.h new file mode 100644 index 000000000..d9ff7e6c6 --- /dev/null +++ b/src/modules/opc/opcprocessvar.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef OPCPROCESSVAR_H_ +#define OPCPROCESSVAR_H_ + +#include "windows.h" +#include "Variant.h" +#include "fortelist.h" +#include "sync.h" + +class COPCItem; + +class COpcProcessVar{ + public: + enum EOpcProcessVarFunctions{ + e_FBInput, e_FBOutput + }; + + COpcProcessVar(const char* pa_acItemGroupName, const char* pa_acItemName, EOpcProcessVarFunctions pa_eFunction); + ~COpcProcessVar(){ + } + + const char* getItemName() const { + return m_acItemName; + } + const char* getItemGroupName() const { + return m_acItemGroupName; + } + EOpcProcessVarFunctions getItemFunction() const { + return m_eFunction; + } + + void setOpcItem(COPCItem* pa_pOpcItem){ + m_pOpcItem = pa_pOpcItem; + } + + void sendItemData(); + + void setNewValue(Variant pa_oNewValue); + Variant peekNewValue(); + + Variant updateValue(); + + bool getIsActive() const { + return m_bActive; + } + + void setIsActive(bool pa_bActive){ + m_bActive = pa_bActive; + } + + private: + COPCItem* m_pOpcItem; + + const char* m_acItemGroupName; + const char* m_acItemName; + bool m_bActive; + + Variant m_oCurrentValue; + + typedef CSinglyLinkedList TVariantList; + TVariantList m_lNewValueQueue; + + Variant m_oNewValue; + + CSyncObject m_oSync; + + EOpcProcessVarFunctions m_eFunction; + +}; + +#endif // OPCPROCESSVAR_H_ diff --git a/src/modules/opc/readme.txt b/src/modules/opc/readme.txt new file mode 100644 index 000000000..6053bd5c8 --- /dev/null +++ b/src/modules/opc/readme.txt @@ -0,0 +1,55 @@ +Installation Instructions +The OPC com layer requires the following packages + - OPC Client library release 0.4 (http://sourceforge.net/projects/opcclient/) + - Boost Lexical Cast (http://www.boost.org) + +Before OPC Client is compiled the function init() in OPCClient.cpp must be changed from: +void COPCClient::init() +{ + HRESULT result = CoInitialize(NULL); + if (FAILED(result)) + { + throw OPCException("CoInitialize failed"); + } + + CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); + + result = CoGetMalloc(MEMCTX_TASK, &iMalloc); + if (FAILED(result)) + { + throw OPCException("CoGetMalloc failed"); + } +} + +to: +void COPCClient::init() +{ + CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); + + HRESULT result = CoGetMalloc(MEMCTX_TASK, &iMalloc); + if (FAILED(result)) + { + throw OPCException("CoGetMalloc failed"); + } +} + + +Once the OPC Client library is compiled performe the steps below: +1. Place OPC Client library in the following folder structure: + /include - all headers should be placed here + /lib - OPCClientToolkit.lib +2. Choose for FORTE_COM_OPC_LIB_ROOT in CMake +3. Choose Boost root folder for FORTE_COM_OPC_BOOST_ROOT + (the lexical_cast.hpp header must be available in /boost) + +Parameter Documentation (all values are required) +OPC Client +opc[host:serverName:updateRate:deadBand:fbInputItems:fbOutputItems] + - host: 127.0.0.1 etc + - serverName: e.g. Matrikon.OPC.Simulation + - updateRate: update frequency in milliseconds + - deadBand: dead band used for update (same unit as value) + - fbInputItems/fbOutputItems: items to be added, items should be separated with a comma i.e. + Random.Int2,Bucket Brigade.Int4 + +example: opc[127.0.0.1:Matrikon.OPC.Simulation:2000:0.01:Bucket Brigade.Int4:Random.Int2,Bucket Brigade.Int4] diff --git a/src/modules/powerlink/CMakeLists.txt b/src/modules/powerlink/CMakeLists.txt new file mode 100644 index 000000000..ec59eef81 --- /dev/null +++ b/src/modules/powerlink/CMakeLists.txt @@ -0,0 +1,81 @@ +#******************************************************************************* +# * Copyright (c) 2012 - 2014 AIT, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +forte_add_module(POWERLINK "openPOWERLINK Service Interface Function Blocks") + +############################################################################# +# COM Service Interface Function Blocks +############################################################################# + +if("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + forte_add_sourcefile_cpp(EplWrapper.cpp) + forte_add_definition( -D_CONSOLE -DWPCAP ) + + forte_add_include_directories(${FORTE_MODULE_POWERLINK_LIB_DIR}/Target/X86/Windows/WpdPack/Include) + + forte_add_link_directories(${FORTE_MODULE_POWERLINK_LIB_DIR}/Target/X86/Windows/WpdPack/Lib) + + forte_add_sourcefile_with_path_cpp(${FORTE_MODULE_POWERLINK_LIB_DIR}/EplStack/trace.c) + + forte_add_link_library(openPOWERLINK.lib) + forte_add_link_library(wpcap.lib) + forte_add_link_library(iphlpapi.lib) + +elseif("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + forte_add_sourcefile_cpp(EplWrapper.cpp) + forte_add_link_library(-lpowerlink -lpcap -lrt) +else() + MESSAGE("openPOWERLINK is only supported for FORTE on Windows and Linux platforms. Disabled Module!") + set(FORTE_MODULE_POWERLINK OFF) +endif() + +if(FORTE_MODULE_POWERLINK) + SET(FORTE_MODULE_POWERLINK_LIB_DIR "" CACHE PATH "Path to openPOWERLINK-V1.08.1 directory") + SET(FORTE_MODULE_POWERLINK_TINYXML_DIR "" CACHE PATH "Path to TinyXML directory") + + forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + forte_add_sourcefile_hcpp( POWERLINK_MN + X20DO9321 + X20DO9322 + X20DI4653 + X20DI9371 + X20DI9372 + X20AI4622 + X20AO4622 + X20AT2402 + X20AT4222 + X20DO4649 + X20DO4623 + EplXmlReader + ModuleList + ProcessImageMatrix ) + + forte_add_sourcefile_h( EplWrapper.h ) + + forte_add_link_directories(${FORTE_MODULE_POWERLINK_LIB_DIR}) + + forte_add_include_directories(${FORTE_MODULE_POWERLINK_LIB_DIR}/Include) + forte_add_include_directories(${FORTE_MODULE_POWERLINK_LIB_DIR}/SharedBuff) + forte_add_include_directories(${FORTE_MODULE_POWERLINK_LIB_DIR}/ObjDicts/CiA302-4_MN) + forte_add_include_directories(${FORTE_MODULE_POWERLINK_LIB_DIR}/Examples/X86/Generic/powerlink_user_lib) + forte_add_sourcefile_with_path_cpp(${FORTE_MODULE_POWERLINK_LIB_DIR}/ObjDicts/CiA302-4_MN/EplApiProcessImageSetup.c) + forte_add_sourcefile_with_path_cpp(${FORTE_MODULE_POWERLINK_LIB_DIR}/EplStack/EplTgtConio.c) + + forte_add_include_directories(${FORTE_MODULE_POWERLINK_TINYXML_DIR}) + forte_add_sourcefile_with_path_hcpp( ${FORTE_MODULE_POWERLINK_TINYXML_DIR}/tinystr + ${FORTE_MODULE_POWERLINK_TINYXML_DIR}/tinyxml ) + + forte_add_sourcefile_with_path_cpp( ${FORTE_MODULE_POWERLINK_TINYXML_DIR}/tinyxmlerror.cpp + ${FORTE_MODULE_POWERLINK_TINYXML_DIR}/tinyxmlparser.cpp ) + + forte_add_definition( -DCONFIG_POWERLINK_USERSTACK ) +endif(FORTE_MODULE_POWERLINK) diff --git a/src/modules/powerlink/EplCNCallback.h b/src/modules/powerlink/EplCNCallback.h new file mode 100644 index 000000000..5c00c6ae8 --- /dev/null +++ b/src/modules/powerlink/EplCNCallback.h @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EPLCNCALLBACK_H_ +#define _EPLCNCALLBACK_H_ + +class IEplCNCallback{ + public: + + virtual void cnSynchCallback() = 0; + + protected: + virtual ~IEplCNCallback(){ + } + ; + +}; + +#endif //_EPLCNCALLBACK_H_ diff --git a/src/modules/powerlink/EplWrapper.cpp b/src/modules/powerlink/EplWrapper.cpp new file mode 100644 index 000000000..7922117bb --- /dev/null +++ b/src/modules/powerlink/EplWrapper.cpp @@ -0,0 +1,1091 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2014 AIT, ACIN, fortiss + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl, Ewald Weinhandl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" +#include "EplXmlReader.h" + +#if (TARGET_SYSTEM == _WIN32_) +#define _WINSOCKAPI_ // prevent windows.h from including winsock.h +#endif // (TARGET_SYSTEM == _WIN32_) +/* includes */ +#include "Epl.h" + +#undef EPL_STACK_VERSION +#define EPL_STACK_VERSION(ver,rev,rel) (((((ver)) & 0xFF)<<24)|((((rev))&0xFF)<<16)|(((rel))&0xFFFF)) + +#if (TARGET_SYSTEM == _LINUX_) +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifndef CONFIG_POWERLINK_USERSTACK +#include +#else +#include +#endif + +#elif (TARGET_SYSTEM == _WIN32_) +#include +#include +#endif // (TARGET_SYSTEM == _WIN32_) +#include +//#include + +/***************************************************************************/ +/* */ +/* */ +/* G L O B A L D E F I N I T I O N S */ +/* */ +/* */ +/***************************************************************************/ + +//--------------------------------------------------------------------------- +// const defines +//--------------------------------------------------------------------------- +#if (TARGET_SYSTEM == _LINUX_) + +#define SET_CPU_AFFINITY +#define MAIN_THREAD_PRIORITY 20 + +#elif (TARGET_SYSTEM == _WIN32_) + +// TracePoint support for realtime-debugging +#ifdef _DBG_TRACE_POINTS_ +void PUBLIC TgtDbgSignalTracePoint (BYTE bTracePointNumber_p); +#define TGT_DBG_SIGNAL_TRACE_POINT(p) TgtDbgSignalTracePoint(p) +#else +#define TGT_DBG_SIGNAL_TRACE_POINT(p) +#endif + +#endif // (TARGET_SYSTEM == _WIN32_) +const DWORD NODEID = 0xF0; //=> MN +const DWORD IP_ADDR = 0xc0a86401; // 192.168.100.1 +const DWORD SUBNET_MASK = 0xFFFFFF00; // 255.255.255.0 +const char* HOSTNAME = "EPL Stack"; + +//--------------------------------------------------------------------------- +// module global vars +//--------------------------------------------------------------------------- + +CONST BYTE abMacAddr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + +static unsigned int uiNodeId_g = EPL_C_ADR_INVALID; + +static tEplApiProcessImageCopyJob AppProcessImageCopyJob_g; + +static bool waitingUntilOperational; + +#ifdef CONFIG_POWERLINK_USERSTACK + +//static char* pszCdcFilename_g = "mnobd.cdc"; + +#else + +static pthread_t eventThreadId; +static pthread_t syncThreadId; + +void *powerlinkEventThread(void * arg); +void *powerlinkSyncThread(void * arg); + +#endif + +//--------------------------------------------------------------------------- +// local function prototypes +//--------------------------------------------------------------------------- + +// This function is the entry point for your object dictionary. It is defined +// in OBJDICT.C by define EPL_OBD_INIT_RAM_NAME. Use this function name to define +// this function prototype here. If you want to use more than one Epl +// instances then the function name of each object dictionary has to differ. + +extern "C" tEplKernel PUBLIC EplObdInitRam (tEplObdInitParam MEM* pInitParam_p); + +tEplKernel PUBLIC AppCbEvent( + tEplApiEventType EventType_p,// IN: event type (enum) + tEplApiEventArg* pEventArg_p,// IN: event argument (union) + void GENERIC* pUserArg_p); + +tEplKernel PUBLIC AppCbSync(void); + +char* CEplStackWrapper::allocProcImage(unsigned int n_bytes){ + char* procImage = (char*) malloc(n_bytes); + for(unsigned int i = 0; i < n_bytes; i++){ + procImage[i] = 0x00; + } + + return procImage; +} + +//=========================================================================// +// // +// S T A T I C F U N C T I O N S // +// // +//=========================================================================// + +DEFINE_SINGLETON(CEplStackWrapper); + +void CEplStackWrapper::eplMainInit(){ +#if (TARGET_SYSTEM == _LINUX_) + sigset_t mask; + + /* + * We have to block the real time signals used by the timer modules so + * that they are able to wait on them using sigwaitinfo! + */ + sigemptyset(&mask); + sigaddset(&mask, SIGRTMIN); + sigaddset(&mask, SIGRTMIN + 1); + pthread_sigmask(SIG_BLOCK, &mask, NULL); +#endif +} + +//=========================================================================// +// // +// C L A S S F U N C T I O N S // +// // +//=========================================================================// + +CEplStackWrapper::CEplStackWrapper(){ +} + +CEplStackWrapper::~CEplStackWrapper(){ +} + +int CEplStackWrapper::eplStackInit(char* pa_chXmlFile, char* pa_chCdcFile, char* pa_chEthDeviceName){ + tEplKernel EplRet; + static tEplApiInitParam EplApiInitParam; + const char* sHostname = HOSTNAME; + char cKey = 0; + + // Read and process XML file + CEplXmlReader xmlReader(&m_oProcMatrixIn, &m_oProcMatrixOut); + xmlReader.readXmlFile(pa_chXmlFile); + + m_nProcInSize = m_oProcMatrixIn.getProcessImageSize(); + m_nProcOutSize = m_oProcMatrixOut.getProcessImageSize(); + + m_pchAppProcessImageIn_g = allocProcImage(m_nProcInSize); + m_pchAppProcessImageOut_g = allocProcImage(m_nProcOutSize); + +#ifdef CONFIG_POWERLINK_USERSTACK +#if (TARGET_SYSTEM == _LINUX_) + struct sched_param schedParam; +#endif + + // variables for Pcap + char sErr_Msg[PCAP_ERRBUF_SIZE]; + pcap_if_t *alldevs; + pcap_if_t *seldev; + int i = 0; + int inum; +#endif + +#ifdef CONFIG_POWERLINK_USERSTACK + +#if (TARGET_SYSTEM == _LINUX_) + /* adjust process priority */ + if(nice(-20) == -1) // push nice level in case we have no RTPreempt + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + EPL_DBGLVL_ERROR_TRACE("%s() couldn't set nice value! (%s)\n", __func__, strerror(errno)); +#else + EPL_DBGLVL_ERROR_TRACE2("%s() couldn't set nice value! (%s)\n", __func__, strerror(errno)); +#endif + + } + schedParam.__sched_priority = MAIN_THREAD_PRIORITY; + if(pthread_setschedparam(pthread_self(), SCHED_RR, &schedParam) != 0){ +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + EPL_DBGLVL_ERROR_TRACE("%s() couldn't set thread scheduling parameters! %d\n", __func__, schedParam.__sched_priority); +#else + EPL_DBGLVL_ERROR_TRACE2("%s() couldn't set thread scheduling parameters! %d\n", __func__, schedParam.__sched_priority); +#endif + } + + /* Initialize target specific stuff */ + // EplTgtInit(); +#elif (TARGET_SYSTEM == _WIN32_) + + // activate realtime priority class + SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); + // lower the priority of this thread + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); + +#endif // (TARGET_SYSTEM == _WIN32_) +#endif // CONFIG_POWERLINK_USERSTACK + /* Enabling ftrace for debugging */ + FTRACE_OPEN(); + FTRACE_ENABLE (TRUE); + + EPL_MEMSET(&EplApiInitParam, 0, sizeof(EplApiInitParam)); + EplApiInitParam.m_uiSizeOfStruct = sizeof(EplApiInitParam); + +#ifdef CONFIG_POWERLINK_USERSTACK + + //////////////////////////////////////////////////////////////////////////////// + // Find ETH card specified by user // + //////////////////////////////////////////////////////////////////////////////// + + bool macFound = false; + char correctDevName[1024]; + + macFound = findMAC(pa_chEthDeviceName, &correctDevName[0]); + + /* Retrieve the device list on the local machine */ + + if(pcap_findalldevs(&alldevs, sErr_Msg) == -1){ + fprintf(stderr, "Error in pcap_findalldevs: %s\n", sErr_Msg); + EplRet = kEplNoResource; + return EplRet; + } + + printf("\n"); + for(seldev = alldevs, i = 0; seldev != NULL; seldev = seldev->next, i++){ + if(seldev->description){ + printf("%d: %s\n %s\n", i, seldev->description, seldev->name); + } + else{ + printf("%d: %s\n", i, seldev->name); + } + + if(macFound){ + const char* userDescLoc = strstr(seldev->name, correctDevName); + if(userDescLoc != NULL){ + inum = i; + if(seldev->description){ + printf("\nChosen Ethernet Card: %s\n %s\n", seldev->description, seldev->name); + } + else{ + printf("\nChosen Ethernet Card: %s\n", seldev->name); + } + break; + } + } + + if(seldev->description){ + const char* userDescLoc = strstr(seldev->description, pa_chEthDeviceName); + if(userDescLoc != NULL){ + inum = i; + printf("\nChosen Ethernet Card: %s\n", seldev->description); + break; + } + } + else{ + const char* userDescLoc = strstr(seldev->name, pa_chEthDeviceName); + if(userDescLoc != NULL){ + inum = i; + printf("Chosen Ethernet Card: %s\n", seldev->name); + break; + } + } + } + + // Check if a device was found, otherwise shutdown stack + if(!seldev){ + fprintf(stderr, "%s(Err/Warn): Invalid MAC address or device name specified. Shutting down Powerlink stack\n", __func__); + EplRet = kEplNoResource; + return EplRet; + } + + //////////////////////////////////////////////////////////////////////////////// + // Setup EplApiInitParam (some of them can be removed as we have obd?) // + //////////////////////////////////////////////////////////////////////////////// + + // pass selected device name to Edrv + char devName[128]; + strncpy(devName, seldev->name, 127); + EplApiInitParam.m_HwParam.m_pszDevName = devName; + +#endif + + EplApiInitParam.m_uiNodeId = uiNodeId_g = NODEID; + EplApiInitParam.m_dwIpAddress = (0xFFFFFF00 & IP_ADDR) | EplApiInitParam.m_uiNodeId; + + /* write 00:00:00:00:00:00 to MAC address, so that the driver uses the real hardware address */ + EPL_MEMCPY(EplApiInitParam.m_abMacAddress, abMacAddr, sizeof(EplApiInitParam.m_abMacAddress)); + + EplApiInitParam.m_fAsyncOnly = FALSE; + + EplApiInitParam.m_dwFeatureFlags = -1; + EplApiInitParam.m_dwCycleLen = 10000; // required for error detection + EplApiInitParam.m_uiIsochrTxMaxPayload = 256; // const + EplApiInitParam.m_uiIsochrRxMaxPayload = 256; // const + EplApiInitParam.m_dwPresMaxLatency = 50000; // const; only required for IdentRes + EplApiInitParam.m_uiPreqActPayloadLimit = 36; // required for initialisation (+28 bytes) + EplApiInitParam.m_uiPresActPayloadLimit = 36; // required for initialisation of Pres frame (+28 bytes) + EplApiInitParam.m_dwAsndMaxLatency = 150000; // const; only required for IdentRes + EplApiInitParam.m_uiMultiplCycleCnt = 0; // required for error detection + EplApiInitParam.m_uiAsyncMtu = 1500; // required to set up max frame size + EplApiInitParam.m_uiPrescaler = 2; // required for sync + EplApiInitParam.m_dwLossOfFrameTolerance = 500000; + EplApiInitParam.m_dwAsyncSlotTimeout = 3000000; + EplApiInitParam.m_dwWaitSocPreq = 150000; + EplApiInitParam.m_dwDeviceType = -1; // NMT_DeviceType_U32 + EplApiInitParam.m_dwVendorId = -1; // NMT_IdentityObject_REC.VendorId_U32 + EplApiInitParam.m_dwProductCode = -1; // NMT_IdentityObject_REC.ProductCode_U32 + EplApiInitParam.m_dwRevisionNumber = -1; // NMT_IdentityObject_REC.RevisionNo_U32 + EplApiInitParam.m_dwSerialNumber = -1; // NMT_IdentityObject_REC.SerialNo_U32 + + EplApiInitParam.m_dwSubnetMask = SUBNET_MASK; + EplApiInitParam.m_dwDefaultGateway = 0; + EPL_MEMCPY(EplApiInitParam.m_sHostname, sHostname, sizeof(EplApiInitParam.m_sHostname)); + EplApiInitParam.m_uiSyncNodeId = EPL_C_ADR_SYNC_ON_SOA; + EplApiInitParam.m_fSyncOnPrcNode = FALSE; + + // set callback functions + EplApiInitParam.m_pfnCbEvent = AppCbEvent; + +#ifdef CONFIG_POWERLINK_USERSTACK + EplApiInitParam.m_pfnObdInitRam = EplObdInitRam; + EplApiInitParam.m_pfnCbSync = AppCbSync; +#else + EplApiInitParam.m_pfnCbSync = NULL; +#endif + //////////////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////////////// + // Initialize Powerlink Stack // + //////////////////////////////////////////////////////////////////////////////// + printf("\n\n Powerlink %s running.\n (build: %s / %s)\n\n", (NODEID == EPL_C_ADR_MN_DEF_NODE_ID ? "Managing Node" : "Controlled Node"), __DATE__, __TIME__); + + // initialize POWERLINK stack + EplRet = EplApiInitialize(&EplApiInitParam); + if(EplRet != kEplSuccessful){ + return EplRet; + } + +#ifdef CONFIG_POWERLINK_USERSTACK + /* At this point, we don't need any more the device list. Free it */ + pcap_freealldevs(alldevs); + + EplRet = EplApiSetCdcFilename(pa_chCdcFile); + if(EplRet != kEplSuccessful){ + return EplRet; + } +#else + // create event thread + if(pthread_create(&eventThreadId, NULL, &powerlinkEventThread, NULL) != 0){ + return EplRet; + } + + // create sync thread + if(pthread_create(&syncThreadId, NULL, &powerlinkSyncThread, NULL) != 0){ + return EplRet; + } +#endif + + AppProcessImageCopyJob_g.m_fNonBlocking = FALSE; + AppProcessImageCopyJob_g.m_uiPriority = 0; + AppProcessImageCopyJob_g.m_In.m_pPart = m_pchAppProcessImageIn_g; + AppProcessImageCopyJob_g.m_In.m_uiOffset = 0; + AppProcessImageCopyJob_g.m_In.m_uiSize = m_nProcInSize; + AppProcessImageCopyJob_g.m_Out.m_pPart = m_pchAppProcessImageOut_g; + AppProcessImageCopyJob_g.m_Out.m_uiOffset = 0; + AppProcessImageCopyJob_g.m_Out.m_uiSize = m_nProcOutSize; + + EplRet = EplApiProcessImageAlloc(m_nProcInSize, m_nProcOutSize, 2, 2); + if(EplRet != kEplSuccessful){ + eplStackShutdown(); + } + + EplRet = EplApiProcessImageSetup(); + if(EplRet != kEplSuccessful){ + eplStackShutdown(); + } + + // start processing + EplRet = EplApiExecNmtCommand(kEplNmtEventSwReset); + if(EplRet != kEplSuccessful){ + eplStackShutdown(); + } + + waitingUntilOperational = false; + if(m_bWait == true){ + while(!waitingUntilOperational){ + // Waiting +#if (TARGET_SYSTEM == _WIN32_) + Sleep(1); +#elif (TARGET_SYSTEM == _LINUX_) + usleep(1); +#endif + } + } + + return EplRet; +} + +//////////////////////////////////////////////////////////////////////////////// +// Stop the stack // +//////////////////////////////////////////////////////////////////////////////// +int CEplStackWrapper::eplStackShutdown(void){ + tEplKernel EplRet; + + // halt the NMT state machine + // so the processing of POWERLINK frames stops + EplRet = EplApiExecNmtCommand(kEplNmtEventSwitchOff); + + // delete process image + EplRet = EplApiProcessImageFree(); + + // delete instance for all modules + EplRet = EplApiShutdown(); + printf("EplApiShutdown(): 0x%X\n", EplRet); + + m_oProcMatrixIn.clearAll(); + m_oProcMatrixOut.clearAll(); + m_lCallbackList.clearAll(); + free(m_pchAppProcessImageIn_g); + free(m_pchAppProcessImageOut_g); + + return EplRet; +} + +CProcessImageMatrix* CEplStackWrapper::getProcessImageMatrixIn(){ + return &m_oProcMatrixIn; +} + +CProcessImageMatrix* CEplStackWrapper::getProcessImageMatrixOut(){ + return &m_oProcMatrixOut; +} + +char* CEplStackWrapper::getProcImageIn(){ + return m_pchAppProcessImageIn_g; +} + +char* CEplStackWrapper::getProcImageOut(){ + return m_pchAppProcessImageOut_g; +} + +void CEplStackWrapper::waitUntilOperational(bool pa_bWait){ + m_bWait = pa_bWait; +} + +void CEplStackWrapper::registerCallback(IEplCNCallback* pa_pCallback){ + m_oSync.lock(); + m_lCallbackList.push_back(pa_pCallback); + m_oSync.unlock(); +} + +bool CEplStackWrapper::findMAC(const char* pa_pchUserMAC, char* pa_pchDeviceName){ + bool macFound = false; + char* correctDevName; + +#if (TARGET_SYSTEM == _LINUX_) + + int nSD; // Socket descriptor + struct ifreq sIfReq; // Interface request + struct if_nameindex *pIfList; // Ptr to interface name index + struct if_nameindex *pListSave; // Ptr to interface name index + + // + // Initialize this function + // + pIfList = (struct if_nameindex *) NULL; + pListSave = (struct if_nameindex *) NULL; +#ifndef SIOCGIFADDR + // The kernel does not support the required ioctls + return (false); +#endif + + // + // Create a socket that we can use for all of our ioctls + // + nSD = socket(PF_INET, SOCK_STREAM, 0); + if(nSD < 0){ + // Socket creation failed, this is a fatal error + printf("File %s: line %d: Socket failed\n", __FILE__, __LINE__); + return (0); + } + + // + // Obtain a list of dynamically allocated structures + // + pIfList = pListSave = if_nameindex(); + + // + // Walk thru the array returned and query for each interface's + // address + // + for(pIfList; *(char *) pIfList != 0; pIfList++){ + + strncpy(sIfReq.ifr_name, pIfList->if_name, IF_NAMESIZE); + + // + // Get the MAC address for this interface + // + if(ioctl(nSD, SIOCGIFHWADDR, &sIfReq) != 0){ + // We failed to get the MAC address for the interface + printf("File %s: line %d: Ioctl failed\n", __FILE__, __LINE__); + return false; + } + + // + // Determine if we are processing the interface that we + // are interested in + // + char chMAC[6 * 2 + 5 + 2]; + sprintf(chMAC, "%02X-%02X-%02X-%02X-%02X-%02X", (unsigned char) sIfReq.ifr_hwaddr.sa_data[0], (unsigned char) sIfReq.ifr_hwaddr.sa_data[1], (unsigned char) sIfReq.ifr_hwaddr.sa_data[2], (unsigned char) sIfReq.ifr_hwaddr.sa_data[3], (unsigned char) sIfReq.ifr_hwaddr.sa_data[4], (unsigned char) sIfReq.ifr_hwaddr.sa_data[5]); + + if(compareMACs(chMAC, pa_pchUserMAC)){ + strncpy(pa_pchDeviceName, pIfList->if_name, IF_NAMESIZE); + macFound = true; + + // + // Clean up things and return + // + if_freenameindex(pListSave); + close(nSD); + + return macFound; + } + } + + // + // Clean up things and return + // + if_freenameindex(pListSave); + close(nSD); + +#elif (TARGET_SYSTEM == _WIN32_) + + // Find MAC address + IP_ADAPTER_INFO AdapterInfo[16];// Allocate information for up to 16 NICs + DWORD dwBufLen = sizeof(AdapterInfo);// Save memory size of buffer + + DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen); + assert(dwStatus == ERROR_SUCCESS);// Verify return value is valid, no buffer overflow + + PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info + + do{ + char* chMAC = new char[6*2+5+1]; + BYTE *macAddr = pAdapterInfo->Address; + for (int i = 0; i < 6*2+5; i = i+2) + { + if (i>0){ + chMAC[i] = '-'; + i++; + } + sprintf(&chMAC[i],"%02x",*macAddr++); + } + + if (compareMACs(chMAC, pa_pchUserMAC)){ + macFound = true; + //correctDevName = new char[strlen(pAdapterInfo->AdapterName)+1]; + strcpy(pa_pchDeviceName,pAdapterInfo->AdapterName); + delete chMAC; + + //pa_pchDeviceName = correctDevName; + return macFound; + } + + pAdapterInfo = pAdapterInfo->Next; // Progress through linked list + delete chMAC; + } + while(pAdapterInfo); // Terminate if last adapter + +#endif + + pa_pchDeviceName = NULL; + return false; +} + +bool CEplStackWrapper::compareMACs(const char* pa_chMACa, const char* pa_chMACb){ + if(strcmp(pa_chMACa, pa_chMACb) == 0){ + return true; + } + + char* macCopyA = new char[strlen(pa_chMACa) + 1]; + strcpy(macCopyA, pa_chMACa); + char* macCopyB = new char[strlen(pa_chMACb) + 1]; + strcpy(macCopyB, pa_chMACb); + + // Change to upper case + for(int i = 0; i < strlen(pa_chMACa); i++){ + switch (macCopyA[i]){ + case 'a': + macCopyA[i] = 'A'; + break; + case 'b': + macCopyA[i] = 'B'; + break; + case 'c': + macCopyA[i] = 'C'; + break; + case 'd': + macCopyA[i] = 'D'; + break; + case 'e': + macCopyA[i] = 'E'; + break; + case 'f': + macCopyA[i] = 'F'; + break; + } + } + for(int i = 0; i < strlen(pa_chMACb); i++){ + switch (macCopyB[i]){ + case 'a': + macCopyB[i] = 'A'; + break; + case 'b': + macCopyB[i] = 'B'; + break; + case 'c': + macCopyB[i] = 'C'; + break; + case 'd': + macCopyB[i] = 'D'; + break; + case 'e': + macCopyB[i] = 'E'; + break; + case 'f': + macCopyB[i] = 'F'; + break; + } + } + + if(strcmp(macCopyA, macCopyB) == 0){ + delete[] macCopyA; + delete[] macCopyB; + return true; + } + + delete[] macCopyA; + delete[] macCopyB; + return false; +} + +//=========================================================================// +// // +// P R I V A T E F U N C T I O N S // +// // +//=========================================================================// + +//--------------------------------------------------------------------------- +// +// Function: AppCbEvent +// +// Description: event callback function called by EPL API layer within +// user part (low priority). +// +// Parameters: EventType_p = event type +// pEventArg_p = pointer to union, which describes +// the event in detail +// pUserArg_p = user specific argument +// +// Returns: tEplKernel = error code, +// kEplSuccessful = no error +// kEplReject = reject further processing +// otherwise = post error event to API layer +// +// State: +// +//--------------------------------------------------------------------------- + +tEplKernel PUBLIC AppCbEvent( + tEplApiEventType EventType_p,// IN: event type (enum) + tEplApiEventArg* pEventArg_p,// IN: event argument (union) + void GENERIC* pUserArg_p) +{ + tEplKernel EplRet = kEplSuccessful; + + UNUSED_PARAMETER(pUserArg_p); + + // check if NMT_GS_OFF is reached + switch (EventType_p) + { + case kEplApiEventNmtStateChange: + { + switch (pEventArg_p->m_NmtStateChange.m_NewNmtState) + { + case kEplNmtGsOff: + { // NMT state machine was shut down, + // because of user signal (CTRL-C) or critical EPL stack error + // -> also shut down EplApiProcess() and main() + EplRet = kEplShutdown; +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(kEplNmtGsOff) originating event = 0x%X\n", __func__, pEventArg_p->m_NmtStateChange.m_NmtEvent); +#else + PRINTF2("%s(kEplNmtGsOff) originating event = 0x%X\n", __func__, pEventArg_p->m_NmtStateChange.m_NmtEvent); +#endif + break; + } + + case kEplNmtGsResetCommunication: + { + // continue + } + + case kEplNmtGsResetConfiguration: + { + // continue + } + + case kEplNmtMsPreOperational1: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(0x%X) originating event = 0x%X\n", + __func__, + pEventArg_p->m_NmtStateChange.m_NewNmtState, + pEventArg_p->m_NmtStateChange.m_NmtEvent); +#else + PRINTF3("%s(0x%X) originating event = 0x%X\n", + __func__, + pEventArg_p->m_NmtStateChange.m_NewNmtState, + pEventArg_p->m_NmtStateChange.m_NmtEvent); +#endif + + // continue + } + + case kEplNmtGsInitialising: + case kEplNmtGsResetApplication: + case kEplNmtMsNotActive: + case kEplNmtCsNotActive: + case kEplNmtCsPreOperational1: + { + break; + } + case kEplNmtCsOperational: + case kEplNmtMsOperational: + { + break; + } + default: + { + break; + } + } + + break; + } + + case kEplApiEventCriticalError: + case kEplApiEventWarning: + { // error or warning occured within the stack or the application + // on error the API layer stops the NMT state machine +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Err/Warn): Source=%02X EplError=0x%03X", + __func__, + pEventArg_p->m_InternalError.m_EventSource, + pEventArg_p->m_InternalError.m_EplError); +#else + PRINTF3("%s(Err/Warn): Source=%02X EplError=0x%03X", + __func__, + pEventArg_p->m_InternalError.m_EventSource, + pEventArg_p->m_InternalError.m_EplError); +#endif + // check additional argument + switch (pEventArg_p->m_InternalError.m_EventSource) + { + case kEplEventSourceEventk: + case kEplEventSourceEventu: + { // error occured within event processing + // either in kernel or in user part +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF(" OrgSource=%02X\n", pEventArg_p->m_InternalError.m_Arg.m_EventSource); +#else + PRINTF1(" OrgSource=%02X\n", pEventArg_p->m_InternalError.m_Arg.m_EventSource); +#endif + break; + } + + case kEplEventSourceDllk: + { // error occured within the data link layer (e.g. interrupt processing) + // the DWORD argument contains the DLL state and the NMT event +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF(" val=%lX\n", pEventArg_p->m_InternalError.m_Arg.m_dwArg); +#else + PRINTF1(" val=%lX\n", pEventArg_p->m_InternalError.m_Arg.m_dwArg); +#endif + break; + } + + case kEplEventSourceObdk: + case kEplEventSourceObdu: + { // error occured within OBD module + // either in kernel or in user part +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF(" Object=0x%04X/%u\n", pEventArg_p->m_InternalError.m_Arg.m_ObdError.m_uiIndex, pEventArg_p->m_InternalError.m_Arg.m_ObdError.m_uiSubIndex); +#else + PRINTF2(" Object=0x%04X/%u\n", pEventArg_p->m_InternalError.m_Arg.m_ObdError.m_uiIndex, pEventArg_p->m_InternalError.m_Arg.m_ObdError.m_uiSubIndex); +#endif + break; + } + + default: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("\n"); +#else + PRINTF0("\n"); +#endif + break; + } + } + break; + } + + case kEplApiEventHistoryEntry: + { // new history entry + PRINTF("%s(HistoryEntry): Type=0x%04X Code=0x%04X (0x%02X %02X %02X %02X %02X %02X %02X %02X)\n", + __func__, + pEventArg_p->m_ErrHistoryEntry.m_wEntryType, + pEventArg_p->m_ErrHistoryEntry.m_wErrorCode, + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[0], + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[1], + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[2], + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[3], + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[4], + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[5], + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[6], + (WORD) pEventArg_p->m_ErrHistoryEntry.m_abAddInfo[7]); + break; + } + + case kEplApiEventNode: + { + // check additional argument + switch (pEventArg_p->m_Node.m_NodeEvent) + { + case kEplNmtNodeEventCheckConf: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, CheckConf)\n", __func__, pEventArg_p->m_Node.m_uiNodeId); +#else + PRINTF2("%s(Node=0x%X, CheckConf)\n", __func__, pEventArg_p->m_Node.m_uiNodeId); +#endif + break; + } + + case kEplNmtNodeEventUpdateConf: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, UpdateConf)\n", __func__, pEventArg_p->m_Node.m_uiNodeId); +#else + PRINTF2("%s(Node=0x%X, UpdateConf)\n", __func__, pEventArg_p->m_Node.m_uiNodeId); +#endif + break; + } + + case kEplNmtNodeEventNmtState: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, NmtState=0x%X)\n", __func__, pEventArg_p->m_Node.m_uiNodeId, pEventArg_p->m_Node.m_NmtState); +#else + PRINTF3("%s(Node=0x%X, NmtState=0x%X)\n", __func__, pEventArg_p->m_Node.m_uiNodeId, pEventArg_p->m_Node.m_NmtState); +#endif + if (pEventArg_p->m_Node.m_NmtState == kEplNmtCsOperational){ + printf("init finished\n"); + waitingUntilOperational = true; + } + break; + } + + case kEplNmtNodeEventError: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, Error=0x%X)\n", __func__, pEventArg_p->m_Node.m_uiNodeId, pEventArg_p->m_Node.m_wErrorCode); +#else + PRINTF3("%s(Node=0x%X, Error=0x%X)\n", __func__, pEventArg_p->m_Node.m_uiNodeId, pEventArg_p->m_Node.m_wErrorCode); +#endif + break; + } + + case kEplNmtNodeEventFound: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, Found)\n", __func__, pEventArg_p->m_Node.m_uiNodeId); +#else + PRINTF2("%s(Node=0x%X, Found)\n", __func__, pEventArg_p->m_Node.m_uiNodeId); +#endif + break; + } + + default: + { + break; + } + } + break; + } + +#if (((EPL_MODULE_INTEGRATION) & (EPL_MODULE_CFM)) != 0) + case kEplApiEventCfmProgress: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, CFM-Progress: Object 0x%X/%u, ", __func__, pEventArg_p->m_CfmProgress.m_uiNodeId, pEventArg_p->m_CfmProgress.m_uiObjectIndex, pEventArg_p->m_CfmProgress.m_uiObjectSubIndex); + PRINTF("%u/%u Bytes", pEventArg_p->m_CfmProgress.m_dwBytesDownloaded, pEventArg_p->m_CfmProgress.m_dwTotalNumberOfBytes); +#else + PRINTF4("%s(Node=0x%X, CFM-Progress: Object 0x%X/%u, ", __func__, pEventArg_p->m_CfmProgress.m_uiNodeId, pEventArg_p->m_CfmProgress.m_uiObjectIndex, pEventArg_p->m_CfmProgress.m_uiObjectSubIndex); + PRINTF2("%u/%u Bytes", pEventArg_p->m_CfmProgress.m_dwBytesDownloaded, pEventArg_p->m_CfmProgress.m_dwTotalNumberOfBytes); +#endif + if ((pEventArg_p->m_CfmProgress.m_dwSdoAbortCode != 0) + || (pEventArg_p->m_CfmProgress.m_EplError != kEplSuccessful)) + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF(" -> SDO Abort=0x%lX, Error=0x%X)\n", pEventArg_p->m_CfmProgress.m_dwSdoAbortCode, pEventArg_p->m_CfmProgress.m_EplError); +#else + PRINTF2(" -> SDO Abort=0x%lX, Error=0x%X)\n", pEventArg_p->m_CfmProgress.m_dwSdoAbortCode, pEventArg_p->m_CfmProgress.m_EplError); +#endif + } + else + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF(")\n"); +#else + PRINTF0(")\n"); +#endif + } + break; + } + + case kEplApiEventCfmResult: + { + switch (pEventArg_p->m_CfmResult.m_NodeCommand) + { + case kEplNmtNodeCommandConfOk: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, ConfOk)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#else + PRINTF2("%s(Node=0x%X, ConfOk)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#endif + break; + } + + case kEplNmtNodeCommandConfErr: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, ConfErr)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#else + PRINTF2("%s(Node=0x%X, ConfErr)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#endif + break; + } + + case kEplNmtNodeCommandConfReset: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, ConfReset)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#else + PRINTF2("%s(Node=0x%X, ConfReset)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#endif + break; + } + + case kEplNmtNodeCommandConfRestored: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, ConfRestored)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#else + PRINTF2("%s(Node=0x%X, ConfRestored)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId); +#endif + break; + } + + default: + { +#if EPL_DEFINED_STACK_VERSION >= EPL_STACK_VERSION(1, 8, 2) + PRINTF("%s(Node=0x%X, CfmResult=0x%X)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId, pEventArg_p->m_CfmResult.m_NodeCommand); +#else + PRINTF3("%s(Node=0x%X, CfmResult=0x%X)\n", __func__, pEventArg_p->m_CfmResult.m_uiNodeId, pEventArg_p->m_CfmResult.m_NodeCommand); +#endif + break; + } + } + break; + } +#endif + + default: + break; + } + + return EplRet; +} + +//--------------------------------------------------------------------------- +// +// Function: AppCbSync +// +// Description: sync event callback function called by event module within +// kernel part (high priority). +// This function sets the outputs, reads the inputs and runs +// the control loop. +// +// Parameters: void +// +// Returns: tEplKernel = error code, +// kEplSuccessful = no error +// otherwise = post error event to API layer +// +// State: +// +//--------------------------------------------------------------------------- + +tEplKernel PUBLIC AppCbSync(void){ + tEplKernel EplRet = kEplSuccessful; + + EplRet = EplApiProcessImageExchange(&AppProcessImageCopyJob_g); + + // Loop through callback list and call each FB in the list + CEplStackWrapper::getInstance().executeAllCallbacks(); + + return EplRet; +} + +void CEplStackWrapper::executeAllCallbacks(){ + m_oSync.lock(); + CSinglyLinkedList::Iterator itEnd = m_lCallbackList.end(); + for(CSinglyLinkedList::Iterator it = m_lCallbackList.begin(); it != itEnd; ++it){ + it->cnSynchCallback(); + } + m_oSync.unlock(); +} + +#ifndef CONFIG_POWERLINK_USERSTACK + +void *powerlinkEventThread(void * arg __attribute__((unused))){ + EplApiProcess(); + + return NULL; +} + +void *powerlinkSyncThread(void * arg __attribute__((unused))){ + while(1){ + AppCbSync(); + } + return NULL; +} + +#endif + +// EOF diff --git a/src/modules/powerlink/EplWrapper.h b/src/modules/powerlink/EplWrapper.h new file mode 100644 index 000000000..27afb5d97 --- /dev/null +++ b/src/modules/powerlink/EplWrapper.h @@ -0,0 +1,101 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2104 AIT, ACIN, fortiss + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EPLWRAPPER_H_ +#define _EPLWRAPPER_H_ + +#include "ProcessImageMatrix.h" +#include "EplCNCallback.h" +#include +#include +#include + +struct SEplMapping{ + struct SEplMappingValues{ + unsigned int m_nDataSize; + unsigned int m_nPiOffset; + unsigned int m_nBitOffset; + char* m_pchCurrentValue; + + SEplMappingValues(unsigned int pa_nDataSize, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset) : + m_nDataSize(pa_nDataSize), m_nPiOffset(pa_nPiOffset), m_nBitOffset(pa_nBitOffset){ + m_pchCurrentValue = new char[pa_nDataSize]; + for(unsigned int i = 0; i < pa_nDataSize; i++){ + m_pchCurrentValue[i] = 0x00; + } + } + + ~SEplMappingValues(){ + delete[] m_pchCurrentValue; + } + }; + + typedef CSinglyLinkedList TEplMappingList; + TEplMappingList m_lCurrentValues; + + ~SEplMapping(){ + while(!m_lCurrentValues.isEmpty()){ + delete *(TEplMappingList::Iterator) m_lCurrentValues.begin(); + m_lCurrentValues.pop_front(); + } + } +}; + +// CEplStackWrapper implemented as class +class CEplStackWrapper{ + DECLARE_SINGLETON(CEplStackWrapper) + ; + public: + /*! \brief Blocking of real-time signals + * + * This must be called in main.cpp before the event execution thread is started + */ + static void eplMainInit(); + + int eplStackInit(char* pa_chXmlFile, char* pa_chCdcFile, char* pa_chEthDeviceName); + + int eplStackShutdown(void); + + CProcessImageMatrix* getProcessImageMatrixIn(); + CProcessImageMatrix* getProcessImageMatrixOut(); + + char* getProcImageIn(); + char* getProcImageOut(); + + void waitUntilOperational(bool pa_bWait); + + void registerCallback(IEplCNCallback* pa_pCallback); + + void executeAllCallbacks(); + + private: + char* allocProcImage(unsigned int n_bytes); + + bool findMAC(const char* pa_pchUserMAC, char* pa_pchDevieName); + + bool compareMACs(const char* pa_chMACa, const char* pa_chMACb); + + CProcessImageMatrix m_oProcMatrixIn; + CProcessImageMatrix m_oProcMatrixOut; + + unsigned int m_nProcInSize; + char* m_pchAppProcessImageIn_g; + unsigned int m_nProcOutSize; + char* m_pchAppProcessImageOut_g; + + bool m_bWait; + + CSinglyLinkedList m_lCallbackList; + + CSyncObject m_oSync; + +}; + +#endif diff --git a/src/modules/powerlink/EplXmlReader.cpp b/src/modules/powerlink/EplXmlReader.cpp new file mode 100644 index 000000000..6b206534d --- /dev/null +++ b/src/modules/powerlink/EplXmlReader.cpp @@ -0,0 +1,242 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2014 AIT, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EplXmlReader.h" + +#include +#include +#include +#include +#include +using namespace std; + +#include + +CEplXmlReader::CEplXmlReader(CProcessImageMatrix* pa_pIn, CProcessImageMatrix* pa_pOut){ + m_pProcImageIn = pa_pIn; + m_pProcImageOut = pa_pOut; +} + +CEplXmlReader::~CEplXmlReader(){ + +} + +void CEplXmlReader::setProcessImageIn(CProcessImageMatrix* pa_pIn){ + m_pProcImageIn = pa_pIn; +} + +void CEplXmlReader::setProcessImageOut(CProcessImageMatrix* pa_pOut){ + m_pProcImageOut = pa_pOut; +} + +void CEplXmlReader::readXmlFile(const char* pa_pchFileName){ + + TiXmlDocument xmlDoc(pa_pchFileName); + + if(xmlDoc.LoadFile()){ + TiXmlNode *appProcess = xmlDoc.FirstChild("ApplicationProcess"); + TiXmlNode *processImageIn; + for(TiXmlNode *processImage = appProcess->ToElement()->FirstChild("ProcessImage"); processImage != NULL; processImage = processImage->NextSibling("ProcessImage")){ + if(strcmp(processImage->ToElement()->Attribute("type"), "output") == 0){ + createProcImageOut(processImage); + } + else if(strcmp(processImage->ToElement()->Attribute("type"), "input") == 0){ + processImageIn = processImage; + } + } + createProcImageIn(processImageIn); + } + else{ + cout << "ERROR: Could not open XML file" << endl; + } +} + +void CEplXmlReader::createProcImageOut(TiXmlNode* pa_pProcessImage){ + int currentCnId = -1; + int currentModuleNr = -1; + char currentModuleId[256]; + int currentIoNr = -1; + + TiXmlNode *channel; + for(channel = pa_pProcessImage->FirstChild("Channel"); channel != NULL; channel = channel->NextSibling("Channel")){ + // New IO + currentIoNr++; + + // Get "Name" attribute + const char *ioName = channel->ToElement()->Attribute("Name"); + char *nameStr = new char[strlen(ioName) + 1]; + strcpy(nameStr, ioName); + + // Get CN ID + char* pch = strtok(nameStr, ".CN"); + int cnId = forte::core::util::strtol(pch,0,10); + + // Get module ID + char* modId = strtok(NULL, "."); + + // Get dataSize + const char *temp = channel->ToElement()->Attribute("dataSize"); + int dSize = forte::core::util::strtoul(temp,0,10); + + // Get PIOffset + temp = channel->ToElement()->Attribute("PIOffset"); + long piOffset = forte::core::util::strtol(temp, NULL, 16); + + // Get BitOffset + long bitOffset = 0; + temp = channel->ToElement()->Attribute("BitOffset"); + if(temp != NULL){ + bitOffset = forte::core::util::strtol(temp, NULL, 16); + } + + // Check CN id, module number and add new IO + if(cnId != currentCnId){ // New CN + currentCnId = cnId; + currentModuleNr = 0; + strcpy(currentModuleId, modId); + currentIoNr = 0; + + m_oModuleListOut.addEntry(ioName, piOffset, bitOffset, currentModuleNr); + m_pProcImageOut->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + else if(m_oModuleListOut.moduleNameExist(ioName)){ // IO name exist => this must be a new module with same brand as another + currentModuleNr++; + strcpy(currentModuleId, modId); + currentIoNr = 0; + + m_oModuleListOut.addEntry(ioName, piOffset, bitOffset, currentModuleNr); + m_pProcImageOut->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + else if(strcmp(modId, currentModuleId) == 0){ // same module ID as IO before => must be same module + + m_pProcImageOut->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + else{ // new module ID => new module + currentModuleNr++; + strcpy(currentModuleId, modId); + currentIoNr = 0; + + m_oModuleListOut.addEntry(ioName, piOffset, bitOffset, currentModuleNr); + m_pProcImageOut->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + + cout << "<< " << currentCnId << ", " << currentModuleNr << ", " << ioName << ", " << currentIoNr << ", " << dSize << ", " << piOffset << ", " << bitOffset << endl; + + delete[] nameStr; + } +} + +void CEplXmlReader::createProcImageIn(TiXmlNode *pa_pProcessImage){ + int currentCnId = -1; + int currentModuleNr = -1; + char currentModuleId[256]; + int currentIoNr = -1; + + TiXmlNode *channel; + for(channel = pa_pProcessImage->FirstChild("Channel"); channel != NULL; channel = channel->NextSibling("Channel")){ + // New IO + currentIoNr++; + + // Get "Name" attribute + const char *ioName = channel->ToElement()->Attribute("Name"); + char *nameStr = new char[strlen(ioName) + 1]; + strcpy(nameStr, ioName); + + // Get CN ID + char* pch = strtok(nameStr, ".CN"); + int cnId = forte::core::util::strtoul(pch,0,10); + + // Get module ID + char* modId = strtok(NULL, "."); + + // Get dataSize + const char *temp = channel->ToElement()->Attribute("dataSize"); + int dSize = forte::core::util::strtoul(temp,0,10); + + // Get PIOffset + temp = channel->ToElement()->Attribute("PIOffset"); + long piOffset = forte::core::util::strtol(temp, NULL, 16); + + // Get BitOffset + long bitOffset = 0; + temp = channel->ToElement()->Attribute("BitOffset"); + if(temp != NULL){ + bitOffset = forte::core::util::strtol(temp, NULL, 16); + } + + // Check CN id, module number and add new IO + if(cnId != currentCnId){ // New CN + currentCnId = cnId; + + currentModuleNr = getModuleNr(ioName); + + strcpy(currentModuleId, modId); + currentIoNr = 0; + + m_oModuleListIn.addEntry(ioName, piOffset, bitOffset, currentModuleNr); + m_pProcImageIn->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + else if(m_oModuleListIn.moduleNameExist(ioName)){ // IO name exist => this must be a new module with same brand as another + + currentModuleNr = getModuleNr(ioName); + + strcpy(currentModuleId, modId); + currentIoNr = 0; + + m_oModuleListIn.addEntry(ioName, piOffset, bitOffset, currentModuleNr); + m_pProcImageIn->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + else if(strcmp(modId, currentModuleId) == 0){ // same module ID as IO before => must be same module + + m_pProcImageIn->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + else{ // new module ID => new module + + currentModuleNr = getModuleNr(ioName); + + strcpy(currentModuleId, modId); + currentIoNr = 0; + + m_oModuleListIn.addEntry(ioName, piOffset, bitOffset, currentModuleNr); + m_pProcImageIn->addEntry(cnId, currentModuleNr, currentIoNr, dSize, piOffset, bitOffset); + + } + + cout << ">> " << currentCnId << ", " << currentModuleNr << ", " << ioName << ", " << currentIoNr << ", " << dSize << ", " << piOffset << ", " << bitOffset << endl; + + delete[] nameStr; + } +} + +int CEplXmlReader::getModuleNr(const char* pa_pchIoId){ + char localCopy[256]; + strcpy(localCopy, pa_pchIoId); + + char dest[256]; + char* pch = strtok(localCopy, "."); + strcpy(dest, pch); + strcat(dest, "."); + pch = strtok(NULL, "."); + strcat(dest, pch); + + int occurences = m_oModuleListIn.getNrOfModules(dest); + int modNr = m_oModuleListOut.getModuleNr(dest, occurences + 1); + if(modNr == -1) + cout << "ShouldNotHappenError" << endl; + + return modNr; +} diff --git a/src/modules/powerlink/EplXmlReader.h b/src/modules/powerlink/EplXmlReader.h new file mode 100644 index 000000000..5f8a84a42 --- /dev/null +++ b/src/modules/powerlink/EplXmlReader.h @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EPLXMLREADER_H_ +#define _EPLXMLREADER_H_ + +#include "ProcessImageMatrix.h" +#include "ModuleList.h" + +class TiXmlNode; + +class CEplXmlReader{ + public: + CEplXmlReader(CProcessImageMatrix* pa_pIn, CProcessImageMatrix* pa_pOut); + ~CEplXmlReader(); + + void setProcessImageIn(CProcessImageMatrix* pa_pIn); + void setProcessImageOut(CProcessImageMatrix* pa_pOut); + + void readXmlFile(const char* pa_pchFileName); + + int getProcessImageIn(); + + private: + CModuleList m_oModuleListOut; + CModuleList m_oModuleListIn; + CProcessImageMatrix* m_pProcImageOut; + CProcessImageMatrix* m_pProcImageIn; + + void createProcImageOut(TiXmlNode* pa_pProcessImage); + void createProcImageIn(TiXmlNode* pa_pProcessImage); + + int getModuleNr(const char* pa_pchIoId); + +}; + +#endif diff --git a/src/modules/powerlink/ModuleList.cpp b/src/modules/powerlink/ModuleList.cpp new file mode 100644 index 000000000..1cbf7cd5d --- /dev/null +++ b/src/modules/powerlink/ModuleList.cpp @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2012, 2014 AIT, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ModuleList.h" +#include + +CModuleList::IoModule::IoModule(const char* pa_pchName, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset, unsigned int pa_nModuleNr) : + m_nPiOffset(pa_nPiOffset), m_nBitOffset(pa_nBitOffset), m_nModuleNr(pa_nModuleNr){ + + m_pchName = new char[strlen(pa_pchName) + 1]; + strcpy(m_pchName, pa_pchName); +} + +CModuleList::IoModule::~IoModule(){ + delete[] m_pchName; +} + +CModuleList::CModuleList() : + m_nNumberOfModules(0){ + +} + +CModuleList::~CModuleList(){ + // Delete modules in list + m_lModules.clearAll(); + +} + +void CModuleList::addEntry(const char* pa_pchName, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset, unsigned int pa_nModuleNr){ + m_lModules.push_back(new IoModule(pa_pchName, pa_nPiOffset, pa_nBitOffset, pa_nModuleNr)); + + m_nNumberOfModules++; +} + +int CModuleList::getModuleNr(const char* pa_pchName, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset){ + + TModuleList::Iterator itEnd(m_lModules.end()); + for(TModuleList::Iterator it(m_lModules.begin()); it != itEnd; ++it){ + if(strcmp(it->m_pchName, pa_pchName) == 0 && it->m_nPiOffset == pa_nPiOffset && it->m_nBitOffset == pa_nBitOffset){ + return it->m_nModuleNr; + } + } + + return -1; +} + +int CModuleList::getModuleNr(const char* pa_pchName, unsigned int pa_nOccurence){ + unsigned int nrOcc = 0; + + TModuleList::Iterator itEnd(m_lModules.end()); + for(TModuleList::Iterator it(m_lModules.begin()); it != itEnd; ++it){ + char* pch = strstr(it->m_pchName, pa_pchName); + if(pch != NULL){ + nrOcc++; + if(nrOcc == pa_nOccurence){ + return it->m_nModuleNr; + } + } + } + + return -1; +} + +int CModuleList::getNrOfModules(const char* pa_pchName){ + int nrMods = 0; + + TModuleList::Iterator itEnd(m_lModules.end()); + for(TModuleList::Iterator it(m_lModules.begin()); it != itEnd; ++it){ + char* pch = strstr(it->m_pchName, pa_pchName); + if(pch != NULL){ + nrMods++; + } + } + + return nrMods; +} + +bool CModuleList::moduleNameExist(const char* pa_pchName){ + + TModuleList::Iterator itEnd(m_lModules.end()); + for(TModuleList::Iterator it(m_lModules.begin()); it != itEnd; ++it){ + if(strcmp(it->m_pchName, pa_pchName) == 0){ + return true; + } + } + + return false; +} diff --git a/src/modules/powerlink/ModuleList.h b/src/modules/powerlink/ModuleList.h new file mode 100644 index 000000000..8b40bb51d --- /dev/null +++ b/src/modules/powerlink/ModuleList.h @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _MODULELIST_H_ +#define _MODULELIST_H_ + +#include + +class CModuleList{ + public: + CModuleList(); + ~CModuleList(); + + void addEntry(const char* pa_pchName, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset, unsigned int pa_nModuleNr); + + int getModuleNr(const char* pa_pchName, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset); + + int getModuleNr(const char* pa_pchName, unsigned int pa_nOccurence); + + int getNrOfModules(const char* pa_pchName); + + bool moduleNameExist(const char* pa_pchName); + + private: + class IoModule{ + public: + IoModule(const char* pa_pchName, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset, unsigned int pa_nModuleNr); + ~IoModule(); + + char* m_pchName; + unsigned int m_nPiOffset; + unsigned int m_nBitOffset; + + unsigned int m_nModuleNr; + }; + + //std::vector m_lModules; + + typedef CSinglyLinkedList TModuleList; + TModuleList m_lModules; + + unsigned int m_nNumberOfModules; +}; + +#endif diff --git a/src/modules/powerlink/POWERLINK_MN.cpp b/src/modules/powerlink/POWERLINK_MN.cpp new file mode 100644 index 000000000..a0716adc6 --- /dev/null +++ b/src/modules/powerlink/POWERLINK_MN.cpp @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "POWERLINK_MN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "POWERLINK_MN_gen.cpp" +#endif + +#include "EplWrapper.h" +#include + +DEFINE_FIRMWARE_FB(FORTE_POWERLINK_MN, g_nStringIdPOWERLINK_MN) + +const CStringDictionary::TStringId FORTE_POWERLINK_MN::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCDC_CFG, g_nStringIdAPP_CFG, g_nStringIdDEV_NAME }; + +const CStringDictionary::TStringId FORTE_POWERLINK_MN::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdSTRING, g_nStringIdSTRING }; + +const CStringDictionary::TStringId FORTE_POWERLINK_MN::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdSTATUS }; + +const CStringDictionary::TStringId FORTE_POWERLINK_MN::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdSTRING }; + +const TForteInt16 FORTE_POWERLINK_MN::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FORTE_POWERLINK_MN::scm_anEIWith[] = { 0, 1, 2, 3, 255 }; +const CStringDictionary::TStringId FORTE_POWERLINK_MN::scm_anEventInputNames[] = { g_nStringIdINIT }; + +const TDataIOID FORTE_POWERLINK_MN::scm_anEOWith[] = { 0, 1, 255 }; +const TForteInt16 FORTE_POWERLINK_MN::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FORTE_POWERLINK_MN::scm_anEventOutputNames[] = { g_nStringIdINITO }; + +const SFBInterfaceSpec FORTE_POWERLINK_MN::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +FORTE_POWERLINK_MN::~FORTE_POWERLINK_MN(){ + shutdownStack(); +} + +void FORTE_POWERLINK_MN::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + + if(QI() == true){ + QO() = QI(); + + CEplStackWrapper* eplStack = &CEplStackWrapper::getInstance(); + + eplStack->waitUntilOperational(false); + eplStack->eplStackInit(APP_CFG().getValue(), CDC_CFG().getValue(), DEV_NAME().getValue()); + + //TODO check if error occured during initialization + + } + else if(QI() == false){ + QO() = QI(); + shutdownStack(); + } + + sendOutputEvent(scm_nEventINITOID); + break; + } +} + +void FORTE_POWERLINK_MN::shutdownStack(){ + CEplStackWrapper::getInstance().eplStackShutdown(); +} + diff --git a/src/modules/powerlink/POWERLINK_MN.h b/src/modules/powerlink/POWERLINK_MN.h new file mode 100644 index 000000000..d043bc819 --- /dev/null +++ b/src/modules/powerlink/POWERLINK_MN.h @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _POWERLINK_MN_H_ +#define _POWERLINK_MN_H_ + +#include +#include +#include + +class FORTE_POWERLINK_MN : public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_POWERLINK_MN) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_STRING &CDC_CFG(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_STRING &APP_CFG(){ + return *static_cast(getDI(2)); + } + ; + + CIEC_STRING &DEV_NAME(){ + return *static_cast(getDI(3)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(1)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 4, 2, 0) + ; + + void executeEvent(int pa_nEIID); + + void shutdownStack(); + + public: + FUNCTION_BLOCK_CTOR(FORTE_POWERLINK_MN){ + }; + + virtual ~FORTE_POWERLINK_MN(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/ProcessImageMatrix.cpp b/src/modules/powerlink/ProcessImageMatrix.cpp new file mode 100644 index 000000000..d67744a72 --- /dev/null +++ b/src/modules/powerlink/ProcessImageMatrix.cpp @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ProcessImageMatrix.h" + +CProcessImageMatrix::CProcessImageMatrix(){ + + m_nBitSize = 0; + m_nNumberOfEntries = 0; + +} + +CProcessImageMatrix::~CProcessImageMatrix(){ + clearAll(); +} + +void CProcessImageMatrix::addEntry(unsigned int pa_nCN, unsigned int pa_nModule, unsigned int pa_nIoId, unsigned int pa_nDataSize, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset){ + + m_lMatrix.push_back(new SChannelEntry(pa_nCN, pa_nModule, pa_nIoId, pa_nDataSize, pa_nPiOffset, pa_nBitOffset)); + + // Check if 8, 16, 32 bit aligned + if((pa_nDataSize % 32 == 0) || (pa_nDataSize % 16 == 0) || (pa_nDataSize % 8 == 0)){ + if(m_nBitSize % pa_nDataSize != 0){ + unsigned long fillBits = pa_nDataSize - (m_nBitSize % pa_nDataSize); + m_nBitSize += fillBits; + } + } + m_nBitSize += pa_nDataSize; + + m_nNumberOfEntries++; +} + +// getEntry: Returns an array with [dataSize, PIOffset, BitOffset] +unsigned int* CProcessImageMatrix::getEntry(unsigned int pa_nCN, unsigned int pa_nModule, unsigned int pa_nIoId){ + static unsigned int data[3] = { 0, 0, 0 }; + + TChannelList::Iterator itEnd = m_lMatrix.end(); + for(TChannelList::Iterator it = m_lMatrix.begin(); it != itEnd; ++it){ + if(it->m_nCN == pa_nCN && it->m_nModuleId == pa_nModule && it->m_nIOid == pa_nIoId){ + data[0] = it->m_nDataSize; + data[1] = it->m_nPIOffset; + data[2] = it->m_nBitOffset; + return data; + } + } + + return NULL; +} + +// getEntry: same as above but returns the values on row "index" +unsigned int* CProcessImageMatrix::getEntry(unsigned int pa_nIndex){ + static unsigned int data[3] = { 0, 0, 0 }; + + if(pa_nIndex < m_nNumberOfEntries){ + TChannelList::Iterator it = m_lMatrix.begin(); + for(unsigned int i = 0; i < pa_nIndex; i++){ + ++it; + } + data[0] = it->m_nDataSize; + data[1] = it->m_nPIOffset; + data[2] = it->m_nBitOffset; + return data; + } + + return NULL; +} + +unsigned int CProcessImageMatrix::getNrOfEntries(){ + return m_nNumberOfEntries; +} + +CProcessImageMatrix* CProcessImageMatrix::getModuleEntries(unsigned int pa_nCN, unsigned int pa_nModule){ + CProcessImageMatrix* newMatrix = NULL; + + TChannelList::Iterator itEnd = m_lMatrix.end(); + for(TChannelList::Iterator it(m_lMatrix.begin()); it != itEnd; ++it){ + if(it->m_nCN == pa_nCN && it->m_nModuleId == pa_nModule){ + if(newMatrix == NULL) + newMatrix = new CProcessImageMatrix(); + + newMatrix->addEntry(it->m_nCN, it->m_nModuleId, it->m_nIOid, it->m_nDataSize, it->m_nPIOffset, it->m_nBitOffset); + } + } + + return newMatrix; +} + +unsigned long CProcessImageMatrix::getProcessImageSize(){ + // Check if the whole matrix is 32 bit aligned + if(m_nBitSize % 32 != 0){ + int fillBits = 32 - (m_nBitSize % 32); + return (unsigned long) (m_nBitSize + fillBits) / 8; + } + return (unsigned long) m_nBitSize / 8; +} + +void CProcessImageMatrix::clearAll(){ + while(!m_lMatrix.isEmpty()){ + delete *(TChannelList::Iterator) m_lMatrix.begin(); + m_lMatrix.pop_front(); + } +} diff --git a/src/modules/powerlink/ProcessImageMatrix.h b/src/modules/powerlink/ProcessImageMatrix.h new file mode 100644 index 000000000..22788eaa3 --- /dev/null +++ b/src/modules/powerlink/ProcessImageMatrix.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _PROCIMAGEMATRIX_H_ +#define _PROCIMAGEMATRIX_H_ + +//#include +#include + +class CProcessImageMatrix{ + public: + CProcessImageMatrix(); + ~CProcessImageMatrix(); + + void addEntry(unsigned int pa_nCN, unsigned int pa_nModule, unsigned int pa_nIoId, unsigned int pa_nDataSize, unsigned int pa_nPiOffset, unsigned int pa_nBitOffset); + + // getEntry: Returns an array with [dataSize, PIOffset, BitOffset] + unsigned int* getEntry(unsigned int pa_nCN, unsigned int pa_nModule, unsigned int pa_nIoId); + unsigned int* getEntry(unsigned int pa_nIndex); + + unsigned int getNrOfEntries(); + + //ProcessImageMatrix* is owned by caller + CProcessImageMatrix* getModuleEntries(unsigned int pa_nCN, unsigned int pa_nModule); + + unsigned long getProcessImageSize(); + + void clearAll(); + + private: + struct SChannelEntry{ + unsigned int m_nCN; + unsigned int m_nModuleId; + unsigned int m_nIOid; + unsigned int m_nDataSize; + unsigned int m_nPIOffset; + unsigned int m_nBitOffset; + + SChannelEntry(unsigned int pa_nCN, unsigned int pa_nModuleId, unsigned int pa_nIOid, unsigned int pa_nDataSize, unsigned int pa_nPIOffset, unsigned int pa_nBitOffset) : + m_nCN(pa_nCN), m_nModuleId(pa_nModuleId), m_nIOid(pa_nIOid), m_nDataSize(pa_nDataSize), m_nPIOffset(pa_nPIOffset), m_nBitOffset(pa_nBitOffset){ + } + ; + + }; + + typedef CSinglyLinkedList TChannelList; + TChannelList m_lMatrix; + + unsigned long m_nBitSize; + + unsigned int m_nNumberOfEntries; +}; + +#endif diff --git a/src/modules/powerlink/X20AI4622.cpp b/src/modules/powerlink/X20AI4622.cpp new file mode 100644 index 000000000..c4954ad7d --- /dev/null +++ b/src/modules/powerlink/X20AI4622.cpp @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren, Thomas Strasser - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20AI4622.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20AI4622_gen.cpp" +#endif + +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20AI4622, g_nStringIdX20AI4622) + +const CStringDictionary::TStringId FORTE_X20AI4622::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID }; + +const CStringDictionary::TStringId FORTE_X20AI4622::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT }; + +const CStringDictionary::TStringId FORTE_X20AI4622::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS, g_nStringIdAI01, g_nStringIdAI02, g_nStringIdAI03, g_nStringIdAI04 }; + +const CStringDictionary::TStringId FORTE_X20AI4622::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING, g_nStringIdINT, g_nStringIdINT, g_nStringIdINT, g_nStringIdINT }; + +const TForteInt16 FORTE_X20AI4622::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20AI4622::scm_anEIWith[] = { 0, 1, 2, 255, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20AI4622::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20AI4622::scm_anEOWith[] = { 0, 1, 2, 255, 2, 3, 4, 5, 6, 0, 255 }; +const TForteInt16 FORTE_X20AI4622::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20AI4622::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20AI4622::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 7, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20AI4622::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Inputs (process inputs) always start with i = 1 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ + short ioVal = 0x0000; + ioVal = *((short*) (it->m_pchCurrentValue)); + *static_cast(getDO(i)) = ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20AI4622::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + short ioVal = 0x0000; + char lowByte; + char highByte; + lowByte = (eplStack.getProcImageOut()[it->m_nPiOffset] & (0xFF << it->m_nBitOffset)) >> it->m_nBitOffset; + highByte = (eplStack.getProcImageOut()[it->m_nPiOffset + 1] & (0xFF << it->m_nBitOffset)) >> it->m_nBitOffset; + ioVal = (short) ((0xFF00 & (highByte << 8))) | (short) (0xFF & lowByte); + + *((short*) (it->m_pchCurrentValue)) = ioVal; + } + + m_oSync.unlock(); +} + diff --git a/src/modules/powerlink/X20AI4622.h b/src/modules/powerlink/X20AI4622.h new file mode 100644 index 000000000..200bc465b --- /dev/null +++ b/src/modules/powerlink/X20AI4622.h @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20AI4622_H_ +#define _X20AI4622_H_ + +#include +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20AI4622 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20AI4622) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + CIEC_INT &AI01(){ + return *static_cast(getDO(3)); + } + ; + + CIEC_INT &AI02(){ + return *static_cast(getDO(4)); + } + ; + + CIEC_INT &AI03(){ + return *static_cast(getDO(5)); + } + ; + + CIEC_INT &AI04(){ + return *static_cast(getDO(6)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(3, 3, 7, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20AI4622){ + }; + + virtual ~FORTE_X20AI4622(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20AO4622.cpp b/src/modules/powerlink/X20AO4622.cpp new file mode 100644 index 000000000..e6a0b98b9 --- /dev/null +++ b/src/modules/powerlink/X20AO4622.cpp @@ -0,0 +1,104 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20AO4622.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20AO4622_gen.cpp" +#endif + +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20AO4622, g_nStringIdX20AO4622) + +const CStringDictionary::TStringId FORTE_X20AO4622::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID, g_nStringIdAO01, g_nStringIdAO02, g_nStringIdAO03, g_nStringIdAO04 }; + +const CStringDictionary::TStringId FORTE_X20AO4622::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT, g_nStringIdINT, g_nStringIdINT, g_nStringIdINT, g_nStringIdINT }; + +const CStringDictionary::TStringId FORTE_X20AO4622::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS }; + +const CStringDictionary::TStringId FORTE_X20AO4622::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING }; + +const TForteInt16 FORTE_X20AO4622::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20AO4622::scm_anEIWith[] = { 0, 1, 2, 255, 3, 4, 5, 6, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20AO4622::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20AO4622::scm_anEOWith[] = { 0, 1, 2, 255, 2, 0, 255 }; +const TForteInt16 FORTE_X20AO4622::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20AO4622::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20AO4622::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 7, scm_anDataInputNames, scm_anDataInputTypeIds, 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20AO4622::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixIn()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Outputs (process inputs) always start with i = 0 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 0; i < moduleIOs->getNrOfEntries(); i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDIs && it != itEnd; i++, ++it){ + short ioVal = *static_cast(getDI(i)); + *((short*) (it->m_pchCurrentValue)) = ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20AO4622::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + short ioVal = *((short*) (it->m_pchCurrentValue)); + char highByte = (char) ((ioVal & 0xFF00) >> 8); + char lowByte = (char) (ioVal & 0x00FF); + (eplStack.getProcImageIn())[it->m_nPiOffset] &= (~(0xFF << it->m_nBitOffset)); + (eplStack.getProcImageIn())[it->m_nPiOffset] |= (lowByte << (it->m_nBitOffset)); + + (eplStack.getProcImageIn())[it->m_nPiOffset + 1] &= (~(0xFF << it->m_nBitOffset)); + (eplStack.getProcImageIn())[it->m_nPiOffset + 1] |= (highByte << (it->m_nBitOffset)); + } + + m_oSync.unlock(); +} diff --git a/src/modules/powerlink/X20AO4622.h b/src/modules/powerlink/X20AO4622.h new file mode 100644 index 000000000..f65affb03 --- /dev/null +++ b/src/modules/powerlink/X20AO4622.h @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20AO4622_H_ +#define _X20AO4622_H_ + +#include +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20AO4622 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20AO4622) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + CIEC_INT &AO01(){ + return *static_cast(getDI(3)); + } + ; + + CIEC_INT &AO02(){ + return *static_cast(getDI(4)); + } + ; + + CIEC_INT &AO03(){ + return *static_cast(getDI(5)); + } + ; + + CIEC_INT &AO04(){ + return *static_cast(getDI(6)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 7, 3, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20AO4622){ + }; + + virtual ~FORTE_X20AO4622(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20AT2402.cpp b/src/modules/powerlink/X20AT2402.cpp new file mode 100644 index 000000000..653ee1cbf --- /dev/null +++ b/src/modules/powerlink/X20AT2402.cpp @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20AT2402.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20AT2402_gen.cpp" +#endif + +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20AT2402, g_nStringIdX20AT2402) + +const CStringDictionary::TStringId FORTE_X20AT2402::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID }; + +const CStringDictionary::TStringId FORTE_X20AT2402::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT }; + +const CStringDictionary::TStringId FORTE_X20AT2402::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS, g_nStringIdT01, g_nStringIdT02 }; + +const CStringDictionary::TStringId FORTE_X20AT2402::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING, g_nStringIdREAL, g_nStringIdREAL }; + +const TForteInt16 FORTE_X20AT2402::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20AT2402::scm_anEIWith[] = { 0, 1, 2, 255, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20AT2402::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20AT2402::scm_anEOWith[] = { 0, 1, 2, 255, 2, 3, 4, 0, 255 }; +const TForteInt16 FORTE_X20AT2402::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20AT2402::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20AT2402::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 5, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20AT2402::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Inputs (process inputs) always start with i = 1 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ + short ioVal = *((short*) (it->m_pchCurrentValue)); + TForteFloat ioValFloat = static_cast(ioVal); + *static_cast(getDO(i)) = ioValFloat / 10; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20AT2402::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + short ioVal = 0x0000; + char lowByte; + char highByte; + lowByte = (eplStack.getProcImageOut()[it->m_nPiOffset] & (0xFF << it->m_nBitOffset)) >> it->m_nBitOffset; + highByte = (eplStack.getProcImageOut()[it->m_nPiOffset + 1] & (0xFF << it->m_nBitOffset)) >> it->m_nBitOffset; + ioVal = (short) ((0xFF00 & (highByte << 8))) | (short) (0xFF & lowByte); + + *((short*) (it->m_pchCurrentValue)) = ioVal; + } + + m_oSync.unlock(); +} + diff --git a/src/modules/powerlink/X20AT2402.h b/src/modules/powerlink/X20AT2402.h new file mode 100644 index 000000000..f71abf56b --- /dev/null +++ b/src/modules/powerlink/X20AT2402.h @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20AT2402_H_ +#define _X20AT2402_H_ + +#include +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20AT2402 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20AT2402) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + CIEC_REAL &T01(){ + return *static_cast(getDO(3)); + } + ; + + CIEC_REAL &T02(){ + return *static_cast(getDO(4)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 5, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20AT2402){ + }; + + virtual ~FORTE_X20AT2402(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20AT4222.cpp b/src/modules/powerlink/X20AT4222.cpp new file mode 100644 index 000000000..50ef7d6c6 --- /dev/null +++ b/src/modules/powerlink/X20AT4222.cpp @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20AT4222.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20AT4222_gen.cpp" +#endif + +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20AT4222, g_nStringIdX20AT4222) + +const CStringDictionary::TStringId FORTE_X20AT4222::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID }; + +const CStringDictionary::TStringId FORTE_X20AT4222::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT }; + +const CStringDictionary::TStringId FORTE_X20AT4222::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS, g_nStringIdT01, g_nStringIdT02, g_nStringIdT03, g_nStringIdT04 }; + +const CStringDictionary::TStringId FORTE_X20AT4222::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING, g_nStringIdREAL, g_nStringIdREAL, g_nStringIdREAL, g_nStringIdREAL }; + +const TForteInt16 FORTE_X20AT4222::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20AT4222::scm_anEIWith[] = { 0, 1, 2, 255, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20AT4222::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20AT4222::scm_anEOWith[] = { 0, 1, 2, 255, 2, 3, 4, 0, 5, 6, 255 }; +const TForteInt16 FORTE_X20AT4222::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20AT4222::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20AT4222::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 7, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20AT4222::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Inputs (process inputs) always start with i = 1 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ + short ioVal = *((short*) (it->m_pchCurrentValue)); + TForteFloat ioValFloat = static_cast(ioVal); + *static_cast(getDO(i)) = ioValFloat / 10; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20AT4222::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + short ioVal = 0x0000; + char lowByte; + char highByte; + lowByte = (eplStack.getProcImageOut()[it->m_nPiOffset] & (0xFF << it->m_nBitOffset)) >> it->m_nBitOffset; + highByte = (eplStack.getProcImageOut()[it->m_nPiOffset + 1] & (0xFF << it->m_nBitOffset)) >> it->m_nBitOffset; + ioVal = (short) ((0xFF00 & (highByte << 8))) | (short) (0xFF & lowByte); + + *((short*) (it->m_pchCurrentValue)) = ioVal; + } + + m_oSync.unlock(); +} + diff --git a/src/modules/powerlink/X20AT4222.h b/src/modules/powerlink/X20AT4222.h new file mode 100644 index 000000000..5d918e487 --- /dev/null +++ b/src/modules/powerlink/X20AT4222.h @@ -0,0 +1,116 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20AT4222_H_ +#define _X20AT4222_H_ + +#include +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20AT4222 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20AT4222) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + CIEC_REAL &T01(){ + return *static_cast(getDO(3)); + } + ; + + CIEC_REAL &T02(){ + return *static_cast(getDO(4)); + } + ; + + CIEC_REAL &T03(){ + return *static_cast(getDO(5)); + } + ; + + CIEC_REAL &T04(){ + return *static_cast(getDO(6)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 7, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20AT4222){ + }; + + virtual ~FORTE_X20AT4222(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20DI4653.cpp b/src/modules/powerlink/X20DI4653.cpp new file mode 100644 index 000000000..09892c759 --- /dev/null +++ b/src/modules/powerlink/X20DI4653.cpp @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DI4653.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20DI4653_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_X20DI4653, g_nStringIdX20DI4653) + +const CStringDictionary::TStringId FORTE_X20DI4653::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID}; + +const CStringDictionary::TStringId FORTE_X20DI4653::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_X20DI4653::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS, g_nStringIdDI01, g_nStringIdDI02, g_nStringIdDI03, g_nStringIdDI04}; + +const CStringDictionary::TStringId FORTE_X20DI4653::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL}; + +const TForteInt16 FORTE_X20DI4653::scm_anEIWithIndexes[] = {0, 4}; +const TDataIOID FORTE_X20DI4653::scm_anEIWith[] = {0, 1, 2, 255, 0, 255}; +const CStringDictionary::TStringId FORTE_X20DI4653::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_X20DI4653::scm_anEOWith[] = {0, 2, 1, 255, 3, 4, 5, 6, 2, 0, 255}; +const TForteInt16 FORTE_X20DI4653::scm_anEOWithIndexes[] = {0, 4, -1}; +const CStringDictionary::TStringId FORTE_X20DI4653::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_X20DI4653::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 7, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_X20DI4653::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Inputs (process inputs) always start with i = 1 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ + bool ioVal = false; + ioVal = *(it->m_pchCurrentValue) != 0x00; + *static_cast(getDO(i)) = ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20DI4653::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + bool ioVal = false; + ioVal = (eplStack.getProcImageOut()[it->m_nPiOffset] & (char) (0x01 << it->m_nBitOffset)) != 0x00; + *(it->m_pchCurrentValue) = (char) ioVal; + } + + m_oSync.unlock(); +} + + + diff --git a/src/modules/powerlink/X20DI4653.h b/src/modules/powerlink/X20DI4653.h new file mode 100644 index 000000000..e1e1ee696 --- /dev/null +++ b/src/modules/powerlink/X20DI4653.h @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DI4653_H_ +#define _X20DI4653_H_ + +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DI4653: public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DI4653) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_USINT &CNID() { + return *static_cast(getDI(1)); + }; + + CIEC_UINT &MODID() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_USINT &CNIDO() { + return *static_cast(getDO(1)); + }; + + CIEC_STRING &STATUS() { + return *static_cast(getDO(2)); + }; + + CIEC_BOOL &DI01() { + return *static_cast(getDO(3)); + }; + + CIEC_BOOL &DI02() { + return *static_cast(getDO(4)); + }; + + CIEC_BOOL &DI03() { + return *static_cast(getDO(5)); + }; + + CIEC_BOOL &DI04() { + return *static_cast(getDO(6)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 7, 0); + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + + SEplMapping m_oEplMapping; + CSyncObject m_oSync; + bool m_bInitOk; + // ... + +public: + FUNCTION_BLOCK_CTOR(FORTE_X20DI4653){ + }; + + virtual ~FORTE_X20DI4653(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/powerlink/X20DI9371.cpp b/src/modules/powerlink/X20DI9371.cpp new file mode 100644 index 000000000..38d4d5859 --- /dev/null +++ b/src/modules/powerlink/X20DI9371.cpp @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DI9371.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20DI9371_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_X20DI9371, g_nStringIdX20DI9371) + +const CStringDictionary::TStringId FORTE_X20DI9371::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID }; + +const CStringDictionary::TStringId FORTE_X20DI9371::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT }; + +const CStringDictionary::TStringId FORTE_X20DI9371::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS, g_nStringIdDI01, g_nStringIdDI02, g_nStringIdDI03, g_nStringIdDI04, g_nStringIdDI05, g_nStringIdDI06, g_nStringIdDI07, g_nStringIdDI08, g_nStringIdDI09, g_nStringIdDI10, g_nStringIdDI11, g_nStringIdDI12 }; + +const CStringDictionary::TStringId FORTE_X20DI9371::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL }; + +const TForteInt16 FORTE_X20DI9371::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20DI9371::scm_anEIWith[] = { 0, 1, 2, 255, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20DI9371::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20DI9371::scm_anEOWith[] = { 0, 2, 1, 255, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 2, 0, 255 }; +const TForteInt16 FORTE_X20DI9371::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20DI9371::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20DI9371::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 15, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20DI9371::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Inputs (process inputs) always start with i = 1 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ + bool ioVal = false; + ioVal = *(it->m_pchCurrentValue) != 0x00; + *static_cast(getDO(i)) = ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20DI9371::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + bool ioVal = false; + ioVal = (eplStack.getProcImageOut()[it->m_nPiOffset] & (char) (0x01 << it->m_nBitOffset)) != 0x00; + *(it->m_pchCurrentValue) = (char) ioVal; + } + + m_oSync.unlock(); +} + diff --git a/src/modules/powerlink/X20DI9371.h b/src/modules/powerlink/X20DI9371.h new file mode 100644 index 000000000..d5b055a90 --- /dev/null +++ b/src/modules/powerlink/X20DI9371.h @@ -0,0 +1,156 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DI9371_H_ +#define _X20DI9371_H_ + +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DI9371 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DI9371) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + CIEC_BOOL &DI01(){ + return *static_cast(getDO(3)); + } + ; + + CIEC_BOOL &DI02(){ + return *static_cast(getDO(4)); + } + ; + + CIEC_BOOL &DI03(){ + return *static_cast(getDO(5)); + } + ; + + CIEC_BOOL &DI04(){ + return *static_cast(getDO(6)); + } + ; + + CIEC_BOOL &DI05(){ + return *static_cast(getDO(7)); + } + ; + + CIEC_BOOL &DI06(){ + return *static_cast(getDO(8)); + } + ; + + CIEC_BOOL &DI07(){ + return *static_cast(getDO(9)); + } + ; + + CIEC_BOOL &DI08(){ + return *static_cast(getDO(10)); + } + ; + + CIEC_BOOL &DI09(){ + return *static_cast(getDO(11)); + } + ; + + CIEC_BOOL &DI10(){ + return *static_cast(getDO(12)); + } + ; + + CIEC_BOOL &DI11(){ + return *static_cast(getDO(13)); + } + ; + + CIEC_BOOL &DI12(){ + return *static_cast(getDO(14)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 15, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20DI9371){ + }; + + virtual ~FORTE_X20DI9371(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20DI9372.cpp b/src/modules/powerlink/X20DI9372.cpp new file mode 100644 index 000000000..d6191a539 --- /dev/null +++ b/src/modules/powerlink/X20DI9372.cpp @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2012 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DI9372.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20DI9372_gen.cpp" +#endif + +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20DI9372, g_nStringIdX20DI9372) + +const CStringDictionary::TStringId FORTE_X20DI9372::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID }; + +const CStringDictionary::TStringId FORTE_X20DI9372::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT }; + +const CStringDictionary::TStringId FORTE_X20DI9372::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS, g_nStringIdDI01, g_nStringIdDI02, g_nStringIdDI03, g_nStringIdDI04, g_nStringIdDI05, g_nStringIdDI06, g_nStringIdDI07, g_nStringIdDI08, g_nStringIdDI09, g_nStringIdDI10, g_nStringIdDI11, g_nStringIdDI12 }; + +const CStringDictionary::TStringId FORTE_X20DI9372::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL }; + +const TForteInt16 FORTE_X20DI9372::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20DI9372::scm_anEIWith[] = { 0, 1, 2, 255, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20DI9372::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20DI9372::scm_anEOWith[] = { 0, 2, 1, 255, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 2, 0, 255 }; +const TForteInt16 FORTE_X20DI9372::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20DI9372::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20DI9372::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 15, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20DI9372::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Inputs (process inputs) always start with i = 1 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ + bool ioVal = false; + ioVal = *(it->m_pchCurrentValue) != 0x00; + *static_cast(getDO(i)) = ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20DI9372::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + bool ioVal = false; + ioVal = (eplStack.getProcImageOut()[it->m_nPiOffset] & (char) (0x01 << it->m_nBitOffset)) != 0x00; + *(it->m_pchCurrentValue) = (char) ioVal; + } + + m_oSync.unlock(); +} diff --git a/src/modules/powerlink/X20DI9372.h b/src/modules/powerlink/X20DI9372.h new file mode 100644 index 000000000..2367f03dc --- /dev/null +++ b/src/modules/powerlink/X20DI9372.h @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DI9372_H_ +#define _X20DI9372_H_ + +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DI9372 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DI9372) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + CIEC_BOOL &DI01(){ + return *static_cast(getDO(3)); + } + ; + + CIEC_BOOL &DI02(){ + return *static_cast(getDO(4)); + } + ; + + CIEC_BOOL &DI03(){ + return *static_cast(getDO(5)); + } + ; + + CIEC_BOOL &DI04(){ + return *static_cast(getDO(6)); + } + ; + + CIEC_BOOL &DI05(){ + return *static_cast(getDO(7)); + } + ; + + CIEC_BOOL &DI06(){ + return *static_cast(getDO(8)); + } + ; + + CIEC_BOOL &DI07(){ + return *static_cast(getDO(9)); + } + ; + + CIEC_BOOL &DI08(){ + return *static_cast(getDO(10)); + } + ; + + CIEC_BOOL &DI09(){ + return *static_cast(getDO(11)); + } + ; + + CIEC_BOOL &DI10(){ + return *static_cast(getDO(12)); + } + ; + + CIEC_BOOL &DI11(){ + return *static_cast(getDO(13)); + } + ; + + CIEC_BOOL &DI12(){ + return *static_cast(getDO(14)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 15, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20DI9372){ + }; + + virtual ~FORTE_X20DI9372(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20DI937X.cpp b/src/modules/powerlink/X20DI937X.cpp new file mode 100644 index 000000000..081349447 --- /dev/null +++ b/src/modules/powerlink/X20DI937X.cpp @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DI937X.h" + +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20DI937X, g_nStringIdX20DI937X) + +const CStringDictionary::TStringId FORTE_X20DI937X::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID }; + +const CStringDictionary::TStringId FORTE_X20DI937X::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT }; + +const CStringDictionary::TStringId FORTE_X20DI937X::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS, g_nStringIdDI01, g_nStringIdDI02, g_nStringIdDI03, g_nStringIdDI04, g_nStringIdDI05, g_nStringIdDI06, g_nStringIdDI07, g_nStringIdDI08, g_nStringIdDI09, g_nStringIdDI10, g_nStringIdDI11, g_nStringIdDI12 }; + +const CStringDictionary::TStringId FORTE_X20DI937X::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL }; + +const TForteInt16 FORTE_X20DI937X::scm_anEIWithIndexes[] = { 0, -1, -1 }; +const TDataIOID FORTE_X20DI937X::scm_anEIWith[] = { 0, 1, 2, 255 }; +const CStringDictionary::TStringId FORTE_X20DI937X::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ, g_nStringIdRSP }; + +const TDataIOID FORTE_X20DI937X::scm_anEOWith[] = { 0, 2, 1, 255, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 255, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 2, 255 }; +const TForteInt16 FORTE_X20DI937X::scm_anEOWithIndexes[] = { 0, 4, 18, -1 }; +const CStringDictionary::TStringId FORTE_X20DI937X::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF, g_nStringIdIND }; + +const SFBInterfaceSpec FORTE_X20DI937X::scm_stFBInterfaceSpec = { 3, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 3, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, 15, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20DI937X::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: { + //#error add code for INIT event! + + EplStackWrapper &eplStack = EplStackWrapper::getInstance(); + + // Get settings for intputs + ProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixOut()->getModuleEntries(CNID(), MODID()); + + // Inputs (process inputs) always start with i = 1 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 1; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_anDataSizes[i] = moduleIOs->getEntry(i)[0]; + m_oEplMapping.m_anPiOffsets[i] = moduleIOs->getEntry(i)[1]; + m_oEplMapping.m_anBitOffsets[i] = moduleIOs->getEntry(i)[2]; + + char* newVal = new char[m_oEplMapping.m_anDataSizes[i]](); + m_oEplMapping.m_lCurrentValues.push_back(newVal); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + } + case scm_nEventREQID: { + m_oSync.lock(); + CSinglyLinkedList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + CSinglyLinkedList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, ++it){ + bool ioVal = false; + ioVal = (bool) **it; + *static_cast(getDO(i)) = ioVal; + } + m_oSync.unlock(); + + sendOutputEvent(scm_nEventCNFID); + break; + } + case scm_nEventRSPID: + break; + } +} + +void FORTE_X20DI937X::cnSynchCallback(){ + EplStackWrapper &eplStack = EplStackWrapper::getInstance(); + + m_oSync.lock(); + + CSinglyLinkedList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + CSinglyLinkedList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3, j = 1; i < m_pstInterfaceSpec->m_nNumDOs && it != itEnd; i++, j++, ++it){ + bool ioVal = false; + ioVal = (bool) (eplStack.getProcImageOut()[m_oEplMapping.m_anPiOffsets[j]] & (char) (0x01 << m_oEplMapping.m_anBitOffsets[j])); + **it = (char) ioVal; + } + + m_oSync.unlock(); +} diff --git a/src/modules/powerlink/X20DI937X.h b/src/modules/powerlink/X20DI937X.h new file mode 100644 index 000000000..4418e9002 --- /dev/null +++ b/src/modules/powerlink/X20DI937X.h @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DI937X_H_ +#define _X20DI937X_H_ + +#include +#include +#include +#include +#include + +#include +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DI937X : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DI937X) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + CIEC_BOOL &DI01(){ + return *static_cast(getDO(3)); + } + ; + + CIEC_BOOL &DI02(){ + return *static_cast(getDO(4)); + } + ; + + CIEC_BOOL &DI03(){ + return *static_cast(getDO(5)); + } + ; + + CIEC_BOOL &DI04(){ + return *static_cast(getDO(6)); + } + ; + + CIEC_BOOL &DI05(){ + return *static_cast(getDO(7)); + } + ; + + CIEC_BOOL &DI06(){ + return *static_cast(getDO(8)); + } + ; + + CIEC_BOOL &DI07(){ + return *static_cast(getDO(9)); + } + ; + + CIEC_BOOL &DI08(){ + return *static_cast(getDO(10)); + } + ; + + CIEC_BOOL &DI09(){ + return *static_cast(getDO(11)); + } + ; + + CIEC_BOOL &DI10(){ + return *static_cast(getDO(12)); + } + ; + + CIEC_BOOL &DI11(){ + return *static_cast(getDO(13)); + } + ; + + CIEC_BOOL &DI12(){ + return *static_cast(getDO(14)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TEventID scm_nEventRSPID = 2; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TEventID scm_nEventINDID = 2; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(3, 3, 15, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + + SEplMapping m_oEplMapping;CSyncObject m_oSync; + + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20DI937X){ + }; + + virtual ~FORTE_X20DI937X(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20DO4623.cpp b/src/modules/powerlink/X20DO4623.cpp new file mode 100644 index 000000000..1b2d04130 --- /dev/null +++ b/src/modules/powerlink/X20DO4623.cpp @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DO4623.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20DO4623_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_X20DO4623, g_nStringIdX20DO4623) + +const CStringDictionary::TStringId FORTE_X20DO4623::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID, g_nStringIdDO01, g_nStringIdDO02, g_nStringIdDO03, g_nStringIdDO04}; + +const CStringDictionary::TStringId FORTE_X20DO4623::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_X20DO4623::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_X20DO4623::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING}; + +const TForteInt16 FORTE_X20DO4623::scm_anEIWithIndexes[] = {0, 4}; +const TDataIOID FORTE_X20DO4623::scm_anEIWith[] = {0, 1, 2, 255, 3, 4, 5, 6, 0, 255}; +const CStringDictionary::TStringId FORTE_X20DO4623::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_X20DO4623::scm_anEOWith[] = {0, 2, 1, 255, 2, 0, 255}; +const TForteInt16 FORTE_X20DO4623::scm_anEOWithIndexes[] = {0, 4, -1}; +const CStringDictionary::TStringId FORTE_X20DO4623::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_X20DO4623::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 7, scm_anDataInputNames, scm_anDataInputTypeIds, + 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_X20DO4623::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixIn()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Outputs (process inputs) always start with i = 0 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 0; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDIs && it != itEnd; i++, ++it){ + bool ioVal = *static_cast(getDI(i)); + *(it->m_pchCurrentValue) = (char) ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20DO4623::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + bool ioVal = *(it->m_pchCurrentValue) != 0x00; + (eplStack.getProcImageIn())[it->m_nPiOffset] &= (char) (~(0x01 << it->m_nBitOffset)); + (eplStack.getProcImageIn())[it->m_nPiOffset] |= (char) (ioVal << it->m_nBitOffset); + } + + m_oSync.unlock(); +} + + + diff --git a/src/modules/powerlink/X20DO4623.h b/src/modules/powerlink/X20DO4623.h new file mode 100644 index 000000000..b0a6898ad --- /dev/null +++ b/src/modules/powerlink/X20DO4623.h @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DO4623_H_ +#define _X20DO4623_H_ + +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DO4623: public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DO4623) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_USINT &CNID() { + return *static_cast(getDI(1)); + }; + + CIEC_UINT &MODID() { + return *static_cast(getDI(2)); + }; + + CIEC_BOOL &DO01() { + return *static_cast(getDI(3)); + }; + + CIEC_BOOL &DO02() { + return *static_cast(getDI(4)); + }; + + CIEC_BOOL &DO03() { + return *static_cast(getDI(5)); + }; + + CIEC_BOOL &DO04() { + return *static_cast(getDI(6)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_USINT &CNIDO() { + return *static_cast(getDO(1)); + }; + + CIEC_STRING &STATUS() { + return *static_cast(getDO(2)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 7, 3, 0); + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping; + CSyncObject m_oSync; + bool m_bInitOk; + // ... + +public: + FUNCTION_BLOCK_CTOR(FORTE_X20DO4623){ + }; + + virtual ~FORTE_X20DO4623(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/powerlink/X20DO4649.cpp b/src/modules/powerlink/X20DO4649.cpp new file mode 100644 index 000000000..268ba154a --- /dev/null +++ b/src/modules/powerlink/X20DO4649.cpp @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DO4649.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20DO4649_gen.cpp" +#endif + +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20DO4649, g_nStringIdX20DO4649) + +const CStringDictionary::TStringId FORTE_X20DO4649::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID, g_nStringIdDO01, g_nStringIdDO02, g_nStringIdDO03, g_nStringIdDO04 }; + +const CStringDictionary::TStringId FORTE_X20DO4649::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL }; + +const CStringDictionary::TStringId FORTE_X20DO4649::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS }; + +const CStringDictionary::TStringId FORTE_X20DO4649::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING }; + +const TForteInt16 FORTE_X20DO4649::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20DO4649::scm_anEIWith[] = { 0, 1, 2, 255, 3, 4, 5, 6, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20DO4649::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20DO4649::scm_anEOWith[] = { 0, 2, 1, 255, 2, 0, 255 }; +const TForteInt16 FORTE_X20DO4649::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20DO4649::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20DO4649::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 7, scm_anDataInputNames, scm_anDataInputTypeIds, 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20DO4649::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixIn()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Outputs (process inputs) always start with i = 0 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 0; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDIs && it != itEnd; i++, ++it){ + bool ioVal = *static_cast(getDI(i)); + *(it->m_pchCurrentValue) = (char) ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20DO4649::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + bool ioVal = *(it->m_pchCurrentValue) != 0x00; + (eplStack.getProcImageIn())[it->m_nPiOffset] &= (char) (~(0x01 << it->m_nBitOffset)); + (eplStack.getProcImageIn())[it->m_nPiOffset] |= (char) (ioVal << it->m_nBitOffset); + } + + m_oSync.unlock(); +} + diff --git a/src/modules/powerlink/X20DO4649.h b/src/modules/powerlink/X20DO4649.h new file mode 100644 index 000000000..2ccd1faa2 --- /dev/null +++ b/src/modules/powerlink/X20DO4649.h @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DO4649_H_ +#define _X20DO4649_H_ + +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DO4649 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DO4649) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + CIEC_BOOL &DO01(){ + return *static_cast(getDI(3)); + } + ; + + CIEC_BOOL &DO02(){ + return *static_cast(getDI(4)); + } + ; + + CIEC_BOOL &DO03(){ + return *static_cast(getDI(5)); + } + ; + + CIEC_BOOL &DO04(){ + return *static_cast(getDI(6)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 7, 3, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20DO4649){ + }; + + virtual ~FORTE_X20DO4649(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20DO9321.cpp b/src/modules/powerlink/X20DO9321.cpp new file mode 100644 index 000000000..149ce889c --- /dev/null +++ b/src/modules/powerlink/X20DO9321.cpp @@ -0,0 +1,100 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DO9321.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20DO9321_gen.cpp" +#endif + +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20DO9321, g_nStringIdX20DO9321) + +const CStringDictionary::TStringId FORTE_X20DO9321::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID, g_nStringIdDO01, g_nStringIdDO02, g_nStringIdDO03, g_nStringIdDO04, g_nStringIdDO05, g_nStringIdDO06, g_nStringIdDO07, g_nStringIdDO08, g_nStringIdDO09, g_nStringIdDO10, g_nStringIdDO11, g_nStringIdDO12 }; + +const CStringDictionary::TStringId FORTE_X20DO9321::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL }; + +const CStringDictionary::TStringId FORTE_X20DO9321::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS }; + +const CStringDictionary::TStringId FORTE_X20DO9321::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING }; + +const TForteInt16 FORTE_X20DO9321::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20DO9321::scm_anEIWith[] = { 0, 1, 2, 255, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20DO9321::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20DO9321::scm_anEOWith[] = { 0, 2, 1, 255, 2, 0, 255 }; +const TForteInt16 FORTE_X20DO9321::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20DO9321::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20DO9321::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 15, scm_anDataInputNames, scm_anDataInputTypeIds, 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20DO9321::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixIn()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Outputs (process inputs) always start with i = 0 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 0; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDIs && it != itEnd; i++, ++it){ + bool ioVal = *static_cast(getDI(i)); + *(it->m_pchCurrentValue) = (char) ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20DO9321::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + bool ioVal = *(it->m_pchCurrentValue) != 0x00; + (eplStack.getProcImageIn())[it->m_nPiOffset] &= (char) (~(0x01 << it->m_nBitOffset)); + (eplStack.getProcImageIn())[it->m_nPiOffset] |= (char) (ioVal << it->m_nBitOffset); + } + + m_oSync.unlock(); +} + diff --git a/src/modules/powerlink/X20DO9321.h b/src/modules/powerlink/X20DO9321.h new file mode 100644 index 000000000..e7c950643 --- /dev/null +++ b/src/modules/powerlink/X20DO9321.h @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DO9321_H_ +#define _X20DO9321_H_ + +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DO9321 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DO9321) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + CIEC_BOOL &DO01(){ + return *static_cast(getDI(3)); + } + ; + + CIEC_BOOL &DO02(){ + return *static_cast(getDI(4)); + } + ; + + CIEC_BOOL &DO03(){ + return *static_cast(getDI(5)); + } + ; + + CIEC_BOOL &DO04(){ + return *static_cast(getDI(6)); + } + ; + + CIEC_BOOL &DO05(){ + return *static_cast(getDI(7)); + } + ; + + CIEC_BOOL &DO06(){ + return *static_cast(getDI(8)); + } + ; + + CIEC_BOOL &DO07(){ + return *static_cast(getDI(9)); + } + ; + + CIEC_BOOL &DO08(){ + return *static_cast(getDI(10)); + } + ; + + CIEC_BOOL &DO09(){ + return *static_cast(getDI(11)); + } + ; + + CIEC_BOOL &DO10(){ + return *static_cast(getDI(12)); + } + ; + + CIEC_BOOL &DO11(){ + return *static_cast(getDI(13)); + } + ; + + CIEC_BOOL &DO12(){ + return *static_cast(getDI(14)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 15, 3, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20DO9321){ + }; + + virtual ~FORTE_X20DO9321(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/X20DO9322.cpp b/src/modules/powerlink/X20DO9322.cpp new file mode 100644 index 000000000..1658275db --- /dev/null +++ b/src/modules/powerlink/X20DO9322.cpp @@ -0,0 +1,98 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "X20DO9322.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "X20DO9322_gen.cpp" +#endif + +#include "EplWrapper.h" +#include "ProcessImageMatrix.h" + +DEFINE_FIRMWARE_FB(FORTE_X20DO9322, g_nStringIdX20DO9322) + +const CStringDictionary::TStringId FORTE_X20DO9322::scm_anDataInputNames[] = { g_nStringIdQI, g_nStringIdCNID, g_nStringIdMODID, g_nStringIdDO01, g_nStringIdDO02, g_nStringIdDO03, g_nStringIdDO04, g_nStringIdDO05, g_nStringIdDO06, g_nStringIdDO07, g_nStringIdDO08, g_nStringIdDO09, g_nStringIdDO10, g_nStringIdDO11, g_nStringIdDO12 }; + +const CStringDictionary::TStringId FORTE_X20DO9322::scm_anDataInputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdUINT, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL }; + +const CStringDictionary::TStringId FORTE_X20DO9322::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdCNIDO, g_nStringIdSTATUS }; + +const CStringDictionary::TStringId FORTE_X20DO9322::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdUSINT, g_nStringIdSTRING }; + +const TForteInt16 FORTE_X20DO9322::scm_anEIWithIndexes[] = { 0, 4 }; +const TDataIOID FORTE_X20DO9322::scm_anEIWith[] = { 0, 1, 2, 255, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 255 }; +const CStringDictionary::TStringId FORTE_X20DO9322::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TDataIOID FORTE_X20DO9322::scm_anEOWith[] = { 0, 2, 1, 255, 2, 0, 255 }; +const TForteInt16 FORTE_X20DO9322::scm_anEOWithIndexes[] = { 0, 4, -1 }; +const CStringDictionary::TStringId FORTE_X20DO9322::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_X20DO9322::scm_stFBInterfaceSpec = { 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 15, scm_anDataInputNames, scm_anDataInputTypeIds, 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, 0, 0 }; + +void FORTE_X20DO9322::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(QI() == true){ + m_bInitOk = false; + + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + // Get settings for intputs + CProcessImageMatrix* moduleIOs = eplStack.getProcessImageMatrixIn()->getModuleEntries(CNID(), MODID()); + + if(moduleIOs){ + // Outputs (process inputs) always start with i = 0 + // Check xap.xml if a BitUnused is present + for(unsigned int i = 0; i < moduleIOs->getNrOfEntries() - 1; i++){ + m_oEplMapping.m_lCurrentValues.push_back(new SEplMapping::SEplMappingValues(moduleIOs->getEntry(i)[0], moduleIOs->getEntry(i)[1], moduleIOs->getEntry(i)[2])); + } + delete moduleIOs; + + eplStack.registerCallback((IEplCNCallback*) this); + + m_bInitOk = true; + } + } + QO() = QI(); + CNIDO() = CNID(); + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(QI() == true && m_bInitOk){ + m_oSync.lock(); + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(int i = 3; i < m_pstInterfaceSpec->m_nNumDIs && it != itEnd; i++, ++it){ + bool ioVal = *static_cast(getDI(i)); + *(it->m_pchCurrentValue) = (char) ioVal; + } + m_oSync.unlock(); + } + QO() = QI(); + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_X20DO9322::cnSynchCallback(){ + CEplStackWrapper &eplStack = CEplStackWrapper::getInstance(); + + m_oSync.lock(); + + SEplMapping::TEplMappingList::Iterator itEnd = m_oEplMapping.m_lCurrentValues.end(); + SEplMapping::TEplMappingList::Iterator it = m_oEplMapping.m_lCurrentValues.begin(); + for(it; it != itEnd; ++it){ + bool ioVal = *(it->m_pchCurrentValue) != 0x00; + (eplStack.getProcImageIn())[it->m_nPiOffset] &= (char) (~(0x01 << it->m_nBitOffset)); + (eplStack.getProcImageIn())[it->m_nPiOffset] |= (char) (ioVal << it->m_nBitOffset); + } + + m_oSync.unlock(); +} diff --git a/src/modules/powerlink/X20DO9322.h b/src/modules/powerlink/X20DO9322.h new file mode 100644 index 000000000..6793f69b3 --- /dev/null +++ b/src/modules/powerlink/X20DO9322.h @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2012 AIT + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Filip Andren - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _X20DO9322_H_ +#define _X20DO9322_H_ + +#include +#include +#include +#include +#include + +#include "EplCNCallback.h" +#include "EplWrapper.h" + +class FORTE_X20DO9322 : public CFunctionBlock, public IEplCNCallback{ + DECLARE_FIRMWARE_FB(FORTE_X20DO9322) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + ; + + CIEC_USINT &CNID(){ + return *static_cast(getDI(1)); + } + ; + + CIEC_UINT &MODID(){ + return *static_cast(getDI(2)); + } + ; + + CIEC_BOOL &DO01(){ + return *static_cast(getDI(3)); + } + ; + + CIEC_BOOL &DO02(){ + return *static_cast(getDI(4)); + } + ; + + CIEC_BOOL &DO03(){ + return *static_cast(getDI(5)); + } + ; + + CIEC_BOOL &DO04(){ + return *static_cast(getDI(6)); + } + ; + + CIEC_BOOL &DO05(){ + return *static_cast(getDI(7)); + } + ; + + CIEC_BOOL &DO06(){ + return *static_cast(getDI(8)); + } + ; + + CIEC_BOOL &DO07(){ + return *static_cast(getDI(9)); + } + ; + + CIEC_BOOL &DO08(){ + return *static_cast(getDI(10)); + } + ; + + CIEC_BOOL &DO09(){ + return *static_cast(getDI(11)); + } + ; + + CIEC_BOOL &DO10(){ + return *static_cast(getDI(12)); + } + ; + + CIEC_BOOL &DO11(){ + return *static_cast(getDI(13)); + } + ; + + CIEC_BOOL &DO12(){ + return *static_cast(getDI(14)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_USINT &CNIDO(){ + return *static_cast(getDO(1)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(2)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 15, 3, 0) + ; + + void executeEvent(int pa_nEIID); + + // Variables for mapping between inputs and POWERLINK stack + SEplMapping m_oEplMapping;CSyncObject m_oSync; + bool m_bInitOk; + // ... + + public: + FUNCTION_BLOCK_CTOR(FORTE_X20DO9322){ + }; + + virtual ~FORTE_X20DO9322(){}; + + void cnSynchCallback(); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/powerlink/readme.txt b/src/modules/powerlink/readme.txt new file mode 100644 index 000000000..ef7c87b16 --- /dev/null +++ b/src/modules/powerlink/readme.txt @@ -0,0 +1,22 @@ +openPOWERLINK interface for FORTE + +Instructions + +Prerequisits +The following is needed in order to use openPOWERLINK with FORTE: + + - openPOWERLINK V1.8.0 + - TinyXML + +To use openPOWERLINK download openPOWERLINK V1.8.0 from Sourceforge (http://sourceforge.net/projects/openpowerlink/). The stack should be compiled using at least the following options in CMake: + + - CFG_POWERLINK_CHM + - CFG_POWERLINK_PROCESS_IMAGE + - CFG_X86_WINDOWS_DLL (only available on Windows) + +If compiled on Windows the resulting DLL and LIB must be copied to the main openPOWERLINK-V1.8.0 folder. + +TinyXML can be downloaded from http://sourceforge.net/projects/tinyxml/. + +Configure FORTE +Check FORTE_MODULE_POWERLINK and set FORTE_MODULE_POWERLINK_LIB_DIR to [OPENPOWERLINK-V1.08.0_HOME] and FORTE_MODULE_POWERLINK_TINYXML_DIR to the directory where you unpacked TinyXML. diff --git a/src/modules/raspberry_sps/CMakeLists.txt b/src/modules/raspberry_sps/CMakeLists.txt new file mode 100644 index 000000000..2d64d6beb --- /dev/null +++ b/src/modules/raspberry_sps/CMakeLists.txt @@ -0,0 +1,27 @@ +#******************************************************************************* +# * Copyright (c) 2015 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Gerd Kainz, Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +forte_add_module(Raspberry-SPS "Interacting with GPIOs Raspberry SPS") + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +####################################################### +# i2c-dev +####################################################### + + +forte_add_sourcefile_hcpp(../../stdfblib/io/IX) +forte_add_sourcefile_hcpp( ../../stdfblib/io/QX) +forte_add_sourcefile_hcpp(../../stdfblib/io/IW) +forte_add_sourcefile_hcpp( ../../stdfblib/io/QW) + +forte_add_sourcefile_hcpp(processinterface) + diff --git a/src/modules/raspberry_sps/processinterface.cpp b/src/modules/raspberry_sps/processinterface.cpp new file mode 100644 index 000000000..b0949a50d --- /dev/null +++ b/src/modules/raspberry_sps/processinterface.cpp @@ -0,0 +1,183 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "processinterface.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +const char * const CProcessInterface::scmInitDeinitOK = "OK"; +const char * const CProcessInterface::scmNotInitialised = "Not initialised"; + +CProcessInterface::CProcessInterface(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData) : + CProcessInterfaceBase(paSrcRes, paInterfaceSpec, paInstanceNameId, paFBConnData, paFBVarsData), mFd(-1), mDeviceAddress(-1), mValueAddress(-1){ +} + +CProcessInterface::~CProcessInterface(){ +} + +bool CProcessInterface::initialise(bool paInput){ + char path[scmBuffer]; + unsigned long funcs; + char * element; + int i2CAdapter; + + strcpy(path, PARAMS().getValue()); + element = strtok(path, "."); + if(NULL == element){ + STATUS() = scmNotInitialised; + return false; + } + else{ + CIEC_INT param; + param.fromString(element); + i2CAdapter = param; + } + element = strtok(NULL, "."); + if(NULL == element){ + STATUS() = scmNotInitialised; + return false; + } + else{ + CIEC_INT param; + param.fromString(element); + mDeviceAddress = param; + } + element = strtok(NULL, "."); + if(NULL == element){ + STATUS() = scmNotInitialised; + return false; + } + else{ + CIEC_INT param; + param.fromString(element); + mValueAddress = param; + } + + snprintf(path, scmBuffer, "/dev/i2c-%d", i2CAdapter); + mFd = open(path, O_RDWR); + if(mFd < 0){ + STATUS() = scmNotInitialised; + return false; + } + + if(ioctl(mFd, I2C_FUNCS, &funcs) < 0){ + STATUS() = scmNotInitialised; + return false; + } + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = scmNotInitialised; + return false; + } + + STATUS() = scmInitDeinitOK; + return true; +} + +bool CProcessInterface::deinitialise(){ + close(mFd); + + STATUS() = scmInitDeinitOK; + return true; +} + +bool CProcessInterface::readPin(){ + int res; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = "Kann net lesen"; + return false; + } + + res = i2c_smbus_read_byte(mFd); + if(res < 0){ + STATUS() = "Kann net lesen"; + return false; + } + + IN_X() = (!(res & (1 << mValueAddress))) ? true : false; + + STATUS() = "Konnte lesen"; + return true; +} + +bool CProcessInterface::writePin(){ + int res; + uint8_t byteValue; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + + byteValue = i2c_smbus_read_byte(mFd); + if(!OUT_X()){ + byteValue = byteValue | (uint8_t) (1 << mValueAddress); + } + else{ + byteValue = byteValue & (uint8_t) (~(1 << mValueAddress)); + } + res = i2c_smbus_write_byte(mFd, byteValue); + if(res < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + STATUS() = "Konnte lesen"; + return true; +} + +bool CProcessInterface::readWord(){ + int res; + uint8_t buffer[3]; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0) + { + STATUS() = "Kann net lesen"; + return false; + } + + res = i2c_smbus_read_i2c_block_data(mFd, (uint8_t)mValueAddress, 3, buffer); + if (res < 0) + { + STATUS() = "Kann net lesen"; + return false; + } + IN_W() = static_cast(static_cast(buffer[2] << 8) | static_cast(buffer[1])); + STATUS() = "Konnte lesen"; + return true; +} + +bool CProcessInterface::writeWord(){ + int res; + + if(ioctl(mFd, I2C_SLAVE, mDeviceAddress) < 0) + { + STATUS() = "Kann net schreiben"; + return false; + } + + res = i2c_smbus_write_word_data(mFd, mValueAddress, (uint16_t)OUT_W()); + if (res < 0) + { + STATUS() = "Kann net schreiben"; + return false; + } + STATUS() = "Konnte schreiben"; + return true; +} diff --git a/src/modules/raspberry_sps/processinterface.h b/src/modules/raspberry_sps/processinterface.h new file mode 100644 index 000000000..b69af3c57 --- /dev/null +++ b/src/modules/raspberry_sps/processinterface.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _PROCESSINTERFACE_H_ +#define _PROCESSINTERFACE_H_ + +#include <../../stdfblib/io/processinterfacebase.h> +#include +#include +#include + +class CProcessInterface : public CProcessInterfaceBase{ + +public: + CProcessInterface(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, + const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData); + virtual ~CProcessInterface(); + +protected: + bool initialise(bool paInput); + bool deinitialise(); + bool writePin(); + bool readPin(); + bool writeWord(); + bool readWord(); + +private: + const static int scmBuffer = 100; + + int mFd; + int mDeviceAddress; + int mValueAddress; + + static const char * const scmInitDeinitOK; + static const char * const scmNotInitialised; +}; + +#endif /* _PROCESSINTERFACE_H_ */ diff --git a/src/modules/reconfiguration/CMakeLists.txt b/src/modules/reconfiguration/CMakeLists.txt new file mode 100644 index 000000000..f25161186 --- /dev/null +++ b/src/modules/reconfiguration/CMakeLists.txt @@ -0,0 +1,19 @@ +#******************************************************************************* +# * Copyright (c) 2014 Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Matthias Plasch - initial API and implementation and/or initial documentation +# *******************************************************************************/ + + +forte_add_module(RECONFIGURATION "FORTE Online Reconfiguration") + +############################################################################# +# FORTE Reconfiguration FBs +############################################################################# +forte_add_sourcefile_hcpp(EC_KILL_ELEM EC_SET_EVT EC_START_ELEM EC_STOP_ELEM) +forte_add_sourcefile_hcpp(ST_CREATE_CONN ST_CREATE_FB ST_DEL_CONN ST_DEL_FB ST_REC_CONN ST_SET_PARM) \ No newline at end of file diff --git a/src/modules/reconfiguration/EC_KILL_ELEM.cpp b/src/modules/reconfiguration/EC_KILL_ELEM.cpp new file mode 100644 index 000000000..f2008a414 --- /dev/null +++ b/src/modules/reconfiguration/EC_KILL_ELEM.cpp @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EC_KILL_ELEM.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "EC_KILL_ELEM_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_EC_KILL_ELEM, g_nStringIdEC_KILL_ELEM) + +const CStringDictionary::TStringId FORTE_EC_KILL_ELEM::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdELEM_NAME, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_EC_KILL_ELEM::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_EC_KILL_ELEM::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_EC_KILL_ELEM::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_EC_KILL_ELEM::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_EC_KILL_ELEM::scm_anEIWith[] = {1, 2, 0, 255}; +const CStringDictionary::TStringId FORTE_EC_KILL_ELEM::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_EC_KILL_ELEM::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_EC_KILL_ELEM::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_EC_KILL_ELEM::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_EC_KILL_ELEM::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_EC_KILL_ELEM::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_EC_KILL_ELEM::executeRQST(void){ + forte::core::SManagementCMD theCommand; + + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(ELEM_NAME().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Kill; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} + + diff --git a/src/modules/reconfiguration/EC_KILL_ELEM.h b/src/modules/reconfiguration/EC_KILL_ELEM.h new file mode 100644 index 000000000..f827765c2 --- /dev/null +++ b/src/modules/reconfiguration/EC_KILL_ELEM.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EC_KILL_ELEM_H_ +#define _EC_KILL_ELEM_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_EC_KILL_ELEM: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_EC_KILL_ELEM) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &ELEM_NAME() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 3, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_EC_KILL_ELEM), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_EC_KILL_ELEM(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/EC_SET_EVT.cpp b/src/modules/reconfiguration/EC_SET_EVT.cpp new file mode 100644 index 000000000..c795042a4 --- /dev/null +++ b/src/modules/reconfiguration/EC_SET_EVT.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EC_SET_EVT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "EC_SET_EVT_gen.cpp" +#endif +#include "DEV_MGR.h" +#include +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_EC_SET_EVT, g_nStringIdEC_SET_EVT) + +const CStringDictionary::TStringId FORTE_EC_SET_EVT::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdFB_NAME, g_nStringIdFB_EVENT_IO, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_EC_SET_EVT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_EC_SET_EVT::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_EC_SET_EVT::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_EC_SET_EVT::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_EC_SET_EVT::scm_anEIWith[] = {0, 3, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_EC_SET_EVT::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_EC_SET_EVT::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FORTE_EC_SET_EVT::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_EC_SET_EVT::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_EC_SET_EVT::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_EC_SET_EVT::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()){ + executeRQST(); + }else{ + STATUS() = "NOT Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_EC_SET_EVT::executeRQST(void){ + forte::core::SManagementCMD theCommand; + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(FB_NAME().getValue())); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(FB_EVENT_IO().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Monitoring_Trigger_Event; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} + + + diff --git a/src/modules/reconfiguration/EC_SET_EVT.h b/src/modules/reconfiguration/EC_SET_EVT.h new file mode 100644 index 000000000..0f0ee50ac --- /dev/null +++ b/src/modules/reconfiguration/EC_SET_EVT.h @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EC_SET_EVT_H_ +#define _EC_SET_EVT_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_EC_SET_EVT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_EC_SET_EVT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &FB_NAME() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &FB_EVENT_IO() { + return *static_cast(getDI(2)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + //! The device the block is contained in + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 4, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_EC_SET_EVT), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_EC_SET_EVT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/EC_START_ELEM.cpp b/src/modules/reconfiguration/EC_START_ELEM.cpp new file mode 100644 index 000000000..cb17f3992 --- /dev/null +++ b/src/modules/reconfiguration/EC_START_ELEM.cpp @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EC_START_ELEM.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "EC_START_ELEM_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_EC_START_ELEM, g_nStringIdEC_START_ELEM) + +const CStringDictionary::TStringId FORTE_EC_START_ELEM::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdELEM_NAME, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_EC_START_ELEM::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_EC_START_ELEM::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_EC_START_ELEM::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_EC_START_ELEM::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_EC_START_ELEM::scm_anEIWith[] = {1, 2, 0, 255}; +const CStringDictionary::TStringId FORTE_EC_START_ELEM::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_EC_START_ELEM::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_EC_START_ELEM::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_EC_START_ELEM::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_EC_START_ELEM::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_EC_START_ELEM::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_EC_START_ELEM::executeRQST(void){ + forte::core::SManagementCMD theCommand; + + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(ELEM_NAME().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Start; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} + diff --git a/src/modules/reconfiguration/EC_START_ELEM.h b/src/modules/reconfiguration/EC_START_ELEM.h new file mode 100644 index 000000000..efecf8a4a --- /dev/null +++ b/src/modules/reconfiguration/EC_START_ELEM.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EC_START_ELEM_H_ +#define _EC_START_ELEM_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_EC_START_ELEM: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_EC_START_ELEM) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &ELEM_NAME() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 3, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_EC_START_ELEM), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_EC_START_ELEM(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/EC_STOP_ELEM.cpp b/src/modules/reconfiguration/EC_STOP_ELEM.cpp new file mode 100644 index 000000000..825c9a0d3 --- /dev/null +++ b/src/modules/reconfiguration/EC_STOP_ELEM.cpp @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EC_STOP_ELEM.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "EC_STOP_ELEM_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_EC_STOP_ELEM, g_nStringIdEC_STOP_ELEM) + +const CStringDictionary::TStringId FORTE_EC_STOP_ELEM::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdELEM_NAME, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_EC_STOP_ELEM::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_EC_STOP_ELEM::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_EC_STOP_ELEM::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_EC_STOP_ELEM::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_EC_STOP_ELEM::scm_anEIWith[] = {1, 2, 0, 255}; +const CStringDictionary::TStringId FORTE_EC_STOP_ELEM::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_EC_STOP_ELEM::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_EC_STOP_ELEM::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_EC_STOP_ELEM::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_EC_STOP_ELEM::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_EC_STOP_ELEM::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + +void FORTE_EC_STOP_ELEM::executeRQST(void){ + forte::core::SManagementCMD theCommand; + + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(ELEM_NAME().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Stop; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} diff --git a/src/modules/reconfiguration/EC_STOP_ELEM.h b/src/modules/reconfiguration/EC_STOP_ELEM.h new file mode 100644 index 000000000..f2689fc31 --- /dev/null +++ b/src/modules/reconfiguration/EC_STOP_ELEM.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EC_STOP_ELEM_H_ +#define _EC_STOP_ELEM_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_EC_STOP_ELEM: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_EC_STOP_ELEM) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &ELEM_NAME() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 3, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_EC_STOP_ELEM), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_EC_STOP_ELEM(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/ST_CREATE_CONN.cpp b/src/modules/reconfiguration/ST_CREATE_CONN.cpp new file mode 100644 index 000000000..36c9d5f2c --- /dev/null +++ b/src/modules/reconfiguration/ST_CREATE_CONN.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ST_CREATE_CONN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ST_CREATE_CONN_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_ST_CREATE_CONN, g_nStringIdST_CREATE_CONN) + +const CStringDictionary::TStringId FORTE_ST_CREATE_CONN::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdSRC_FB, g_nStringIdSRC_FB_OUT, g_nStringIdDST_FB, g_nStringIdDST_FB_IN, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_ST_CREATE_CONN::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_ST_CREATE_CONN::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_ST_CREATE_CONN::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_ST_CREATE_CONN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_ST_CREATE_CONN::scm_anEIWith[] = {1, 2, 3, 4, 5, 0, 255}; +const CStringDictionary::TStringId FORTE_ST_CREATE_CONN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_ST_CREATE_CONN::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_ST_CREATE_CONN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_ST_CREATE_CONN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_ST_CREATE_CONN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 6, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_ST_CREATE_CONN::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + +void FORTE_ST_CREATE_CONN::executeRQST(void){ + forte::core::SManagementCMD theCommand; + + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(SRC_FB().getValue())); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(SRC_FB_OUT().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(DST_FB().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(DST_FB_IN().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Create_Connection; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} diff --git a/src/modules/reconfiguration/ST_CREATE_CONN.h b/src/modules/reconfiguration/ST_CREATE_CONN.h new file mode 100644 index 000000000..beb4e519a --- /dev/null +++ b/src/modules/reconfiguration/ST_CREATE_CONN.h @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ST_CREATE_CONN_H_ +#define _ST_CREATE_CONN_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_ST_CREATE_CONN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_ST_CREATE_CONN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &SRC_FB() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &SRC_FB_OUT() { + return *static_cast(getDI(2)); + }; + + CIEC_WSTRING &DST_FB() { + return *static_cast(getDI(3)); + }; + + CIEC_WSTRING &DST_FB_IN() { + return *static_cast(getDI(4)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(5)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + //! The device the block is contained in + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 6, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); +public: + FUNCTION_BLOCK_CTOR(FORTE_ST_CREATE_CONN), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_ST_CREATE_CONN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/ST_CREATE_FB.cpp b/src/modules/reconfiguration/ST_CREATE_FB.cpp new file mode 100644 index 000000000..01bf4e7fd --- /dev/null +++ b/src/modules/reconfiguration/ST_CREATE_FB.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ST_CREATE_FB.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ST_CREATE_FB_gen.cpp" +#endif +#include "DEV_MGR.h" +#include +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_ST_CREATE_FB, g_nStringIdST_CREATE_FB) + +const CStringDictionary::TStringId FORTE_ST_CREATE_FB::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdFB_NAME, g_nStringIdFB_TYPE, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_ST_CREATE_FB::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_ST_CREATE_FB::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_ST_CREATE_FB::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_ST_CREATE_FB::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_ST_CREATE_FB::scm_anEIWith[] = {1, 2, 3, 0, 255}; +const CStringDictionary::TStringId FORTE_ST_CREATE_FB::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_ST_CREATE_FB::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_ST_CREATE_FB::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_ST_CREATE_FB::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_ST_CREATE_FB::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_ST_CREATE_FB::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_ST_CREATE_FB::executeRQST(void){ + forte::core::SManagementCMD theCommand; + + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().insert(FB_NAME().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(FB_TYPE().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Create_FBInstance; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} + + diff --git a/src/modules/reconfiguration/ST_CREATE_FB.h b/src/modules/reconfiguration/ST_CREATE_FB.h new file mode 100644 index 000000000..1c17ca597 --- /dev/null +++ b/src/modules/reconfiguration/ST_CREATE_FB.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ST_CREATE_FB_H_ +#define _ST_CREATE_FB_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_ST_CREATE_FB: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_ST_CREATE_FB) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &FB_NAME() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &FB_TYPE() { + return *static_cast(getDI(2)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + //! The device the block is contained in + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 4, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); +public: + FUNCTION_BLOCK_CTOR(FORTE_ST_CREATE_FB), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_ST_CREATE_FB(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/ST_DEL_CONN.cpp b/src/modules/reconfiguration/ST_DEL_CONN.cpp new file mode 100644 index 000000000..ecb960096 --- /dev/null +++ b/src/modules/reconfiguration/ST_DEL_CONN.cpp @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ST_DEL_CONN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ST_DEL_CONN_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_ST_DEL_CONN, g_nStringIdST_DEL_CONN) + +const CStringDictionary::TStringId FORTE_ST_DEL_CONN::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdSRC_FB, g_nStringIdSRC_FB_OUT, g_nStringIdDST_FB, g_nStringIdDST_FB_IN, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_ST_DEL_CONN::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_ST_DEL_CONN::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_ST_DEL_CONN::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_ST_DEL_CONN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_ST_DEL_CONN::scm_anEIWith[] = {1, 2, 3, 4, 5, 0, 255}; +const CStringDictionary::TStringId FORTE_ST_DEL_CONN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_ST_DEL_CONN::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_ST_DEL_CONN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_ST_DEL_CONN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_ST_DEL_CONN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 6, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_ST_DEL_CONN::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_ST_DEL_CONN::executeRQST(void){ + forte::core::SManagementCMD theCommand; + + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(SRC_FB().getValue())); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(SRC_FB_OUT().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(DST_FB().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(DST_FB_IN().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Delete_Connection; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); + +} + diff --git a/src/modules/reconfiguration/ST_DEL_CONN.h b/src/modules/reconfiguration/ST_DEL_CONN.h new file mode 100644 index 000000000..aeca40821 --- /dev/null +++ b/src/modules/reconfiguration/ST_DEL_CONN.h @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ST_DEL_CONN_H_ +#define _ST_DEL_CONN_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_ST_DEL_CONN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_ST_DEL_CONN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &SRC_FB() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &SRC_FB_OUT() { + return *static_cast(getDI(2)); + }; + + CIEC_WSTRING &DST_FB() { + return *static_cast(getDI(3)); + }; + + CIEC_WSTRING &DST_FB_IN() { + return *static_cast(getDI(4)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(5)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + //! The device the block is contained in + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 6, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_ST_DEL_CONN), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_ST_DEL_CONN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/ST_DEL_FB.cpp b/src/modules/reconfiguration/ST_DEL_FB.cpp new file mode 100644 index 000000000..af08e8ed2 --- /dev/null +++ b/src/modules/reconfiguration/ST_DEL_FB.cpp @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ST_DEL_FB.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ST_DEL_FB_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_ST_DEL_FB, g_nStringIdST_DEL_FB) + +const CStringDictionary::TStringId FORTE_ST_DEL_FB::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdFB_NAME, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_ST_DEL_FB::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_ST_DEL_FB::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_ST_DEL_FB::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_ST_DEL_FB::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_ST_DEL_FB::scm_anEIWith[] = {1, 2, 0, 255}; +const CStringDictionary::TStringId FORTE_ST_DEL_FB::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_ST_DEL_FB::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_ST_DEL_FB::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_ST_DEL_FB::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_ST_DEL_FB::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_ST_DEL_FB::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_ST_DEL_FB::executeRQST(void){ + forte::core::SManagementCMD theCommand; + + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(FB_NAME().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Delete_FBInstance; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} + diff --git a/src/modules/reconfiguration/ST_DEL_FB.h b/src/modules/reconfiguration/ST_DEL_FB.h new file mode 100644 index 000000000..3252381ad --- /dev/null +++ b/src/modules/reconfiguration/ST_DEL_FB.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ST_DEL_FB_H_ +#define _ST_DEL_FB_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_ST_DEL_FB: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_ST_DEL_FB) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &FB_NAME() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + //! The device the block is contained in + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 3, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_ST_DEL_FB), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_ST_DEL_FB(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/ST_REC_CONN.cpp b/src/modules/reconfiguration/ST_REC_CONN.cpp new file mode 100644 index 000000000..65adfe132 --- /dev/null +++ b/src/modules/reconfiguration/ST_REC_CONN.cpp @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ST_REC_CONN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ST_REC_CONN_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_ST_REC_CONN, g_nStringIdST_REC_CONN) + +const CStringDictionary::TStringId FORTE_ST_REC_CONN::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdOLD_SRC_FB, g_nStringIdOLD_SRC_FB_OUT, g_nStringIdOLD_DST_FB, g_nStringIdOLD_DST_FB_IN, g_nStringIdNEW_SRC_FB, g_nStringIdNEW_SRC_FB_OUT, g_nStringIdNEW_DST_FB, g_nStringIdNEW_DST_FB_IN, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_ST_REC_CONN::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_ST_REC_CONN::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_ST_REC_CONN::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_ST_REC_CONN::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_ST_REC_CONN::scm_anEIWith[] = {1, 2, 3, 4, 9, 5, 6, 7, 8, 0, 255}; +const CStringDictionary::TStringId FORTE_ST_REC_CONN::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_ST_REC_CONN::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_ST_REC_CONN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_ST_REC_CONN::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_ST_REC_CONN::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 10, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_ST_REC_CONN::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + +void FORTE_ST_REC_CONN::executeRQST(void){ + forte::core::SManagementCMD theCommand; + // delete old connection + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(OLD_SRC_FB().getValue())); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(OLD_SRC_FB_OUT().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(OLD_DST_FB().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(OLD_DST_FB_IN().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Delete_Connection; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + if (resp == e_RDY) { + // create new connection + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.clear(); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(NEW_SRC_FB().getValue())); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(NEW_SRC_FB_OUT().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(NEW_DST_FB().getValue())); + theCommand.mSecondParam.pushBack(CStringDictionary::getInstance().getId(NEW_DST_FB_IN().getValue())); + theCommand.mCMD = cg_nMGM_CMD_Create_Connection; + resp = m_poDevice.executeMGMCommand(theCommand); + } + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); +} + + + + diff --git a/src/modules/reconfiguration/ST_REC_CONN.h b/src/modules/reconfiguration/ST_REC_CONN.h new file mode 100644 index 000000000..f04c38086 --- /dev/null +++ b/src/modules/reconfiguration/ST_REC_CONN.h @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ST_REC_CONN_H_ +#define _ST_REC_CONN_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_ST_REC_CONN: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_ST_REC_CONN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &OLD_SRC_FB() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &OLD_SRC_FB_OUT() { + return *static_cast(getDI(2)); + }; + + CIEC_WSTRING &OLD_DST_FB() { + return *static_cast(getDI(3)); + }; + + CIEC_WSTRING &OLD_DST_FB_IN() { + return *static_cast(getDI(4)); + }; + + CIEC_WSTRING &NEW_SRC_FB() { + return *static_cast(getDI(5)); + }; + + CIEC_WSTRING &NEW_SRC_FB_OUT() { + return *static_cast(getDI(6)); + }; + + CIEC_WSTRING &NEW_DST_FB() { + return *static_cast(getDI(7)); + }; + + CIEC_WSTRING &NEW_DST_FB_IN() { + return *static_cast(getDI(8)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(9)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + //! The device the block is contained in + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 10, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_ST_REC_CONN), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_ST_REC_CONN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/reconfiguration/ST_SET_PARM.cpp b/src/modules/reconfiguration/ST_SET_PARM.cpp new file mode 100644 index 000000000..a6cf99877 --- /dev/null +++ b/src/modules/reconfiguration/ST_SET_PARM.cpp @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2014, 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ST_SET_PARM.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ST_SET_PARM_gen.cpp" +#endif +#include "DEV_MGR.h" +#include "core/device.h" + +DEFINE_FIRMWARE_FB(FORTE_ST_SET_PARM, g_nStringIdST_SET_PARM) + +const CStringDictionary::TStringId FORTE_ST_SET_PARM::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdELEM_NAME, g_nStringIdELEM_DATA_IN, g_nStringIdPARM_VAL, g_nStringIdDST}; + +const CStringDictionary::TStringId FORTE_ST_SET_PARM::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING, g_nStringIdWSTRING}; + +const CStringDictionary::TStringId FORTE_ST_SET_PARM::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_ST_SET_PARM::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + +const TForteInt16 FORTE_ST_SET_PARM::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_ST_SET_PARM::scm_anEIWith[] = {1, 2, 3, 4, 0, 255}; +const CStringDictionary::TStringId FORTE_ST_SET_PARM::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_ST_SET_PARM::scm_anEOWith[] = {1, 0, 255}; +const TForteInt16 FORTE_ST_SET_PARM::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_ST_SET_PARM::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_ST_SET_PARM::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_ST_SET_PARM::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + QO() = QI(); + if(true == QI()) { + executeRQST(); + } else { + STATUS() = "Not Ready"; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + +void FORTE_ST_SET_PARM::executeRQST(void){ + forte::core::SManagementCMD theCommand; + theCommand.mDestination = CStringDictionary::getInstance().getId(DST().getValue()); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(ELEM_NAME().getValue())); + theCommand.mFirstParam.pushBack(CStringDictionary::getInstance().getId(ELEM_DATA_IN().getValue())); + theCommand.mAdditionalParams = PARM_VAL().getValue(); + theCommand.mCMD = cg_nMGM_CMD_Write; + + EMGMResponse resp = m_poDevice.executeMGMCommand(theCommand); + + //calculate return value + CIEC_STRING retVal(DEV_MGR::scm_sMGMResponseTexts[resp]); + CIEC_STRING compareVal(DEV_MGR::scm_sMGMResponseTexts[e_RDY]); + QO() = retVal == compareVal; + + DEVLOG_DEBUG("%s\n", DEV_MGR::scm_sMGMResponseTexts[resp]); + STATUS() = (DEV_MGR::scm_sMGMResponseTexts[resp]); + +} diff --git a/src/modules/reconfiguration/ST_SET_PARM.h b/src/modules/reconfiguration/ST_SET_PARM.h new file mode 100644 index 000000000..ce5f8136f --- /dev/null +++ b/src/modules/reconfiguration/ST_SET_PARM.h @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Gerhard Ebenhofer - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ST_SET_PARM_H_ +#define _ST_SET_PARM_H_ + +#include +#include +#include +#include "core/resource.h" + +class FORTE_ST_SET_PARM: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_ST_SET_PARM) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_WSTRING &ELEM_NAME() { + return *static_cast(getDI(1)); + }; + + CIEC_WSTRING &ELEM_DATA_IN() { + return *static_cast(getDI(2)); + }; + + CIEC_WSTRING &PARM_VAL() { + return *static_cast(getDI(3)); + }; + + CIEC_WSTRING &DST() { + return *static_cast(getDI(4)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_WSTRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + //! The device the block is contained in + CDevice &m_poDevice; + + FORTE_FB_DATA_ARRAY(1, 5, 2, 0); + + void executeEvent(int pa_nEIID); + void executeRQST(void); + +public: + FUNCTION_BLOCK_CTOR(FORTE_ST_SET_PARM), m_poDevice(pa_poSrcRes->getDevice()){ + }; + + virtual ~FORTE_ST_SET_PARM(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/CMakeLists.txt b/src/modules/rt_events/CMakeLists.txt new file mode 100644 index 000000000..e79ae79e7 --- /dev/null +++ b/src/modules/rt_events/CMakeLists.txt @@ -0,0 +1,18 @@ +#******************************************************************************* +# * Copyright (c) 2010, 2011 ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +forte_add_module(RT_Events "Real-Time Event Funktion blocks") + +############################################################################# +# RT_Events FB +############################################################################# +forte_add_sourcefile_hcpp(RT_E_CYCLE RT_E_DEMUX RT_E_F_TRIG RT_E_PERMIT RT_E_R_TRIG RT_E_SPLIT) +forte_add_sourcefile_hcpp(RT_E_DELAY RT_E_EC_COUPLER RT_E_MERGE RT_E_REND RT_E_SELECT RT_E_SWITCH RT_E_TRAIN) diff --git a/src/modules/rt_events/RT_E_CYCLE.cpp b/src/modules/rt_events/RT_E_CYCLE.cpp new file mode 100644 index 000000000..f3b29a8cd --- /dev/null +++ b/src/modules/rt_events/RT_E_CYCLE.cpp @@ -0,0 +1,78 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_CYCLE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_CYCLE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_CYCLE, g_nStringIdRT_E_CYCLE) + +const CStringDictionary::TStringId FORTE_RT_E_CYCLE::scm_anDataInputNames[] = {g_nStringIdDT, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_CYCLE::scm_anDataInputTypeIds[] = {g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_CYCLE::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_CYCLE::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_CYCLE::scm_anEIWithIndexes[] = {0, -1}; +const TDataIOID FORTE_RT_E_CYCLE::scm_anEIWith[] = {0, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_RT_E_CYCLE::scm_anEventInputNames[] = {g_nStringIdSTART, g_nStringIdSTOP}; + +const TDataIOID FORTE_RT_E_CYCLE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_CYCLE::scm_anEOWithIndexes[] = {-1, 0}; +const CStringDictionary::TStringId FORTE_RT_E_CYCLE::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_CYCLE::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +FORTE_RT_E_CYCLE::FORTE_RT_E_CYCLE(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CEventSourceFB( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData){ + setEventChainExecutor(&m_oECEO); + m_bActive = false; + //Timeout value is correctly initialized by the constructor m_stTimeListEntry.m_nTimeOut = 0; + m_stTimeListEntry.m_nInterval = 0; + m_stTimeListEntry.m_pstNext = 0; + m_stTimeListEntry.m_poTimedFB = this; + m_stTimeListEntry.m_eType = e_Periodic; + m_oECEO.changeExecutionState(cg_nMGM_CMD_Start); +} + + +void FORTE_RT_E_CYCLE::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case cg_nExternalEventID: + sendOutputEvent(scm_nEventEOID); + break; + case scm_nEventSTOPID: + if(m_bActive){ + m_oECEO.setDeadline(static_cast(0)); + CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); + m_bActive = false; + } + break; + case scm_nEventSTARTID: + if(!m_bActive){ + m_oECEO.setDeadline(Deadline()); + CTimerHandler::sm_poFORTETimer->registerTimedFB( &m_stTimeListEntry, DT()); + m_bActive = true; + } + break; + default: + break; + } +} + diff --git a/src/modules/rt_events/RT_E_CYCLE.h b/src/modules/rt_events/RT_E_CYCLE.h new file mode 100644 index 000000000..479c17ebd --- /dev/null +++ b/src/modules/rt_events/RT_E_CYCLE.h @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_CYCLE_H_ +#define _RT_E_CYCLE_H_ + +#include +#include +#include +#include +#include "../arch/timerha.h" + +class FORTE_RT_E_CYCLE: public CEventSourceFB{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_CYCLE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &DT() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventSTARTID = 0; + static const TEventID scm_nEventSTOPID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0); + + bool m_bActive; //!> flag to indicate that the timed fb is currently active + STimedFBListEntry m_stTimeListEntry; + CEventChainExecutionThread m_oECEO; + + void executeEvent(int pa_nEIID); + +public: + FORTE_RT_E_CYCLE(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + virtual ~FORTE_RT_E_CYCLE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_DELAY.cpp b/src/modules/rt_events/RT_E_DELAY.cpp new file mode 100644 index 000000000..5946d301f --- /dev/null +++ b/src/modules/rt_events/RT_E_DELAY.cpp @@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_DELAY.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_DELAY_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_DELAY, g_nStringIdRT_E_DELAY) + +const CStringDictionary::TStringId FORTE_RT_E_DELAY::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdDT, g_nStringIdTmin, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_DELAY::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_DELAY::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_DELAY::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_DELAY::scm_anEIWithIndexes[] = {0, 5, -1}; +const TDataIOID FORTE_RT_E_DELAY::scm_anEIWith[] = {0, 2, 3, 4, 255, 1, 255}; +const CStringDictionary::TStringId FORTE_RT_E_DELAY::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdSTART, g_nStringIdSTOP}; + +const TDataIOID FORTE_RT_E_DELAY::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_DELAY::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_DELAY::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_DELAY::scm_stFBInterfaceSpec = { + 3, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +FORTE_RT_E_DELAY::FORTE_RT_E_DELAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CEventSourceFB( pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData){ + + setEventChainExecutor(&m_oECEO); + m_bActive = false; + m_bInitialized = false; + //Timout value is correctly initialized by the constructor m_stTimeListEntry.m_nTimeOut = 0; + m_stTimeListEntry.m_nInterval = 0; + m_stTimeListEntry.m_pstNext = 0; + m_stTimeListEntry.m_poTimedFB = this; + m_stTimeListEntry.m_eType = e_SingleShot; + m_oECEO.changeExecutionState(cg_nMGM_CMD_Start); +} + +void FORTE_RT_E_DELAY::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case cg_nExternalEventID: + sendOutputEvent(scm_nEventEOID); + m_bActive = false; + break; + case scm_nEventSTOPID: + if(m_bActive){ + CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); + m_bActive = false; + } + break; + case scm_nEventSTARTID: + if((!m_bActive)&&(m_bInitialized)){ + CTimerHandler::sm_poFORTETimer->registerTimedFB( &m_stTimeListEntry, DT()); + m_bActive = true; + } + break; + case scm_nEventINITID: + if(QI() == true){ + if(!m_bInitialized){ + //m_oECEO.start(); + m_bInitialized = true; + } + m_oECEO.setDeadline(Deadline()); + } + else{ + // m_oECEO.end(); + m_bInitialized = false; + m_oECEO.setDeadline(static_cast(0)); + } + QO() = QI(); + sendOutputEvent(scm_nEventINITOID); + default: + break; + } +} + + diff --git a/src/modules/rt_events/RT_E_DELAY.h b/src/modules/rt_events/RT_E_DELAY.h new file mode 100644 index 000000000..b1f4e3ac1 --- /dev/null +++ b/src/modules/rt_events/RT_E_DELAY.h @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_DELAY_H_ +#define _RT_E_DELAY_H_ + +#include +#include +#include +#include +#include "../arch/timerha.h" + +class FORTE_RT_E_DELAY: public CEventSourceFB{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_DELAY) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &DT() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(3)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(4)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventSTARTID = 1; + static const TEventID scm_nEventSTOPID = 2; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 5, 1, 0); + + bool m_bActive; //!> flag to indicate that the timed fb is currently active + bool m_bInitialized; + STimedFBListEntry m_stTimeListEntry; + CEventChainExecutionThread m_oECEO; + + virtual void executeEvent(int pa_nEIID); + +public: + FORTE_RT_E_DELAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~FORTE_RT_E_DELAY(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_DEMUX.cpp b/src/modules/rt_events/RT_E_DEMUX.cpp new file mode 100644 index 000000000..b22312b97 --- /dev/null +++ b/src/modules/rt_events/RT_E_DEMUX.cpp @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_DEMUX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_DEMUX_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_DEMUX, g_nStringIdRT_E_DEMUX) + +const CStringDictionary::TStringId FORTE_RT_E_DEMUX::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdK, g_nStringIdTmin, g_nStringIdDeadline0, g_nStringIdWCET0, g_nStringIdDeadline1, g_nStringIdWCET1, g_nStringIdDeadline2, g_nStringIdWCET2, g_nStringIdDeadline3, g_nStringIdWCET3}; + +const CStringDictionary::TStringId FORTE_RT_E_DEMUX::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdUINT, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_DEMUX::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_DEMUX::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_DEMUX::scm_anEIWithIndexes[] = {0, 11}; +const TDataIOID FORTE_RT_E_DEMUX::scm_anEIWith[] = {0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 255, 1, 255}; +const CStringDictionary::TStringId FORTE_RT_E_DEMUX::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI}; + +const TDataIOID FORTE_RT_E_DEMUX::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_DEMUX::scm_anEOWithIndexes[] = {0, -1, -1, -1, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_DEMUX::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO0, g_nStringIdEO1, g_nStringIdEO2, g_nStringIdEO3}; + +const SFBInterfaceSpec FORTE_RT_E_DEMUX::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 5, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 11, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +FORTE_RT_E_DEMUX::FORTE_RT_E_DEMUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CFunctionBlock( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData) { + m_bInitialized = false; +} + +void FORTE_RT_E_DEMUX::executeEvent(int pa_nEIID){ + + if(scm_nEventEIID == pa_nEIID){ + if(m_bInitialized){ + CEventConnection *eoCon; + switch(K()){ + case 0: + eoCon = getEOConUnchecked(scm_nEventEO0ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO0); + m_oECEO0.resumeSelfSuspend(); + } + break; + case 1: + eoCon = getEOConUnchecked(scm_nEventEO1ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO1); + m_oECEO1.resumeSelfSuspend(); + } + break; + case 2: + eoCon = getEOConUnchecked(scm_nEventEO2ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO2); + m_oECEO2.resumeSelfSuspend(); + } + break; + case 3: + eoCon = getEOConUnchecked(scm_nEventEO3ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO3); + m_oECEO3.resumeSelfSuspend(); + } + break; + default: + break; + } + } + } + else + if(scm_nEventINITID == pa_nEIID){ + if(QI() == true){ + if(!m_bInitialized){ + m_oECEO0.changeExecutionState(cg_nMGM_CMD_Start); + m_oECEO1.changeExecutionState(cg_nMGM_CMD_Start); + m_oECEO2.changeExecutionState(cg_nMGM_CMD_Start); + m_oECEO3.changeExecutionState(cg_nMGM_CMD_Start); + m_bInitialized = true; + } + m_oECEO0.setDeadline(Deadline0()); + m_oECEO1.setDeadline(Deadline1()); + m_oECEO2.setDeadline(Deadline2()); + m_oECEO3.setDeadline(Deadline3()); + } + else{ + m_oECEO0.changeExecutionState(cg_nMGM_CMD_Stop); + m_oECEO1.changeExecutionState(cg_nMGM_CMD_Stop); + m_oECEO2.changeExecutionState(cg_nMGM_CMD_Stop); + m_oECEO3.changeExecutionState(cg_nMGM_CMD_Stop); + m_bInitialized = false; + } + QO() = QI(); + sendOutputEvent(scm_nEventINITOID); + } +} + + diff --git a/src/modules/rt_events/RT_E_DEMUX.h b/src/modules/rt_events/RT_E_DEMUX.h new file mode 100644 index 000000000..54a91a10f --- /dev/null +++ b/src/modules/rt_events/RT_E_DEMUX.h @@ -0,0 +1,113 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_DEMUX_H_ +#define _RT_E_DEMUX_H_ + +#include +#include +#include +#include +#include + +class FORTE_RT_E_DEMUX: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_DEMUX) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_UINT &K() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &Deadline0() { + return *static_cast(getDI(3)); + }; + + CIEC_TIME &WCET0() { + return *static_cast(getDI(4)); + }; + + CIEC_TIME &Deadline1() { + return *static_cast(getDI(5)); + }; + + CIEC_TIME &WCET1() { + return *static_cast(getDI(6)); + }; + + CIEC_TIME &Deadline2() { + return *static_cast(getDI(7)); + }; + + CIEC_TIME &WCET2() { + return *static_cast(getDI(8)); + }; + + CIEC_TIME &Deadline3() { + return *static_cast(getDI(9)); + }; + + CIEC_TIME &WCET3() { + return *static_cast(getDI(10)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEIID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEO0ID = 1; + static const TEventID scm_nEventEO1ID = 2; + static const TEventID scm_nEventEO2ID = 3; + static const TEventID scm_nEventEO3ID = 4; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(5, 11, 1, 0); + + + CEventChainExecutionThread m_oECEO0; + CEventChainExecutionThread m_oECEO1; + CEventChainExecutionThread m_oECEO2; + CEventChainExecutionThread m_oECEO3; + bool m_bInitialized; + + void executeEvent(int pa_nEIID); + +public: + FORTE_RT_E_DEMUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + virtual ~FORTE_RT_E_DEMUX(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_EC_COUPLER.cpp b/src/modules/rt_events/RT_E_EC_COUPLER.cpp new file mode 100644 index 000000000..b47c737c2 --- /dev/null +++ b/src/modules/rt_events/RT_E_EC_COUPLER.cpp @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_EC_COUPLER.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_EC_COUPLER_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_EC_COUPLER, g_nStringIdRT_E_EC_COUPLER) + +const CStringDictionary::TStringId FORTE_RT_E_EC_COUPLER::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdTmin, g_nStringIdDeadline}; + +const CStringDictionary::TStringId FORTE_RT_E_EC_COUPLER::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_EC_COUPLER::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_EC_COUPLER::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_EC_COUPLER::scm_anEIWithIndexes[] = {0, -1}; +const TDataIOID FORTE_RT_E_EC_COUPLER::scm_anEIWith[] = {0, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_RT_E_EC_COUPLER::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI}; + +const TDataIOID FORTE_RT_E_EC_COUPLER::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_EC_COUPLER::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_EC_COUPLER::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_EC_COUPLER::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +FORTE_RT_E_EC_COUPLER::FORTE_RT_E_EC_COUPLER(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CRTEventSingle( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, + m_anFBConnData, m_anFBVarsData) { +} + + + diff --git a/src/modules/rt_events/RT_E_EC_COUPLER.h b/src/modules/rt_events/RT_E_EC_COUPLER.h new file mode 100644 index 000000000..0df4bfc78 --- /dev/null +++ b/src/modules/rt_events/RT_E_EC_COUPLER.h @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_EC_COUPLER_H_ +#define _RT_E_EC_COUPLER_H_ + +#include "rtesingle.h" +#include +#include + +class FORTE_RT_E_EC_COUPLER: public CRTEventSingle{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_EC_COUPLER) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEIID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 1, 0); + + virtual bool checkActivation(int ) {return true;}; + +public: + FORTE_RT_E_EC_COUPLER(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + virtual ~FORTE_RT_E_EC_COUPLER(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_F_TRIG.cpp b/src/modules/rt_events/RT_E_F_TRIG.cpp new file mode 100644 index 000000000..628aa6ae3 --- /dev/null +++ b/src/modules/rt_events/RT_E_F_TRIG.cpp @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_F_TRIG.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_F_TRIG_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_F_TRIG, g_nStringIdRT_E_F_TRIG) + +const CStringDictionary::TStringId FORTE_RT_E_F_TRIG::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdTmin, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_F_TRIG::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_F_TRIG::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_F_TRIG::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_F_TRIG::scm_anEIWithIndexes[] = {0, 5}; +const TDataIOID FORTE_RT_E_F_TRIG::scm_anEIWith[] = {0, 1, 2, 3, 255, 0, 255}; +const CStringDictionary::TStringId FORTE_RT_E_F_TRIG::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI}; + +const TDataIOID FORTE_RT_E_F_TRIG::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_F_TRIG::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_F_TRIG::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_F_TRIG::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +FORTE_RT_E_F_TRIG::FORTE_RT_E_F_TRIG(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CRTEventSingle( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, + m_anFBConnData, m_anFBVarsData){ + m_bWasHigh = false; +} + +bool FORTE_RT_E_F_TRIG::checkActivation(int ){ + bool bRetval = false; + + if((QI() == false)&&(m_bWasHigh)){ + bRetval = true; + } + m_bWasHigh = QI(); + return bRetval; +} + + diff --git a/src/modules/rt_events/RT_E_F_TRIG.h b/src/modules/rt_events/RT_E_F_TRIG.h new file mode 100644 index 000000000..9db19d44f --- /dev/null +++ b/src/modules/rt_events/RT_E_F_TRIG.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_F_TRIG_H_ +#define _RT_E_F_TRIG_H_ + +#include "rtesingle.h" +#include +#include + +class FORTE_RT_E_F_TRIG: public CRTEventSingle{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_F_TRIG) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEIID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 4, 1, 0); + + bool m_bWasHigh; + + + virtual bool checkActivation(int pa_nEIID); +public: + FORTE_RT_E_F_TRIG(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + virtual ~FORTE_RT_E_F_TRIG(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_MERGE.cpp b/src/modules/rt_events/RT_E_MERGE.cpp new file mode 100644 index 000000000..0a3bfd56b --- /dev/null +++ b/src/modules/rt_events/RT_E_MERGE.cpp @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_MERGE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_MERGE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_MERGE, g_nStringIdRT_E_MERGE) + +const CStringDictionary::TStringId FORTE_RT_E_MERGE::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdTmin, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_MERGE::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_MERGE::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_MERGE::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_MERGE::scm_anEIWithIndexes[] = {0, -1, -1}; +const TDataIOID FORTE_RT_E_MERGE::scm_anEIWith[] = {0, 1, 2, 3, 255}; +const CStringDictionary::TStringId FORTE_RT_E_MERGE::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI1, g_nStringIdEI2}; + +const TDataIOID FORTE_RT_E_MERGE::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_MERGE::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_MERGE::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_MERGE::scm_stFBInterfaceSpec = { + 3, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +FORTE_RT_E_MERGE::FORTE_RT_E_MERGE(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CRTEventSingle( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, + m_anFBConnData, m_anFBVarsData) { +} + + diff --git a/src/modules/rt_events/RT_E_MERGE.h b/src/modules/rt_events/RT_E_MERGE.h new file mode 100644 index 000000000..be2cedc80 --- /dev/null +++ b/src/modules/rt_events/RT_E_MERGE.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_MERGE_H_ +#define _RT_E_MERGE_H_ + +#include "rtesingle.h" +#include +#include + +class FORTE_RT_E_MERGE: public CRTEventSingle{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_MERGE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEI1ID = 1; + static const TEventID scm_nEventEI2ID = 2; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 4, 1, 0); + + + virtual bool checkActivation(int ) {return true;}; //we activate on every input event + + +public: + FORTE_RT_E_MERGE(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + + virtual ~FORTE_RT_E_MERGE(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_PERMIT.cpp b/src/modules/rt_events/RT_E_PERMIT.cpp new file mode 100644 index 000000000..fcf6d1976 --- /dev/null +++ b/src/modules/rt_events/RT_E_PERMIT.cpp @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_PERMIT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_PERMIT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_PERMIT, g_nStringIdRT_E_PERMIT) + +const CStringDictionary::TStringId FORTE_RT_E_PERMIT::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdPERMIT, g_nStringIdTmin, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_PERMIT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_PERMIT::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_PERMIT::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_PERMIT::scm_anEIWithIndexes[] = {0, 5}; +const TDataIOID FORTE_RT_E_PERMIT::scm_anEIWith[] = {0, 2, 3, 4, 255, 1, 255}; +const CStringDictionary::TStringId FORTE_RT_E_PERMIT::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI}; + +const TDataIOID FORTE_RT_E_PERMIT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_PERMIT::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_PERMIT::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_PERMIT::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + + +FORTE_RT_E_PERMIT::FORTE_RT_E_PERMIT(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CRTEventSingle( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, + m_anFBConnData, m_anFBVarsData) { +} + +bool FORTE_RT_E_PERMIT::checkActivation(int ){ + return PERMIT(); +} + + + + + diff --git a/src/modules/rt_events/RT_E_PERMIT.h b/src/modules/rt_events/RT_E_PERMIT.h new file mode 100644 index 000000000..c386779c6 --- /dev/null +++ b/src/modules/rt_events/RT_E_PERMIT.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_PERMIT_H_ +#define _RT_E_PERMIT_H_ + +#include "rtesingle.h" +#include +#include + +class FORTE_RT_E_PERMIT: public CRTEventSingle{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_PERMIT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_BOOL &PERMIT() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(3)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(4)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEIID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 5, 1, 0); + + virtual bool checkActivation(int ); + +public: + + + FORTE_RT_E_PERMIT(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + virtual ~FORTE_RT_E_PERMIT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_REND.cpp b/src/modules/rt_events/RT_E_REND.cpp new file mode 100644 index 000000000..5d27d5ac3 --- /dev/null +++ b/src/modules/rt_events/RT_E_REND.cpp @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_REND.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_REND_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_REND, g_nStringIdRT_E_REND) + +const CStringDictionary::TStringId FORTE_RT_E_REND::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdTmin, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_REND::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_REND::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_REND::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_REND::scm_anEIWithIndexes[] = {0, -1, -1, -1}; +const TDataIOID FORTE_RT_E_REND::scm_anEIWith[] = {0, 1, 2, 3, 255}; +const CStringDictionary::TStringId FORTE_RT_E_REND::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI1, g_nStringIdEI2, g_nStringIdR}; + +const TDataIOID FORTE_RT_E_REND::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_REND::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_REND::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_REND::scm_stFBInterfaceSpec = { + 4, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +FORTE_RT_E_REND::FORTE_RT_E_REND(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CRTEventSingle( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, + m_anFBConnData, m_anFBVarsData), + m_nState(0) { +} + +bool FORTE_RT_E_REND::checkActivation(int pa_nEIID){ + bool bRetval = false; + + if(scm_nEventEI1ID == pa_nEIID){ + if(m_nState == 2) + bRetval = true; + else + m_nState = 1; + } + else + if(scm_nEventEI2ID == pa_nEIID){ + if(m_nState == 1) + bRetval = true; + else + m_nState = 2; + } + else + if(scm_nEventRID == pa_nEIID) + m_nState = 0; + + return bRetval; +} + diff --git a/src/modules/rt_events/RT_E_REND.h b/src/modules/rt_events/RT_E_REND.h new file mode 100644 index 000000000..740688bfa --- /dev/null +++ b/src/modules/rt_events/RT_E_REND.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_REND_H_ +#define _RT_E_REND_H_ + +#include "rtesingle.h" +#include +#include + +class FORTE_RT_E_REND: public CRTEventSingle{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_REND) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEI1ID = 1; + static const TEventID scm_nEventEI2ID = 2; + static const TEventID scm_nEventRID = 3; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 4, 1, 0); + + int m_nState; + + virtual bool checkActivation(int pa_nEIID); + +public: + FORTE_RT_E_REND(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~FORTE_RT_E_REND(){}; + + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_R_TRIG.cpp b/src/modules/rt_events/RT_E_R_TRIG.cpp new file mode 100644 index 000000000..e93f08abb --- /dev/null +++ b/src/modules/rt_events/RT_E_R_TRIG.cpp @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_R_TRIG.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_R_TRIG_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_R_TRIG, g_nStringIdRT_E_R_TRIG) + +const CStringDictionary::TStringId FORTE_RT_E_R_TRIG::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdTmin, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_R_TRIG::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_R_TRIG::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_R_TRIG::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_R_TRIG::scm_anEIWithIndexes[] = {0, 5}; +const TDataIOID FORTE_RT_E_R_TRIG::scm_anEIWith[] = {0, 1, 2, 3, 255, 0, 255}; +const CStringDictionary::TStringId FORTE_RT_E_R_TRIG::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI}; + +const TDataIOID FORTE_RT_E_R_TRIG::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_R_TRIG::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_R_TRIG::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_R_TRIG::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +FORTE_RT_E_R_TRIG::FORTE_RT_E_R_TRIG(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CRTEventSingle( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, + m_anFBConnData, m_anFBVarsData){ + m_bWasHigh = false; +} + +bool FORTE_RT_E_R_TRIG::checkActivation(int ){ + bool bRetval = false; + + if((QI() == true)&&(!m_bWasHigh)){ + bRetval = true; + } + m_bWasHigh = QI(); + return bRetval; +} + + diff --git a/src/modules/rt_events/RT_E_R_TRIG.h b/src/modules/rt_events/RT_E_R_TRIG.h new file mode 100644 index 000000000..fa0e42e7e --- /dev/null +++ b/src/modules/rt_events/RT_E_R_TRIG.h @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_R_TRIG_H_ +#define _RT_E_R_TRIG_H_ + +#include "rtesingle.h" +#include +#include + +class FORTE_RT_E_R_TRIG: public CRTEventSingle { + DECLARE_FIRMWARE_FB(FORTE_RT_E_R_TRIG) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEIID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 4, 1, 0); + + bool m_bWasHigh; + + + virtual bool checkActivation(int pa_nEIID); + +public: + FORTE_RT_E_R_TRIG(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~FORTE_RT_E_R_TRIG(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_SELECT.cpp b/src/modules/rt_events/RT_E_SELECT.cpp new file mode 100644 index 000000000..39ae106ef --- /dev/null +++ b/src/modules/rt_events/RT_E_SELECT.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_SELECT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_SELECT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_SELECT, g_nStringIdRT_E_SELECT) + +const CStringDictionary::TStringId FORTE_RT_E_SELECT::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdG, g_nStringIdTmin, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_SELECT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_SELECT::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_SELECT::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_SELECT::scm_anEIWithIndexes[] = {0, 5, 7}; +const TDataIOID FORTE_RT_E_SELECT::scm_anEIWith[] = {0, 2, 3, 4, 255, 1, 255, 1, 255}; +const CStringDictionary::TStringId FORTE_RT_E_SELECT::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI0, g_nStringIdEI1}; + +const TDataIOID FORTE_RT_E_SELECT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_SELECT::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_SELECT::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_SELECT::scm_stFBInterfaceSpec = { + 3, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 5, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +FORTE_RT_E_SELECT::FORTE_RT_E_SELECT(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CRTEventSingle( + pa_poSrcRes, + &scm_stFBInterfaceSpec, pa_nInstanceNameId, + m_anFBConnData, m_anFBVarsData) { +} + +bool FORTE_RT_E_SELECT::checkActivation(int pa_nEIID){ + return (((scm_nEventEI0ID == pa_nEIID) && (G() == false))|| + ((scm_nEventEI1ID == pa_nEIID) && (G() == true))); +} + diff --git a/src/modules/rt_events/RT_E_SELECT.h b/src/modules/rt_events/RT_E_SELECT.h new file mode 100644 index 000000000..83c866e37 --- /dev/null +++ b/src/modules/rt_events/RT_E_SELECT.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_SELECT_H_ +#define _RT_E_SELECT_H_ + +#include "rtesingle.h" +#include +#include + +class FORTE_RT_E_SELECT: public CRTEventSingle{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_SELECT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_BOOL &G() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(3)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(4)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEI0ID = 1; + static const TEventID scm_nEventEI1ID = 2; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 5, 1, 0); + + virtual bool checkActivation(int pa_nEIID); + +public: + FORTE_RT_E_SELECT(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~FORTE_RT_E_SELECT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_SPLIT.cpp b/src/modules/rt_events/RT_E_SPLIT.cpp new file mode 100644 index 000000000..6b85ed71e --- /dev/null +++ b/src/modules/rt_events/RT_E_SPLIT.cpp @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_SPLIT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_SPLIT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_SPLIT, g_nStringIdRT_E_SPLIT) + +const CStringDictionary::TStringId FORTE_RT_E_SPLIT::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdTmin, g_nStringIdDeadline_EO1, g_nStringIdWCET_EO1, g_nStringIdDeadline_EO2, g_nStringIdWCET_EO2}; + +const CStringDictionary::TStringId FORTE_RT_E_SPLIT::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_SPLIT::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_SPLIT::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_SPLIT::scm_anEIWithIndexes[] = {0, -1}; +const TDataIOID FORTE_RT_E_SPLIT::scm_anEIWith[] = {0, 1, 2, 3, 4, 5, 255}; +const CStringDictionary::TStringId FORTE_RT_E_SPLIT::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI}; + +const TDataIOID FORTE_RT_E_SPLIT::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_SPLIT::scm_anEOWithIndexes[] = {0, -1, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_SPLIT::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO1, g_nStringIdEO2}; + +const SFBInterfaceSpec FORTE_RT_E_SPLIT::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 3, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 6, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_RT_E_SPLIT::executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + if(m_bInitialized){ + CEventConnection *eoCon; + eoCon = getEOConUnchecked(scm_nEventEO1ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO1); + m_oECEO1.resumeSelfSuspend(); + } + eoCon = getEOConUnchecked(scm_nEventEO2ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO2); + m_oECEO2.resumeSelfSuspend(); + } + } + } + else + if(scm_nEventINITID == pa_nEIID){ + if(QI() == true){ + if(!m_bInitialized){ + m_oECEO1.changeExecutionState(cg_nMGM_CMD_Start); + m_oECEO2.changeExecutionState(cg_nMGM_CMD_Start); + m_bInitialized = true; + } + m_oECEO1.setDeadline(Deadline_EO1()); + m_oECEO2.setDeadline(Deadline_EO2()); + } + else{ + m_oECEO1.changeExecutionState(cg_nMGM_CMD_Stop); + m_oECEO2.changeExecutionState(cg_nMGM_CMD_Stop); + m_bInitialized = false; + } + QO() = QI(); + sendOutputEvent(scm_nEventINITOID); + } +} + + + diff --git a/src/modules/rt_events/RT_E_SPLIT.h b/src/modules/rt_events/RT_E_SPLIT.h new file mode 100644 index 000000000..723eadc17 --- /dev/null +++ b/src/modules/rt_events/RT_E_SPLIT.h @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_SPLIT_H_ +#define _RT_E_SPLIT_H_ + +#include +#include +#include +#include + +class FORTE_RT_E_SPLIT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_SPLIT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Deadline_EO1() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &WCET_EO1() { + return *static_cast(getDI(3)); + }; + + CIEC_TIME &Deadline_EO2() { + return *static_cast(getDI(4)); + }; + + CIEC_TIME &WCET_EO2() { + return *static_cast(getDI(5)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEIID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEO1ID = 1; + static const TEventID scm_nEventEO2ID = 2; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(3, 6, 1, 0); + + CEventChainExecutionThread m_oECEO1, m_oECEO2; + bool m_bInitialized; + + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_RT_E_SPLIT){ + m_bInitialized = false; + }; + + virtual ~FORTE_RT_E_SPLIT(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_SWITCH.cpp b/src/modules/rt_events/RT_E_SWITCH.cpp new file mode 100644 index 000000000..005061b91 --- /dev/null +++ b/src/modules/rt_events/RT_E_SWITCH.cpp @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, Monika Wenger, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_SWITCH.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_SWITCH_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_SWITCH, g_nStringIdRT_E_SWITCH) + +const CStringDictionary::TStringId FORTE_RT_E_SWITCH::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdG, g_nStringIdTmin, g_nStringIdDeadline_EO1, g_nStringIdWCET_EO1, g_nStringIdDeadline_EO2, g_nStringIdWCET_EO2}; + +const CStringDictionary::TStringId FORTE_RT_E_SWITCH::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_SWITCH::scm_anDataOutputNames[] = {g_nStringIdQO}; + +const CStringDictionary::TStringId FORTE_RT_E_SWITCH::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_RT_E_SWITCH::scm_anEIWithIndexes[] = {0, 7}; +const TDataIOID FORTE_RT_E_SWITCH::scm_anEIWith[] = {0, 2, 3, 4, 5, 6, 255, 1, 255}; +const CStringDictionary::TStringId FORTE_RT_E_SWITCH::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdEI}; + +const TDataIOID FORTE_RT_E_SWITCH::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_SWITCH::scm_anEOWithIndexes[] = {0, -1, -1, -1}; +const CStringDictionary::TStringId FORTE_RT_E_SWITCH::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdEO1, g_nStringIdEO2}; + +const SFBInterfaceSpec FORTE_RT_E_SWITCH::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 3, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 7, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_RT_E_SWITCH::executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + if(m_bInitialized){ + CEventConnection *eoCon; + if(G() == false){ + eoCon = getEOConUnchecked(scm_nEventEO1ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO1); + m_oECEO1.resumeSelfSuspend(); + } + } + else{ + eoCon = getEOConUnchecked(scm_nEventEO2ID); + if(eoCon->isConnected()){ + eoCon->triggerEvent(m_oECEO2); + m_oECEO2.resumeSelfSuspend(); + } + } + } + } + else + if(scm_nEventINITID == pa_nEIID){ + if(QI() == true){ + if(!m_bInitialized){ + m_oECEO1.changeExecutionState(cg_nMGM_CMD_Start); + m_oECEO2.changeExecutionState(cg_nMGM_CMD_Start); + m_bInitialized = true; + } + m_oECEO1.setDeadline(Deadline_EO1()); + m_oECEO2.setDeadline(Deadline_EO2()); + } + else{ + m_oECEO1.changeExecutionState(cg_nMGM_CMD_Stop); + m_oECEO2.changeExecutionState(cg_nMGM_CMD_Stop); + m_bInitialized = false; + } + QO() = QI(); + sendOutputEvent(scm_nEventINITOID); + } +} + + + + diff --git a/src/modules/rt_events/RT_E_SWITCH.h b/src/modules/rt_events/RT_E_SWITCH.h new file mode 100644 index 000000000..71867a8c5 --- /dev/null +++ b/src/modules/rt_events/RT_E_SWITCH.h @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_SWITCH_H_ +#define _RT_E_SWITCH_H_ + +#include +#include +#include +#include +#include + +class FORTE_RT_E_SWITCH: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_SWITCH) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_BOOL &G() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Tmin() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &Deadline_EO1() { + return *static_cast(getDI(3)); + }; + + CIEC_TIME &WCET_EO1() { + return *static_cast(getDI(4)); + }; + + CIEC_TIME &Deadline_EO2() { + return *static_cast(getDI(5)); + }; + + CIEC_TIME &WCET_EO2() { + return *static_cast(getDI(6)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventEIID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventEO1ID = 1; + static const TEventID scm_nEventEO2ID = 2; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(3, 7, 1, 0); + + CEventChainExecutionThread m_oECEO1, m_oECEO2; + bool m_bInitialized; + + virtual void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_RT_E_SWITCH){ + m_bInitialized = false; + }; + + virtual ~FORTE_RT_E_SWITCH(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/RT_E_TRAIN.cpp b/src/modules/rt_events/RT_E_TRAIN.cpp new file mode 100644 index 000000000..c0c8b29ca --- /dev/null +++ b/src/modules/rt_events/RT_E_TRAIN.cpp @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RT_E_TRAIN.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RT_E_TRAIN_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_RT_E_TRAIN, g_nStringIdRT_E_TRAIN) + +const CStringDictionary::TStringId FORTE_RT_E_TRAIN::scm_anDataInputNames[] = {g_nStringIdDT, g_nStringIdN, g_nStringIdDeadline, g_nStringIdWCET}; + +const CStringDictionary::TStringId FORTE_RT_E_TRAIN::scm_anDataInputTypeIds[] = {g_nStringIdTIME, g_nStringIdUINT, g_nStringIdTIME, g_nStringIdTIME}; + +const CStringDictionary::TStringId FORTE_RT_E_TRAIN::scm_anDataOutputNames[] = {g_nStringIdCV}; + +const CStringDictionary::TStringId FORTE_RT_E_TRAIN::scm_anDataOutputTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 FORTE_RT_E_TRAIN::scm_anEIWithIndexes[] = {0, -1}; +const TDataIOID FORTE_RT_E_TRAIN::scm_anEIWith[] = {0, 1, 2, 3, 255}; +const CStringDictionary::TStringId FORTE_RT_E_TRAIN::scm_anEventInputNames[] = {g_nStringIdSTART, g_nStringIdSTOP}; + +const TDataIOID FORTE_RT_E_TRAIN::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_RT_E_TRAIN::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_RT_E_TRAIN::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec FORTE_RT_E_TRAIN::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 4, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +const SCFB_FBInstanceData FORTE_RT_E_TRAIN::scm_astInternalFBs[] = { + {g_nStringIdRT_E_CYCLE, g_nStringIdRT_E_CYCLE}, + {g_nStringIdE_CTU, g_nStringIdE_CTU}, + {g_nStringIdE_SWITCH, g_nStringIdE_SWITCH}, +}; + +const SCFB_FBConnectionData FORTE_RT_E_TRAIN::scm_astEventConnections[] = { + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRT_E_CYCLE, g_nStringIdEO), 0, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_CTU, g_nStringIdCU), 1}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdSTART), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_CTU, g_nStringIdR), 1}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdSTOP), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRT_E_CYCLE, g_nStringIdSTOP), 0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_CTU, g_nStringIdRO), 1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRT_E_CYCLE, g_nStringIdSTART), 0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_CTU, g_nStringIdCUO), 1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SWITCH, g_nStringIdEI), 2}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SWITCH, g_nStringIdEO0), 2, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdEO), -1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SWITCH, g_nStringIdEO1), 2, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRT_E_CYCLE, g_nStringIdSTOP), 0}, +}; + +const SCFB_FBConnectionData FORTE_RT_E_TRAIN::scm_astDataConnections[] = { + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdDT), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRT_E_CYCLE, g_nStringIdDT), 0}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdDeadline), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRT_E_CYCLE, g_nStringIdDeadline), 0}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdWCET), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRT_E_CYCLE, g_nStringIdWCET), 0}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdN), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_CTU, g_nStringIdPV), 1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_CTU, g_nStringIdCV), 1, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdCV), -1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_CTU, g_nStringIdQ), 1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SWITCH, g_nStringIdG), 2}, +}; + +const SCFB_FBNData FORTE_RT_E_TRAIN::scm_stFBNData = { + 3, scm_astInternalFBs, + 7, scm_astEventConnections, + 0, 0, + 6, scm_astDataConnections, + 0, 0, + 0, 0 +}; + + diff --git a/src/modules/rt_events/RT_E_TRAIN.h b/src/modules/rt_events/RT_E_TRAIN.h new file mode 100644 index 000000000..2cb9a9e52 --- /dev/null +++ b/src/modules/rt_events/RT_E_TRAIN.h @@ -0,0 +1,79 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RT_E_TRAIN_H_ +#define _RT_E_TRAIN_H_ + +#include +#include +#include +#include + +class FORTE_RT_E_TRAIN: public CCompositeFB{ + DECLARE_FIRMWARE_FB(FORTE_RT_E_TRAIN) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_TIME &DT() { + return *static_cast(getDI(0)); + }; + + CIEC_UINT &N() { + return *static_cast(getDI(1)); + }; + + CIEC_TIME &Deadline() { + return *static_cast(getDI(2)); + }; + + CIEC_TIME &WCET() { + return *static_cast(getDI(3)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_UINT &CV() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventSTARTID = 0; + static const TEventID scm_nEventSTOPID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 4, 1, 0); + + static const SCFB_FBInstanceData scm_astInternalFBs[]; + + static const SCFB_FBConnectionData scm_astEventConnections[]; + + static const SCFB_FBConnectionData scm_astDataConnections[]; + static const SCFB_FBNData scm_stFBNData; + +public: + COMPOSITE_FUNCTION_BLOCK_CTOR(FORTE_RT_E_TRAIN){ + }; + + virtual ~FORTE_RT_E_TRAIN(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/rt_events/rtesingle.h b/src/modules/rt_events/rtesingle.h new file mode 100644 index 000000000..bc5adc8af --- /dev/null +++ b/src/modules/rt_events/rtesingle.h @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef RTESINGLE_H_ +#define RTESINGLE_H_ + +#include +#include +#include +#include +#include + + +/*!\brief Base class for all single output real-time event function blocks. + * + */ +class CRTEventSingle: public CFunctionBlock{ +private: + CEventChainExecutionThread m_oECEO; + CSyncObject m_oSyncObj; //!isConnected()){ + eoCon->triggerEvent(m_oECEO); + m_oECEO.resumeSelfSuspend(); + } + } + } + } + else{ // we got init + if(QI() == true){ + if(!m_bInitialized){ + m_oECEO.changeExecutionState(cg_nMGM_CMD_Start); + m_bInitialized = true; + } + m_oECEO.setDeadline(Deadline()); + } + else{ + m_oECEO.changeExecutionState(cg_nMGM_CMD_Stop); + m_bInitialized = false; + } + QO() = QI(); + sendOutputEvent(0); + } + } + +public: + + + CRTEventSingle(CResource *pa_poSrcRes, const SFBInterfaceSpec *pa_pstInterfaceSpec, + const CStringDictionary::TStringId pa_nInstanceNameId, TForteByte *pa_acFBConnData, TForteByte *pa_acFBVarsData) : + CFunctionBlock( pa_poSrcRes, pa_pstInterfaceSpec, pa_nInstanceNameId, pa_acFBConnData, pa_acFBVarsData) + { + m_bInitialized = false; + }; + virtual ~CRTEventSingle(){}; +}; + +#endif /*RTESINGLE_H_*/ diff --git a/src/modules/sysfs/CMakeLists.txt b/src/modules/sysfs/CMakeLists.txt new file mode 100644 index 000000000..ad4e4eaab --- /dev/null +++ b/src/modules/sysfs/CMakeLists.txt @@ -0,0 +1,24 @@ +#******************************************************************************* +# * Copyright (c) 2015 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Waldemar Eisenmenger - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +forte_add_module(SysFs "Interacting with GPIOs of linuxbased devices via the filesystem using sysfs") + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +####################################################### +# SysFs +####################################################### + + +forte_add_sourcefile_hcpp(../../stdfblib/io/IX) +forte_add_sourcefile_hcpp( ../../stdfblib/io/QX) +forte_add_sourcefile_hcpp(processinterface) + diff --git a/src/modules/sysfs/processinterface.cpp b/src/modules/sysfs/processinterface.cpp new file mode 100644 index 000000000..41d1b9d12 --- /dev/null +++ b/src/modules/sysfs/processinterface.cpp @@ -0,0 +1,159 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Waldemar Eisenmenger, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include "processinterface.h" +#include +#include +#include +#include +#include +#include + +const char * const CSysFsProcessInterface::scmPinInUse = "Pin already in use by other FB"; +const char * const CSysFsProcessInterface::scmInitDeinitOK = "OK"; +const char * const CSysFsProcessInterface::scmNotInitialised = "Not initialised"; + +CSysFsProcessInterface::CSysFsProcessInterface(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData) : + CProcessInterfaceBase(paSrcRes, paInterfaceSpec, paInstanceNameId, paFBConnData, paFBVarsData), mPinNumber(-1){ +} + +CSysFsProcessInterface::~CSysFsProcessInterface(){ +} + +bool CSysFsProcessInterface::initialise(bool m_bInputOrOutput){ + char buffer[scmBuffer]; + ssize_t bytes; + int fd; + int res; + char path[scmBuffer]; + + fd = open("/sys/class/gpio/export", O_WRONLY); + if(fd < 0){ + STATUS() = scmNotInitialised; + return false; + } + + CIEC_INT param; + param.fromString(PARAMS().getValue()); + mPinNumber = param; + + bytes = snprintf(buffer, scmBuffer, "%d", mPinNumber); + write(fd, buffer, bytes); + close(fd); + + snprintf(path, scmBuffer, "/sys/class/gpio/gpio%d/direction", mPinNumber); + fd = open(path, O_WRONLY); + if(fd < 0){ + STATUS() = scmNotInitialised; + return false; + } + + if(m_bInputOrOutput){ + res = write(fd, "in", 2); + } + else if(!m_bInputOrOutput){ + res = write(fd, "out", 3); + } + if(res < 0){ + STATUS() = scmNotInitialised; + return false; + } + close(fd); + + STATUS() = scmInitDeinitOK; + return true; +} + +bool CSysFsProcessInterface::deinitialise(){ + char buffer[scmBuffer]; + ssize_t bytes; + int fd; + + fd = open("/sys/class/gpio/unexport", O_WRONLY); + if(fd < 0){ + STATUS() = scmNotInitialised; //rework status messages + return false; + } + + CIEC_INT param; + param.fromString(PARAMS().getValue()); + mPinNumber = param; + + bytes = snprintf(buffer, scmBuffer, "%d", mPinNumber); + write(fd, buffer, bytes); + close(fd); + + STATUS() = scmInitDeinitOK; + return true; +} + +bool CSysFsProcessInterface::readPin(){ + char path[scmBuffer]; + int fd; + char result[scmBuffer] = { 0 }; + + CIEC_INT param; + param.fromString(PARAMS().getValue()); + mPinNumber = param; + + snprintf(path, scmBuffer, "/sys/class/gpio/gpio%d/value", mPinNumber); + fd = open(path, O_RDONLY); + if(fd < 0){ + STATUS() = "Kann net lesen"; + return false; + } + if(read(fd, result, 3) < 0){ + STATUS() = "Kann net lesen"; + return false; + } + close(fd); + + if('0' == result[0]){ + IN_X() = false; + } + else if('1' == result[0]){ + IN_X() = true; + } + STATUS() = "Konnte lesen"; + return true; +} + +bool CSysFsProcessInterface::writePin(){ + char path[scmBuffer]; + int fd; + int res; + + CIEC_INT param; + param.fromString(PARAMS().getValue()); + mPinNumber = param; + + snprintf(path, scmBuffer, "/sys/class/gpio/gpio%d/value", mPinNumber); + fd = open(path, O_WRONLY); + if(fd < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + + if(OUT_X()){ + res = write(fd, "0", 1); + } + else{ + res = write(fd, "1", 1); + } + if(res < 0){ + STATUS() = "Kann net schreiben"; + return false; + } + + close(fd); + STATUS() = "Konnte lesen"; + return true; +} diff --git a/src/modules/sysfs/processinterface.h b/src/modules/sysfs/processinterface.h new file mode 100644 index 000000000..90f68e1fa --- /dev/null +++ b/src/modules/sysfs/processinterface.h @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Waldemar Eisenmenger - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#ifndef _PROCESSINTERFACE_H_ +#define _PROCESSINTERFACE_H_ + +#include <../../stdfblib/io/processinterfacebase.h> +#include +#include +#include + +class CSysFsProcessInterface : public CProcessInterfaceBase{ + +public: + CSysFsProcessInterface(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, + const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData); + virtual ~CSysFsProcessInterface(); + +protected: + bool initialise(bool m_bInputOrOutput); + bool deinitialise(); + bool writePin(); + bool readPin(); + +private: + bool checkPin(); + const static int scmBuffer = 100; + + int mPinNumber; + + static const char * const scmPinInUse; + static const char * const scmInitDeinitOK; + static const char * const scmNotInitialised; + +}; + +//tell the IX and QX FB that this is the process interface to be used +typedef CSysFsProcessInterface CProcessInterface; + +#endif /* PROCESSINTERFACE_H_ */ diff --git a/src/modules/utils/CMakeLists.txt b/src/modules/utils/CMakeLists.txt new file mode 100644 index 000000000..9298408ed --- /dev/null +++ b/src/modules/utils/CMakeLists.txt @@ -0,0 +1,21 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2014 AIT, ACIN, Profactor GmbH, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Thomas Strasser, Alois Zoitl, Matthias Plasch +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +forte_add_module(UTILS "FORTE UTILITY FBs") + +############################################################################# +# FORTE UTILITY FBs +############################################################################# +forte_add_sourcefile_hcpp(OUT_ANY_CONSOLE GEN_F_MUX GEN_CSV_WRITER GEN_APPEND_STRING) +forte_add_sourcefile_hcpp(GEN_ARRAY2VALUES GEN_VALUES2ARRAY GEN_ARRAY2ARRAY GET_AT_INDEX SET_AT_INDEX) +forte_add_sourcefile_hcpp(STEST_END) + +forte_add_subdirectory(tests) diff --git a/src/modules/utils/GEN_APPEND_STRING.cpp b/src/modules/utils/GEN_APPEND_STRING.cpp new file mode 100644 index 000000000..5a0f7e4a6 --- /dev/null +++ b/src/modules/utils/GEN_APPEND_STRING.cpp @@ -0,0 +1,189 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2014 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_APPEND_STRING.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_APPEND_STRING_gen.cpp" +#endif +#include +#include +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_APPEND_STRING, g_nStringIdGEN_APPEND_STRING); + +const CStringDictionary::TStringId GEN_APPEND_STRING::scm_anEventOutputNames[] = { g_nStringIdCNF }; +const CStringDictionary::TStringId GEN_APPEND_STRING::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const CStringDictionary::TStringId GEN_APPEND_STRING::scm_anDataOutputNames[] = {g_nStringIdOUT}; +const CStringDictionary::TStringId GEN_APPEND_STRING::scm_anDataOutputTypeIds[] = {g_nStringIdSTRING}; + +const TForteInt16 GEN_APPEND_STRING::scm_anEIWithIndexes[] = {0}; + +const TDataIOID GEN_APPEND_STRING::scm_anEOWith[] = {0, 255}; +const TForteInt16 GEN_APPEND_STRING::scm_anEOWithIndexes[] = {0, -1}; + +//default value is set to 100 (sufficient for several data types) +const TForteInt16 GEN_APPEND_STRING::scm_maxStringBufSize = 100; + +GEN_APPEND_STRING::GEN_APPEND_STRING(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : +CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ +} + +GEN_APPEND_STRING::~GEN_APPEND_STRING(){ + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anEIWith; +} + +void GEN_APPEND_STRING::executeEvent(int pa_nEIID){ + + if(pa_nEIID < 1 && pa_nEIID > -1){ + //pointers to data inputs and data output + CIEC_ANY *pDataInput; + CIEC_ANY *pDataOutput = getDO(0); + + int nUsedBytes = -1; + TForteUInt16 nBytesFree = 0; + TForteUInt16 nCurrentLength = 0; + TForteUInt16 nArrayElements = 0; + TForteUInt16 nRequiredBytes = 0; + TForteUInt16 nStringLength = 0; + + //iterate over data inputs + for(int input_index = 0; input_index < m_nDInputs; input_index++){ + //get current data input + pDataInput = getDI(input_index); + + //for string data inputs of type CIEC_STRING or CIEC_WSTRING + if(pDataInput->getDataTypeID() == CIEC_ANY::e_STRING || pDataInput->getDataTypeID() == CIEC_ANY::e_WSTRING){ + //get length of input string + nStringLength = static_cast(pDataInput)->length(); + + if(input_index == 0){ + //initialize output with first value to append + (static_cast(pDataOutput))->assign((static_cast(pDataInput))->getValue(), nStringLength); + } + else{ + //append string value to output + (static_cast(pDataOutput))->append((static_cast(pDataInput))->getValue(), nStringLength); + } + } + //no string data type (use method toString) + else{ + if(pDataInput->getDataTypeID() == CIEC_ANY::e_ARRAY){ + //get number of array elements + nArrayElements = (static_cast(pDataInput))->size(); + //number of required bytes (including brackets '[' ']' and ',' separators + nRequiredBytes = nArrayElements * scm_maxStringBufSize + nArrayElements + static_cast(1); + } + else{ + //size for single data values + nRequiredBytes = scm_maxStringBufSize; + } + + + if((static_cast(pDataOutput))->length() != static_cast(0) && input_index != 0){ + //if data has been written to pDataOutput and input_index does not refer to first input + //get length and number of free bytes (unused memory) + nCurrentLength = (static_cast(pDataOutput))->length(); + nBytesFree = (static_cast(pDataOutput))->getCapacity() - nCurrentLength; + + //if there is not enough free memory ==> reserve + if(nBytesFree < nRequiredBytes){ + //reserve currentLength + extension Length + (static_cast(pDataOutput))->reserve(nCurrentLength + nRequiredBytes); + } + } + //if first data input or no data has yet been written + else{ + //reset nCurrentLength and nBytesFree + nCurrentLength = 0; + nBytesFree = 0; + //reserve required length + (static_cast(pDataOutput))->reserve(nRequiredBytes); + } + + //append the value which has been converted to a string ==> enough capacity is required + if((static_cast(pDataOutput))->getCapacity() - nCurrentLength >= nRequiredBytes){ + //use toString to write the Data (observe offset nCurrentLength) + nUsedBytes = pDataInput->toString(((static_cast(pDataOutput))->getValue()) + nCurrentLength, nRequiredBytes); + //maintain the state of the output data value string + (static_cast(pDataOutput))->assign((static_cast(pDataOutput))->getValue(), nCurrentLength + nUsedBytes); + } + } + } + sendOutputEvent(0); + } +} + +bool GEN_APPEND_STRING::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + + const char *pcPos = strrchr(pa_acConfigString, '_'); + + if(0 != pcPos){ + ++pcPos; + if('S' != *pcPos){ + //we have an underscore and it is not the first underscore after E + m_nDInputs = forte::core::util::strtoul(pcPos,0,10); + DEVLOG_DEBUG("DIs: %d;\n", m_nDInputs); + } + else{ + m_nDInputs = 0; + } + } + else{ + return false; + } + + if(m_nDInputs < 2){ + + return false; + } + + //now the number of needed eventInputs and dataOutputs are available in the integer array + //create the eventInputs + if(m_nDInputs < CFunctionBlock::scm_nMaxInterfaceEvents){ + + //create the data inputs + m_anDataInputNames = new CStringDictionary::TStringId[m_nDInputs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[m_nDInputs]; + + generateGenericDataPointArrays("IN_", m_anDataInputTypeIds, m_anDataInputNames, m_nDInputs); + + //now create the WITH constructs... + //the With-Indexes for the data variables + m_anEIWith = new TDataIOID[m_nDInputs + 1]; //for inputs + '255' separators at the list end + + //in-withs + for(int in_with = 0; in_with < m_nDInputs + 1; in_with = in_with + 1){ + if(in_with == m_nDInputs){ + //set end separator of with + m_anEIWith[in_with] = 255; + } + else{ + m_anEIWith[in_with] = static_cast(in_with); + } + } + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, m_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, m_nDInputs, m_anDataInputNames, m_anDataInputTypeIds, 1, scm_anDataOutputNames, scm_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize(pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize(pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + return bRetVal; +} diff --git a/src/modules/utils/GEN_APPEND_STRING.h b/src/modules/utils/GEN_APPEND_STRING.h new file mode 100644 index 000000000..270cb9024 --- /dev/null +++ b/src/modules/utils/GEN_APPEND_STRING.h @@ -0,0 +1,61 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_APPEND_STRING_H_ +#define _GEN_APPEND_STRING_H_ + +#include +#include +#include + +class GEN_APPEND_STRING : public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_APPEND_STRING) + + private: + //we know for sure that there is one output event and one input event + static const TEventID scm_nEventCNFID = 0; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const TEventID scm_nEventREQID = 0; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + + static const TForteInt16 scm_anEIWithIndexes[]; + TDataIOID *m_anEIWith; + + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + + //maximum string buffer size for conversions into string values + static const TForteInt16 scm_maxStringBufSize; + //self-defined members + int m_nDInputs; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void executeEvent(int pa_nEIID); + + GEN_APPEND_STRING(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_APPEND_STRING(); + public: + + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); +}; +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/utils/GEN_ARRAY2ARRAY.cpp b/src/modules/utils/GEN_ARRAY2ARRAY.cpp new file mode 100644 index 000000000..ac78605f1 --- /dev/null +++ b/src/modules/utils/GEN_ARRAY2ARRAY.cpp @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_ARRAY2ARRAY.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_ARRAY2ARRAY_gen.cpp" +#endif + +DEFINE_GENERIC_FIRMWARE_FB(GEN_ARRAY2ARRAY, g_nStringIdGEN_ARRAY2ARRAY) + + const CStringDictionary::TStringId GEN_ARRAY2ARRAY::scm_anDataInputNames[] = {g_nStringIdIN}; +const CStringDictionary::TStringId GEN_ARRAY2ARRAY::scm_anDataOutputNames[] = {g_nStringIdOUT}; + +const TForteInt16 GEN_ARRAY2ARRAY::scm_anEIWithIndexes[] = {0}; +const TDataIOID GEN_ARRAY2ARRAY::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId GEN_ARRAY2ARRAY::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID GEN_ARRAY2ARRAY::scm_anEOWith[] = {0, 255}; +const TForteInt16 GEN_ARRAY2ARRAY::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId GEN_ARRAY2ARRAY::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +GEN_ARRAY2ARRAY::GEN_ARRAY2ARRAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : +CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ +} + +GEN_ARRAY2ARRAY::~GEN_ARRAY2ARRAY(){ + delete[] m_anDataInputTypeIds; + delete[] m_anDataOutputTypeIds; +} + +void GEN_ARRAY2ARRAY::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + + OUT_Array().setValue(IN_Array()); + + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + +bool GEN_ARRAY2ARRAY::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + const char *dTypePos = 0; + const char *dNumberPos = strchr(pa_acConfigString, '_'); + + if(0 != dNumberPos){ + ++dNumberPos; + //get position of a second underscore + dTypePos = strchr(dNumberPos, '_'); + + if(0 != dTypePos){ + //there is a number and a data type of inputs within the typename + m_nArrayLength = forte::core::util::strtoul(dNumberPos,0,10); + + unsigned int nLen = strlen(++dTypePos); + if(nLen < cg_nIdentifierLength){ + char dTypeName[cg_nIdentifierLength + 1]; + + strncpy(dTypeName, dTypePos, nLen); + dTypeName[nLen] = '\0'; + //get the data type id + m_ValueTypeID = CStringDictionary::getInstance().getId(dTypeName); + //DEVLOG_DEBUG("ValueType: %s, DIs: %d;\n", dTypeName, m_nDInputs); + } + } + else{ + m_ValueTypeID = CStringDictionary::scm_nInvalidStringId; + m_nArrayLength = 0; + } + } + else{ + return false; + } + + if(m_ValueTypeID != CStringDictionary::scm_nInvalidStringId && m_nArrayLength >= 1){ + //create data input type + m_anDataInputTypeIds = new CStringDictionary::TStringId[3]; + m_anDataInputTypeIds[0] = g_nStringIdARRAY; + m_anDataInputTypeIds[1] = m_nArrayLength; + m_anDataInputTypeIds[2] = m_ValueTypeID; + + //create data output type + m_anDataOutputTypeIds = new CStringDictionary::TStringId[3]; + m_anDataOutputTypeIds[0] = g_nStringIdARRAY; + m_anDataOutputTypeIds[1] = m_nArrayLength; + m_anDataOutputTypeIds[2] = m_ValueTypeID; + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, m_anDataInputTypeIds, 1, scm_anDataOutputNames, m_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize(pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize(pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + + return bRetVal; +} + diff --git a/src/modules/utils/GEN_ARRAY2ARRAY.h b/src/modules/utils/GEN_ARRAY2ARRAY.h new file mode 100644 index 000000000..8eb4e88ad --- /dev/null +++ b/src/modules/utils/GEN_ARRAY2ARRAY.h @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_ARRAY2ARRAY_H_ +#define _GEN_ARRAY2ARRAY_H_ + +#include +#include + +class GEN_ARRAY2ARRAY: public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_ARRAY2ARRAY) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + CIEC_ARRAY &IN_Array() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + CStringDictionary::TStringId *m_anDataOutputTypeIds; + + CIEC_ARRAY &OUT_Array() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + //self-defined members + CStringDictionary::TStringId m_ValueTypeID; + unsigned int m_nArrayLength; + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + virtual void executeEvent(int pa_nEIID); + + GEN_ARRAY2ARRAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_ARRAY2ARRAY();; + +public: + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/utils/GEN_ARRAY2VALUES.cpp b/src/modules/utils/GEN_ARRAY2VALUES.cpp new file mode 100644 index 000000000..d483fe760 --- /dev/null +++ b/src/modules/utils/GEN_ARRAY2VALUES.cpp @@ -0,0 +1,144 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_ARRAY2VALUES.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_ARRAY2VALUES_gen.cpp" +#endif + +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_ARRAY2VALUES, g_nStringIdGEN_ARRAY2VALUES) + +const CStringDictionary::TStringId GEN_ARRAY2VALUES::scm_anDataInputNames[] = { g_nStringIdIN }; + +const TForteInt16 GEN_ARRAY2VALUES::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID GEN_ARRAY2VALUES::scm_anEIWith[] = { 0, 255 }; +const CStringDictionary::TStringId GEN_ARRAY2VALUES::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const TForteInt16 GEN_ARRAY2VALUES::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId GEN_ARRAY2VALUES::scm_anEventOutputNames[] = { g_nStringIdCNF }; + +GEN_ARRAY2VALUES::GEN_ARRAY2VALUES(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ +} + +GEN_ARRAY2VALUES::~GEN_ARRAY2VALUES(){ + delete[] m_anDataOutputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anDataOutputTypeIds; + delete[] m_anEOWith; +} + +void GEN_ARRAY2VALUES::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventREQID: + + for(int output_index = 0; output_index < m_nDOutputs; output_index++){ + //copy input values to array + getDO(output_index)->saveAssign(*(IN_Array()[output_index])); + } + + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + +bool GEN_ARRAY2VALUES::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + const char *dTypePos = 0; + const char *dNumberPos = strchr(pa_acConfigString, '_'); + + if(0 != dNumberPos){ + ++dNumberPos; + //get position of a second underscore + dTypePos = strchr(dNumberPos, '_'); + + if(0 != dTypePos){ + //there is a number and a data type of inputs within the typename + m_nDOutputs = forte::core::util::strtoul(dNumberPos, 0, 10); + + int nLen = strlen(++dTypePos); + if(nLen < cg_nIdentifierLength){ + char dTypeName[cg_nIdentifierLength + 1]; + + strncpy(dTypeName, dTypePos, nLen); + dTypeName[nLen] = '\0'; + //get the data type id + m_ValueTypeID = CStringDictionary::getInstance().getId(dTypeName); + //DEVLOG_DEBUG("ValueType: %s, DIs: %d;\n", dTypeName, m_nDInputs); + } + } + else{ + m_ValueTypeID = CStringDictionary::scm_nInvalidStringId; + m_nDOutputs = 0; + } + } + else{ + return false; + } + + if(m_ValueTypeID != CStringDictionary::scm_nInvalidStringId && m_nDOutputs >= 2){ + //create the data outputs + m_anDataOutputNames = new CStringDictionary::TStringId[m_nDOutputs]; + m_anDataOutputTypeIds = new CStringDictionary::TStringId[m_nDOutputs]; + + char doNames[cg_nIdentifierLength] = { "OUT_" }; + for(int doIndex = 0; doIndex < m_nDOutputs; doIndex = doIndex + 1){ +#ifdef WIN32 + _snprintf(&(doNames[4]), 8 - 4, "%i", doIndex+1); +#else + snprintf(&(doNames[4]), 8 - 4, "%i", doIndex + 1); +#endif + m_anDataOutputNames[doIndex] = CStringDictionary::getInstance().insert(doNames); + m_anDataOutputTypeIds[doIndex] = m_ValueTypeID; + } + + //create data input type + m_anDataInputTypeIds = new CStringDictionary::TStringId[3]; + m_anDataInputTypeIds[0] = g_nStringIdARRAY; + m_anDataInputTypeIds[1] = m_nDOutputs; + m_anDataInputTypeIds[2] = m_ValueTypeID; + + //get input with-indices for the data vars + m_anEOWith = new TDataIOID[m_nDOutputs + 1]; + + //in-withs + for(int out_with = 0; out_with < m_nDOutputs + 1; out_with = out_with + 1){ + if(out_with == m_nDOutputs){ + //set end separator of with + m_anEOWith[out_with] = 255; + } + else{ + m_anEOWith[out_with] = static_cast(out_with); + } + } + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = + new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, m_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, m_anDataInputTypeIds, m_nDOutputs, m_anDataOutputNames, m_anDataOutputTypeIds); + + TForteByte *acFBConnData = + new TForteByte[genFBConnDataSize(pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = + new TForteByte[genFBVarsDataSize(pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + + return bRetVal; +} + diff --git a/src/modules/utils/GEN_ARRAY2VALUES.h b/src/modules/utils/GEN_ARRAY2VALUES.h new file mode 100644 index 000000000..134ce15a0 --- /dev/null +++ b/src/modules/utils/GEN_ARRAY2VALUES.h @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH, fortiss GbmH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_ARRAY2VALUES_H_ +#define _GEN_ARRAY2VALUES_H_ + +#include +#include + +class GEN_ARRAY2VALUES : public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_ARRAY2VALUES) + + private: + CStringDictionary::TStringId *m_anDataOutputNames; + CStringDictionary::TStringId *m_anDataOutputTypeIds; + + static const CStringDictionary::TStringId scm_anDataInputNames[]; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + CIEC_ARRAY &IN_Array(){ + return *static_cast(getDI(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + TDataIOID *m_anEOWith; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + //self-defined members + int m_nDOutputs; + CStringDictionary::TStringId m_ValueTypeID; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + virtual void executeEvent(int pa_nEIID); + + GEN_ARRAY2VALUES(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_ARRAY2VALUES(); + + public: + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/utils/GEN_CSV_WRITER.cpp b/src/modules/utils/GEN_CSV_WRITER.cpp new file mode 100644 index 000000000..801059e2a --- /dev/null +++ b/src/modules/utils/GEN_CSV_WRITER.cpp @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_CSV_WRITER.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_CSV_WRITER_gen.cpp" +#endif +#include +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_CSV_WRITER, g_nStringIdGEN_CSV_WRITER); + +const CStringDictionary::TStringId GEN_CSV_WRITER::scm_anDataOutputNames[] = { g_nStringIdQO, g_nStringIdSTATUS }; + +const CStringDictionary::TStringId GEN_CSV_WRITER::scm_anDataOutputTypeIds[] = { g_nStringIdBOOL, g_nStringIdSTRING }; + +const CStringDictionary::TStringId GEN_CSV_WRITER::scm_anEventInputNames[] = { g_nStringIdINIT, g_nStringIdREQ }; + +const TForteInt16 GEN_CSV_WRITER::scm_anEIWithIndexes[] = { 0, 3 }; +const TDataIOID GEN_CSV_WRITER::scm_anEOWith[] = { 0, 1, 255, 0, 1, 255 }; +const TForteInt16 GEN_CSV_WRITER::scm_anEOWithIndexes[] = { 0, 3, -1 }; +const CStringDictionary::TStringId GEN_CSV_WRITER::scm_anEventOutputNames[] = { g_nStringIdINITO, g_nStringIdCNF }; + +void GEN_CSV_WRITER::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventINITID: + if(true == QI()){ + openCSVFile(); + } + else{ + closeCSVFile(); + } + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + QO() = QI(); + if(true == QI()){ + writeCSVFileLine(); + } + sendOutputEvent(scm_nEventREQID); + break; + } +} + +GEN_CSV_WRITER::GEN_CSV_WRITER(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ + m_pstCSVFile = 0; +} + +GEN_CSV_WRITER::~GEN_CSV_WRITER(){ + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anEIWith; +} + +bool GEN_CSV_WRITER::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + + const char *acPos = strrchr(pa_acConfigString, '_'); + if(0 != acPos){ + acPos++; + int nNumDIs = forte::core::util::strtoul(acPos,0,10); + nNumDIs += 2; // we have in addition to the SDs a QI and FILE_NAME data inputs + + m_anDataInputNames = new CStringDictionary::TStringId[nNumDIs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[nNumDIs]; + + m_anDataInputNames[0] = g_nStringIdQI; + m_anDataInputTypeIds[0] = g_nStringIdBOOL; + m_anDataInputNames[1] = g_nStringIdFILE_NAME; + m_anDataInputTypeIds[1] = g_nStringIdSTRING; + + generateGenericDataPointArrays("SD_", &(m_anDataInputTypeIds[2]), &(m_anDataInputNames[2]), nNumDIs - 2); + + m_anEIWith = new TDataIOID[3 + nNumDIs]; + + m_anEIWith[0] = 0; + m_anEIWith[1] = 1; + m_anEIWith[2] = 255; + m_anEIWith[3] = 0; + + for(TDataIOID i = 2; i < (nNumDIs); i++){ + m_anEIWith[i + 2] = i; + } + + m_anEIWith[2 + nNumDIs] = 255; + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = new SFBInterfaceSpecforGenerics(2, scm_anEventInputNames, m_anEIWith, scm_anEIWithIndexes, 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, nNumDIs, m_anDataInputNames, m_anDataInputTypeIds, 2, scm_anDataOutputNames, scm_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize(pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize(pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + return bRetVal; +} + +void GEN_CSV_WRITER::openCSVFile(){ + QO() = false; + if(0 == m_pstCSVFile){ + m_pstCSVFile = fopen(FILE_NAME().getValue(), "w+"); + if(0 != m_pstCSVFile){ + STATUS() = "OK"; + QO() = true; + } + else{ + STATUS() = strerror(errno); + } + } + else{ + STATUS() = "File already open"; + } +} + +void GEN_CSV_WRITER::closeCSVFile(){ + QO() = false; + if(0 != m_pstCSVFile){ + if(0 == fclose(m_pstCSVFile)){ + STATUS() = "OK"; + } + else{ + STATUS() = strerror(errno); + } + m_pstCSVFile = 0; + } +} + +void GEN_CSV_WRITER::writeCSVFileLine(){ + if(0 != m_pstCSVFile){ + char acBuffer[100]; + for(int i = 2; i < m_pstInterfaceSpec->m_nNumDIs; i++){ + int nLen = getDI(i)->toString(acBuffer, 100); + fwrite(acBuffer, 1, nLen, m_pstCSVFile); + fwrite("; ", 1, 2, m_pstCSVFile); + } + fwrite("\n", 1, 1, m_pstCSVFile); + } + else{ + QO() = false; + STATUS() = "File not opened"; + } +} + diff --git a/src/modules/utils/GEN_CSV_WRITER.h b/src/modules/utils/GEN_CSV_WRITER.h new file mode 100644 index 000000000..1577164ea --- /dev/null +++ b/src/modules/utils/GEN_CSV_WRITER.h @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Monika Wenger + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_CSV_WRITER_H_ +#define _GEN_CSV_WRITER_H_ + +#include +#include +#include +#include +#include + +class GEN_CSV_WRITER : public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_CSV_WRITER) + + private: + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + + CIEC_STRING &FILE_NAME(){ + return *static_cast(getDI(1)); + } + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + ; + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(1)); + } + ; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + void executeEvent(int pa_nEIID); + + public: + GEN_CSV_WRITER(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_CSV_WRITER(); + + virtual bool configureFB(const char *pa_acConfigString); + + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + private: + void openCSVFile(); + void closeCSVFile(); + void writeCSVFileLine(); + + FILE *m_pstCSVFile; + + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + TDataIOID *m_anEIWith; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/utils/GEN_F_MUX.cpp b/src/modules/utils/GEN_F_MUX.cpp new file mode 100644 index 000000000..33a00f6d3 --- /dev/null +++ b/src/modules/utils/GEN_F_MUX.cpp @@ -0,0 +1,249 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2013 Profactor GmbH, ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_F_MUX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_F_MUX_gen.cpp" +#endif +#include +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_F_MUX, g_nStringIdGEN_F_MUX); + +const CStringDictionary::TStringId GEN_F_MUX::scm_anEventOutputNames[] = { g_nStringIdEO }; + +GEN_F_MUX::GEN_F_MUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ +} + +GEN_F_MUX::~GEN_F_MUX(){ + delete[] m_anEventInputNames; + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anDataOutputNames; + delete[] m_anDataOutputTypeIds; + delete[] m_anEIWith; + delete[] m_anEIWithIndexes; + delete[] m_anEOWith; + delete[] m_anEOWithIndexes; +} + +void GEN_F_MUX::executeEvent(int pa_nEIID){ + + if(pa_nEIID < m_nEInputs && pa_nEIID > -1){ + + int startIndex = pa_nEIID * m_nDOutputs; + CIEC_ANY *p_dataInput; + CIEC_ANY *p_dataOutput; + bool status = true; + + for(int input_index = startIndex, output_index = 2; input_index < startIndex + m_nDOutputs; input_index++, output_index++){ + + p_dataInput = getDI(input_index); + p_dataOutput = getDO(output_index); + + // check whether datatypes match + if(p_dataInput != 0 && p_dataOutput != 0 && p_dataInput->getDataTypeID() == p_dataOutput->getDataTypeID()){ + + p_dataOutput->setValue(*p_dataInput); + status = true && status; + } + else{ + status = false; + } + } + + if(status == true){ + *static_cast(getDO(0)) = true; + *static_cast(getDO(1)) = "OK"; + } + else{ + *static_cast(getDO(0)) = false; + *static_cast(getDO(1)) = "Datatype ERROR"; + } + + sendOutputEvent(0); + } +} + +bool GEN_F_MUX::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + int index = 0; + char *paramEI = 0; + char *paramDO = 0; + char baseName[cg_nIdentifierLength]; + + TIdentifier typeIdString; + size_t inlength; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + + memcpy(typeIdString, pa_acConfigString, cg_nIdentifierLength); + + typeIdString[cg_nIdentifierLength] = '\0'; //make a string + + inlength = strlen(typeIdString); + + for(index = 0; index < (int) inlength - 1; index++){ + + if(typeIdString[index] == '_'){ + + //make sure that there is no invalid index + if(index - 1 >= 0){ + memcpy(&baseName[0], &typeIdString[index - 1], 5); // F_MUX ... prefix has 5 characters + baseName[5] = '\0'; + + //check if the prefix F_MUX exists; in this case, the next "_" separates the parameters + if(strcmp(baseName, "F_MUX") == 0){ + continue; + } + } + else{ + //error on creating the FB; this would mean that the Typename starts with "_" + return false; + } + + paramEI = paramDO = &(typeIdString[index + 1]); + break; + } + } + if(paramDO != 0){ + + for(index = index + 1; index < (int) inlength - 1; index++){ + + if(typeIdString[index] == '_'){ + + typeIdString[index] = '\0'; + paramDO = &(typeIdString[index + 1]); + break; + } + } + } + + if(paramDO == 0){ + + return false; + } + else{ + //set the data and event port numbers + m_nEInputs = forte::core::util::strtoul(paramEI,0,10); + m_nDOutputs = forte::core::util::strtoul(paramDO,0,10); + m_nEOutputs = 1; + m_nDInputs = m_nEInputs * m_nDOutputs; + + DEVLOG_DEBUG("EIs: %d; DIs: %d; EOs: %d; DOs: %d \n", m_nEInputs, m_nDInputs, m_nEOutputs, m_nDOutputs); + + //return with error if there are not enough event inputs (use common merge FB instead!!) + if(m_nEInputs < 2){ + DEVLOG_ERROR("At least 2 Event Inputs need to be set\n"); + return false; + } + } + + //now the number of needed eventInputs and dataOutputs are available in the integer array + //create the eventInputs + if(m_nEInputs < CFunctionBlock::scm_nMaxInterfaceEvents && m_nDInputs < CFunctionBlock::scm_nMaxInterfaceEvents){ + //create the eventInputs + m_anEventInputNames = new CStringDictionary::TStringId[m_nEInputs]; + + generateGenericInterfacePointNameArray("EI", m_anEventInputNames, m_nEInputs); + + //create the data inputs + m_anDataInputNames = new CStringDictionary::TStringId[m_nDInputs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[m_nDInputs]; + char diNames[cg_nIdentifierLength] = { "IN_" }; + int di_posIndex = 0; + for(int ei = 0; ei < m_nEInputs; ei = ei + 1){ + + for(int di = 0; di < m_nDOutputs; di = di + 1){ + +#ifdef WIN32 + _snprintf(&(diNames[3]), 11 - 3, "%i_%i", ei+1, di+1); +#else + snprintf(&(diNames[3]), 11 - 3, "%i_%i", ei + 1, di + 1); +#endif + di_posIndex = ei * m_nDOutputs + di; + m_anDataInputNames[di_posIndex] = CStringDictionary::getInstance().insert(diNames); + m_anDataInputTypeIds[di_posIndex] = g_nStringIdANY; + } + } + + //create the data outputs + m_anDataOutputNames = new CStringDictionary::TStringId[m_nDOutputs + 2]; + m_anDataOutputTypeIds = new CStringDictionary::TStringId[m_nDOutputs + 2]; + + //data outputs for status and QO + m_anDataOutputNames[0] = CStringDictionary::getInstance().insert("QO"); + m_anDataOutputTypeIds[0] = g_nStringIdBOOL; + m_anDataOutputNames[1] = CStringDictionary::getInstance().insert("STATUS"); + m_anDataOutputTypeIds[1] = g_nStringIdWSTRING; + + generateGenericDataPointArrays("OUT_", &(m_anDataOutputTypeIds[2]), &(m_anDataOutputNames[2]), m_nDOutputs); + + //now create the WITH constructs... + //first the With-Indexes Events + m_anEIWithIndexes = new TForteInt16[m_nEInputs]; + m_anEOWithIndexes = new TForteInt16[2]; //contains terminating -1 value + + for(int ei_index = 0; ei_index < m_nEInputs; ei_index = ei_index + 1){ + if(ei_index == 0){ + m_anEIWithIndexes[ei_index] = 0; + } + else{ + m_anEIWithIndexes[ei_index] = ei_index * (m_nDOutputs + 1); + } + } + + m_anEOWithIndexes[0] = 0; + m_anEOWithIndexes[1] = -1; + + //second the With-Indexes for the data variables + m_anEIWith = new TDataIOID[m_nDInputs + m_nEInputs]; //for inputs per event + '255' separators between withs + m_anEOWith = new TDataIOID[m_nDOutputs + 2 + 1]; //for outputs only one '255' separator since one output event is needed + 2 for QO and STATUS + + //in-withs + int withListIndex = 0; + int dataIndex = 0; + for(int in_block = 0; in_block < m_nEInputs; in_block = in_block + 1){ + + for(int in_with = 0; in_with < m_nDOutputs; in_with = in_with + 1){ + m_anEIWith[withListIndex] = static_cast(dataIndex); + withListIndex++; + dataIndex++; + } + + //set '255' separator + m_anEIWith[withListIndex] = 255; + withListIndex++; + } + + //out-withs + m_anEOWith[0] = 0; //for QO and STATUS + m_anEOWith[1] = 1; + + for(int out_with = 2; out_with < m_nDOutputs + 2; out_with = out_with + 1){ + m_anEOWith[out_with] = static_cast(out_with); + } + //set '255' separator + m_anEOWith[m_nDOutputs + 2] = 255; + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = new SFBInterfaceSpecforGenerics(m_nEInputs, m_anEventInputNames, m_anEIWith, m_anEIWithIndexes, m_nEOutputs, scm_anEventOutputNames, m_anEOWith, m_anEOWithIndexes, m_nDInputs, m_anDataInputNames, m_anDataInputTypeIds, m_nDOutputs + 2, m_anDataOutputNames, m_anDataOutputTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize(pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize(pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + return bRetVal; +} diff --git a/src/modules/utils/GEN_F_MUX.h b/src/modules/utils/GEN_F_MUX.h new file mode 100644 index 000000000..685d8a987 --- /dev/null +++ b/src/modules/utils/GEN_F_MUX.h @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2012 - 2015 Profactor GmbH, ACIN, fortiss Gmbh + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Monika Wenger, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_F_MUX_H_ +#define _GEN_F_MUX_H_ + +#include +#include + +class GEN_F_MUX : public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_F_MUX) + + private: + //we know for sure that there is one output event + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const TEventID scm_nEventEOID = 0; + + CStringDictionary::TStringId *m_anEventInputNames; + CStringDictionary::TStringId *m_anDataOutputNames; + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataOutputTypeIds; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + TForteInt16 *m_anEIWithIndexes; + TDataIOID *m_anEIWith; + + TForteInt16 *m_anEOWithIndexes; + TDataIOID *m_anEOWith; + + //self-defined members + unsigned int m_nEInputs; + unsigned int m_nEOutputs; + unsigned int m_nDInputs; + unsigned int m_nDOutputs; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void executeEvent(int pa_nEIID); + + GEN_F_MUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_F_MUX(); + public: + + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); +}; +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/utils/GEN_VALUES2ARRAY.cpp b/src/modules/utils/GEN_VALUES2ARRAY.cpp new file mode 100644 index 000000000..b49df402f --- /dev/null +++ b/src/modules/utils/GEN_VALUES2ARRAY.cpp @@ -0,0 +1,146 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_VALUES2ARRAY.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_VALUES2ARRAY_gen.cpp" +#endif + +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_VALUES2ARRAY, g_nStringIdGEN_VALUES2ARRAY) + +const CStringDictionary::TStringId GEN_VALUES2ARRAY::scm_anDataOutputNames[] = { g_nStringIdOUT }; + +const TForteInt16 GEN_VALUES2ARRAY::scm_anEIWithIndexes[] = { 0 }; +const CStringDictionary::TStringId GEN_VALUES2ARRAY::scm_anEventInputNames[] = { g_nStringIdREQ }; + +const TDataIOID GEN_VALUES2ARRAY::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 GEN_VALUES2ARRAY::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId GEN_VALUES2ARRAY::scm_anEventOutputNames[] = { g_nStringIdCNF }; + +GEN_VALUES2ARRAY::GEN_VALUES2ARRAY(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ +} + +GEN_VALUES2ARRAY::~GEN_VALUES2ARRAY(){ + delete[] m_anDataInputNames; + delete[] m_anDataInputTypeIds; + delete[] m_anDataOutputTypeIds; + delete[] m_anEIWith; +} + +void GEN_VALUES2ARRAY::executeEvent(int pa_nEIID){ + switch (pa_nEIID){ + case scm_nEventREQID: + + for(int input_index = 0; input_index < m_nDInputs; input_index++){ + //copy input values to array + OUT_Array()[input_index]->saveAssign(*getDI(input_index)); + } + + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + +bool GEN_VALUES2ARRAY::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + const char *dTypePos = 0; + const char *dNumberPos = strchr(pa_acConfigString, '_'); + + if(0 != dNumberPos){ + ++dNumberPos; + //get position of a second underscore + dTypePos = strchr(dNumberPos, '_'); + + if(0 != dTypePos){ + //there is a number and a data type of inputs within the typename + m_nDInputs = forte::core::util::strtoul(dNumberPos, 0, 10); + + unsigned int nLen = strlen(++dTypePos); + if(nLen < cg_nIdentifierLength){ + char dTypeName[cg_nIdentifierLength + 1]; + + strncpy(dTypeName, dTypePos, nLen); + dTypeName[nLen] = '\0'; + //get the data type id + m_ValueTypeID = CStringDictionary::getInstance().getId(dTypeName); + //DEVLOG_DEBUG("ValueType: %s, DIs: %d;\n", dTypeName, m_nDInputs); + } + } + else{ + m_ValueTypeID = CStringDictionary::scm_nInvalidStringId; + m_nDInputs = 0; + } + } + else{ + return false; + } + + if(m_ValueTypeID != CStringDictionary::scm_nInvalidStringId && m_nDInputs >= 2){ + //create the data inputs + m_anDataInputNames = new CStringDictionary::TStringId[m_nDInputs]; + m_anDataInputTypeIds = new CStringDictionary::TStringId[m_nDInputs]; + + char diNames[cg_nIdentifierLength] = { "IN_" }; + for(int di = 0; di < m_nDInputs; di = di + 1){ +#ifdef WIN32 + _snprintf(&(diNames[3]), 7 - 3, "%i", di+1); +#else + snprintf(&(diNames[3]), 7 - 3, "%i", di + 1); +#endif + m_anDataInputNames[di] = CStringDictionary::getInstance().insert(diNames); + m_anDataInputTypeIds[di] = m_ValueTypeID; + } + + //create data output type + m_anDataOutputTypeIds = new CStringDictionary::TStringId[3]; + m_anDataOutputTypeIds[0] = g_nStringIdARRAY; + m_anDataOutputTypeIds[1] = m_nDInputs; + m_anDataOutputTypeIds[2] = m_ValueTypeID; + + //get input with-indices for the data vars + m_anEIWith = new TDataIOID[m_nDInputs + 1]; + + //in-withs + for(int in_with = 0; in_with < m_nDInputs + 1; in_with = in_with + 1){ + if(in_with == m_nDInputs){ + //set end separator of with + m_anEIWith[in_with] = 255; + } + else{ + m_anEIWith[in_with] = static_cast(in_with); + } + } + + //create the interface Specification + SFBInterfaceSpecforGenerics *pstInterfaceSpec = + new SFBInterfaceSpecforGenerics(1, scm_anEventInputNames, m_anEIWith, scm_anEIWithIndexes, 1, scm_anEventOutputNames, + scm_anEOWith, scm_anEOWithIndexes, static_cast(m_nDInputs), m_anDataInputNames, m_anDataInputTypeIds, 1, scm_anDataOutputNames, + m_anDataOutputTypeIds); + + TForteByte *acFBConnData = + new TForteByte[genFBConnDataSize(pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = + new TForteByte[genFBVarsDataSize(pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + + return bRetVal; +} + diff --git a/src/modules/utils/GEN_VALUES2ARRAY.h b/src/modules/utils/GEN_VALUES2ARRAY.h new file mode 100644 index 000000000..899093d76 --- /dev/null +++ b/src/modules/utils/GEN_VALUES2ARRAY.h @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_VALUES2ARRAY_H_ +#define _GEN_VALUES2ARRAY_H_ + +#include +#include + +class GEN_VALUES2ARRAY : public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_VALUES2ARRAY) + + private: + CStringDictionary::TStringId *m_anDataInputNames; + CStringDictionary::TStringId *m_anDataInputTypeIds; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + CStringDictionary::TStringId *m_anDataOutputTypeIds; + + CIEC_ARRAY &OUT_Array(){ + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + TDataIOID *m_anEIWith; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + //self-defined members + unsigned int m_nDInputs; + CStringDictionary::TStringId m_ValueTypeID; + + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + virtual void executeEvent(int pa_nEIID); + + GEN_VALUES2ARRAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_VALUES2ARRAY(); + + public: + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/utils/GET_AT_INDEX.cpp b/src/modules/utils/GET_AT_INDEX.cpp new file mode 100644 index 000000000..4d1221891 --- /dev/null +++ b/src/modules/utils/GET_AT_INDEX.cpp @@ -0,0 +1,80 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GET_AT_INDEX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GET_AT_INDEX_gen.cpp" +#endif +#include +#include + +DEFINE_FIRMWARE_FB(FORTE_GET_AT_INDEX, g_nStringIdGET_AT_INDEX) + + const CStringDictionary::TStringId FORTE_GET_AT_INDEX::scm_anDataInputNames[] = {g_nStringIdIN_ARRAY, g_nStringIdINDEX}; + +const CStringDictionary::TStringId FORTE_GET_AT_INDEX::scm_anDataInputTypeIds[] = {g_nStringIdANY, g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_GET_AT_INDEX::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_GET_AT_INDEX::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdANY}; + +const TForteInt16 FORTE_GET_AT_INDEX::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_GET_AT_INDEX::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId FORTE_GET_AT_INDEX::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_GET_AT_INDEX::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FORTE_GET_AT_INDEX::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_GET_AT_INDEX::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_GET_AT_INDEX::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_GET_AT_INDEX::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + + if(CIEC_ANY::e_ARRAY == IN_ARRAY().getDataTypeID()){ + CIEC_ARRAY &rInArray = static_cast(IN_ARRAY()); + //check if data types match + if(rInArray.getElementDataTypeID() == OUT().getDataTypeID()){ + //now check array length of input array + if(INDEX() < rInArray.size()){ + //update the output value + OUT().setValue(*rInArray[INDEX()]); + QO() = true; + } + else{ + DEVLOG_DEBUG("Access index out of range.\n"); + QO() = false; + } + } + else{ + DEVLOG_DEBUG("Inequal element data types.\n"); + QO() = false; + } + } + else{ + DEVLOG_DEBUG("No 'Array' typed input and output data.\n"); + QO() = false; + } + sendOutputEvent(scm_nEventCNFID); + + break; + } +} + + + diff --git a/src/modules/utils/GET_AT_INDEX.h b/src/modules/utils/GET_AT_INDEX.h new file mode 100644 index 000000000..b64cbb145 --- /dev/null +++ b/src/modules/utils/GET_AT_INDEX.h @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GET_AT_INDEX_H_ +#define _GET_AT_INDEX_H_ + +#include +#include +#include +#include + +class FORTE_GET_AT_INDEX: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_GET_AT_INDEX) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY &IN_ARRAY() { + return *static_cast(getDI(0)); + }; + + CIEC_UINT &INDEX() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_ANY &OUT() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 2, 2, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_GET_AT_INDEX){ + }; + + virtual ~FORTE_GET_AT_INDEX(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/utils/OUT_ANY_CONSOLE.cpp b/src/modules/utils/OUT_ANY_CONSOLE.cpp new file mode 100644 index 000000000..80721279a --- /dev/null +++ b/src/modules/utils/OUT_ANY_CONSOLE.cpp @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 AIT, ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Alois Zoitl, Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "OUT_ANY_CONSOLE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "OUT_ANY_CONSOLE_gen.cpp" +#endif + +#include + +DEFINE_FIRMWARE_FB(FORTE_OUT_ANY_CONSOLE, g_nStringIdOUT_ANY_CONSOLE) + + const CStringDictionary::TStringId FORTE_OUT_ANY_CONSOLE::scm_anDataInputNames[] = +{ g_nStringIdQI, g_nStringIdLABEL, g_nStringIdIN }; + +const CStringDictionary::TStringId FORTE_OUT_ANY_CONSOLE::scm_anDataInputTypeIds[] = +{ g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdANY }; + +const CStringDictionary::TStringId FORTE_OUT_ANY_CONSOLE::scm_anDataOutputNames[] = +{ g_nStringIdQO }; + +const CStringDictionary::TStringId FORTE_OUT_ANY_CONSOLE::scm_anDataOutputTypeIds[] = +{ g_nStringIdBOOL }; + +const TForteInt16 FORTE_OUT_ANY_CONSOLE::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID FORTE_OUT_ANY_CONSOLE::scm_anEIWith[] = { 0, 2, 1, 255 }; +const CStringDictionary::TStringId FORTE_OUT_ANY_CONSOLE::scm_anEventInputNames[] = +{ g_nStringIdREQ }; + +const TDataIOID FORTE_OUT_ANY_CONSOLE::scm_anEOWith[] = { 0, 255 }; +const TForteInt16 FORTE_OUT_ANY_CONSOLE::scm_anEOWithIndexes[] = { 0, -1 }; +const CStringDictionary::TStringId FORTE_OUT_ANY_CONSOLE::scm_anEventOutputNames[] = +{ g_nStringIdCNF }; + +const SFBInterfaceSpec FORTE_OUT_ANY_CONSOLE::scm_stFBInterfaceSpec = { 1, + scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, + scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, + scm_anDataInputNames, scm_anDataInputTypeIds, 1, scm_anDataOutputNames, + scm_anDataOutputTypeIds, 0, 0 }; + +//default value is set to 100 (sufficient for several data types) +const TForteInt16 FORTE_OUT_ANY_CONSOLE::scm_maxStringBufSize = 100; + +void FORTE_OUT_ANY_CONSOLE::executeEvent(int pa_nEIID) { + switch (pa_nEIID) { + case scm_nEventREQID: + QO() = QI(); + if (true == QI()) { + TForteUInt16 nRequiredBytes; + TForteUInt16 nUsedBytes; + TForteUInt16 nStringLength; + CIEC_WSTRING sOutput; + char strbuf1[scm_maxStringBufSize]; + LABEL().toString(strbuf1, sizeof(strbuf1)); + + if(IN().getDataTypeID() == CIEC_ANY::e_STRING || IN().getDataTypeID() == CIEC_ANY::e_WSTRING){ + //obtain length of string value + nStringLength = (static_cast(&IN()))->length(); + //assign value + sOutput.assign((static_cast(&IN()))->getValue(), nStringLength); + } + else{ + //values other than strings + //for arrays + if(IN().getDataTypeID() == CIEC_ANY::e_ARRAY){ + //get number of array elements + TForteUInt16 nArrayElements = (static_cast(&IN()))->size(); + //number of required bytes (including brackets '[' ']' and ',' separators + nRequiredBytes = nArrayElements * scm_maxStringBufSize + nArrayElements + static_cast(1); + } + else{ + //size for single data values + nRequiredBytes = scm_maxStringBufSize; + } + + sOutput.reserve(nRequiredBytes); + //write StringValue + nUsedBytes = IN().toString(sOutput.getValue(), nRequiredBytes); + //maintain the state of the output data value string + sOutput.assign(sOutput.getValue(), nUsedBytes); + } + + DEVLOG_INFO(" %s = %s\n", strbuf1, sOutput.getValue()); + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + diff --git a/src/modules/utils/OUT_ANY_CONSOLE.h b/src/modules/utils/OUT_ANY_CONSOLE.h new file mode 100644 index 000000000..2f11b7ebd --- /dev/null +++ b/src/modules/utils/OUT_ANY_CONSOLE.h @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 AIT, ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Strasser, Monika Wenger, Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _OUT_ANY_CONSOLE_H_ +#define _OUT_ANY_CONSOLE_H_ + +#include +#include + +#include +#include + +class FORTE_OUT_ANY_CONSOLE: public CFunctionBlock { + DECLARE_FIRMWARE_FB(FORTE_OUT_ANY_CONSOLE) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + } + ; + + CIEC_STRING &LABEL() { + return *static_cast(getDI(1)); + } + ; + + CIEC_ANY &IN() { + return *static_cast(getDI(2)); + } + ; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + } + ; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + //maximum string buffer size for conversions into string values + static const TForteInt16 scm_maxStringBufSize; + + FORTE_FB_DATA_ARRAY(1, 3, 1, 0) + ; + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_OUT_ANY_CONSOLE){ + }; + + virtual ~FORTE_OUT_ANY_CONSOLE() {}; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/modules/utils/SET_AT_INDEX.cpp b/src/modules/utils/SET_AT_INDEX.cpp new file mode 100644 index 000000000..a7d5aa18a --- /dev/null +++ b/src/modules/utils/SET_AT_INDEX.cpp @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "SET_AT_INDEX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "SET_AT_INDEX_gen.cpp" +#endif +#include +#include + +DEFINE_FIRMWARE_FB(FORTE_SET_AT_INDEX, g_nStringIdSET_AT_INDEX) + + const CStringDictionary::TStringId FORTE_SET_AT_INDEX::scm_anDataInputNames[] = {g_nStringIdIN_ARRAY, g_nStringIdINDEX, g_nStringIdVALUE}; + +const CStringDictionary::TStringId FORTE_SET_AT_INDEX::scm_anDataInputTypeIds[] = {g_nStringIdANY, g_nStringIdUINT, g_nStringIdANY}; + +const CStringDictionary::TStringId FORTE_SET_AT_INDEX::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdOUT_ARRAY}; + +const CStringDictionary::TStringId FORTE_SET_AT_INDEX::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdANY}; + +const TForteInt16 FORTE_SET_AT_INDEX::scm_anEIWithIndexes[] = {0}; +const TDataIOID FORTE_SET_AT_INDEX::scm_anEIWith[] = {0, 1, 2, 255}; +const CStringDictionary::TStringId FORTE_SET_AT_INDEX::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const TDataIOID FORTE_SET_AT_INDEX::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 FORTE_SET_AT_INDEX::scm_anEOWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId FORTE_SET_AT_INDEX::scm_anEventOutputNames[] = {g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_SET_AT_INDEX::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_SET_AT_INDEX::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventREQID: + + if(CIEC_ANY::e_ARRAY == IN_ARRAY().getDataTypeID() && CIEC_ANY::e_ARRAY == OUT_ARRAY().getDataTypeID()){ + CIEC_ARRAY &rInArray = static_cast(IN_ARRAY()); + CIEC_ARRAY &rOutArray = static_cast(OUT_ARRAY()); + //check if data types match + if(rInArray.getElementDataTypeID() == rOutArray.getElementDataTypeID() && + rInArray.getElementDataTypeID() == VALUE().getDataTypeID()){ + //now check array length of input array + if(INDEX() < rInArray.size() && rOutArray.size() >= rInArray.size()){ + //update the value + rOutArray.setValue(rInArray); + rOutArray[INDEX()]->saveAssign(VALUE()); + QO() = true; + } + else{ + DEVLOG_DEBUG("Access index out of range, or mismatching array lengths.\n"); + QO() = false; + } + } + else{ + DEVLOG_DEBUG("Inequal element data types.\n"); + QO() = false; + } + } + else{ + DEVLOG_DEBUG("No 'Array' typed input and output data.\n"); + QO() = false; + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + + diff --git a/src/modules/utils/SET_AT_INDEX.h b/src/modules/utils/SET_AT_INDEX.h new file mode 100644 index 000000000..6f1cdfbf2 --- /dev/null +++ b/src/modules/utils/SET_AT_INDEX.h @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _SET_AT_INDEX_H_ +#define _SET_AT_INDEX_H_ + +#include +#include +#include +#include + +class FORTE_SET_AT_INDEX: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_SET_AT_INDEX) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_ANY &IN_ARRAY() { + return *static_cast(getDI(0)); + }; + + CIEC_UINT &INDEX() { + return *static_cast(getDI(1)); + }; + + CIEC_ANY &VALUE() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_ANY &OUT_ARRAY() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1, 3, 2, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_SET_AT_INDEX){ + }; + + virtual ~FORTE_SET_AT_INDEX(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/utils/STEST_END.cpp b/src/modules/utils/STEST_END.cpp new file mode 100644 index 000000000..45d2d9798 --- /dev/null +++ b/src/modules/utils/STEST_END.cpp @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2013 - 2015 Profactor GmbH, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Hofmann, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "STEST_END.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "STEST_END_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(FORTE_STEST_END, g_nStringIdSTEST_END) + +const TForteInt16 FORTE_STEST_END::scm_anEIWithIndexes[] = {-1}; +const CStringDictionary::TStringId FORTE_STEST_END::scm_anEventInputNames[] = {g_nStringIdREQ}; + +const SFBInterfaceSpec FORTE_STEST_END::scm_stFBInterfaceSpec = { + 1, scm_anEventInputNames, 0, scm_anEIWithIndexes, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, + 0, 0 +}; + +void FORTE_STEST_END::executeEvent(int pa_nEIID){ + if(scm_nEventREQID == pa_nEIID){ + getResource().getDevice().changeFBExecutionState(cg_nMGM_CMD_Kill); + } +} + + + diff --git a/src/modules/utils/STEST_END.h b/src/modules/utils/STEST_END.h new file mode 100644 index 000000000..a138c05bb --- /dev/null +++ b/src/modules/utils/STEST_END.h @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2013 - 2015 Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Hofmann, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _STEST_END_H_ +#define _STEST_END_H_ + +#include +#include "../../core/resource.h" +#include + +class FORTE_STEST_END: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(FORTE_STEST_END) + +private: + static const TEventID scm_nEventREQID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TForteInt16 scm_anEOWithIndexes[]; + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(0, 0, 0, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR(FORTE_STEST_END){ + }; + + virtual ~FORTE_STEST_END(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/modules/utils/tests/CMakeLists.txt b/src/modules/utils/tests/CMakeLists.txt new file mode 100644 index 000000000..99247c359 --- /dev/null +++ b/src/modules/utils/tests/CMakeLists.txt @@ -0,0 +1,5 @@ +############################################################################# +# FORTE UTILITY FBs +############################################################################# +forte_add_test(Test_utils_1 test_utils_1.fboot 5) +set_tests_properties (Test_utils_1 PROPERTIES WILL_FAIL true) diff --git a/src/modules/utils/tests/test_utils_1.fboot b/src/modules/utils/tests/test_utils_1.fboot new file mode 100644 index 000000000..63a021acf --- /dev/null +++ b/src/modules/utils/tests/test_utils_1.fboot @@ -0,0 +1,22 @@ +; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; diff --git a/src/stdfblib/CMakeLists.txt b/src/stdfblib/CMakeLists.txt new file mode 100644 index 000000000..293ef0f70 --- /dev/null +++ b/src/stdfblib/CMakeLists.txt @@ -0,0 +1,17 @@ +#******************************************************************************* +# * Copyright (c) 2010, 2011 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ +SET(SOURCE_GROUP ${SOURCE_GROUP}\\fblib) + +forte_add_sourcefile_hcpp(timedfb) + +add_subdirectory(events) +add_subdirectory(ita) +add_subdirectory(net) diff --git a/src/stdfblib/events/ARTimeOut.cpp b/src/stdfblib/events/ARTimeOut.cpp new file mode 100644 index 000000000..8328b9bb5 --- /dev/null +++ b/src/stdfblib/events/ARTimeOut.cpp @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ARTimeOut.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ARTimeOut_gen.cpp" +#endif + +DEFINE_ADAPTER_TYPE(FORTE_ARTimeOut, g_nStringIdARTimeOut) + +const CStringDictionary::TStringId FORTE_ARTimeOut::scm_anDataOutputNames[] = {g_nStringIdDT}; + +const CStringDictionary::TStringId FORTE_ARTimeOut::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_ARTimeOut::scm_anEIWithIndexes[] = {-1, -1}; +const CStringDictionary::TStringId FORTE_ARTimeOut::scm_anEventInputNames[] = {g_nStringIdTimeOut}; + +const TDataIOID FORTE_ARTimeOut::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_ARTimeOut::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_ARTimeOut::scm_anEventOutputNames[] = {g_nStringIdSTART, g_nStringIdSTOP}; + +const SFBInterfaceSpec FORTE_ARTimeOut::scm_stFBInterfaceSpecSocket = { + 1, scm_anEventInputNames, 0, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 0, 0, 0, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +const SFBInterfaceSpec FORTE_ARTimeOut::scm_stFBInterfaceSpecPlug = { + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, + 1, scm_anEventInputNames, 0, 0, 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0, 0, + 0, 0 +}; + + + diff --git a/src/stdfblib/events/ARTimeOut.h b/src/stdfblib/events/ARTimeOut.h new file mode 100644 index 000000000..481f05131 --- /dev/null +++ b/src/stdfblib/events/ARTimeOut.h @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ARTIMEOUT_H_ +#define _ARTIMEOUT_H_ + +#include +#include +#include + +class FORTE_ARTimeOut: public CAdapter{ + DECLARE_ADAPTER_TYPE(FORTE_ARTimeOut) + +private: + private: + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + public: + CIEC_TIME &DT() { + return *static_cast((isSocket()) ? getDO(0) : getDI(0)); + }; + + public: + static const TEventID scm_nEventTimeOutID = 0; + int TimeOut() { + return m_nParentAdapterListEventID + scm_nEventTimeOutID; + } + private: + static const TForteInt16 scm_anEIWithIndexes[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + public: + static const TEventID scm_nEventSTARTID = 0; + int START() { + return m_nParentAdapterListEventID + scm_nEventSTARTID; + } + static const TEventID scm_nEventSTOPID = 1; + int STOP() { + return m_nParentAdapterListEventID + scm_nEventSTOPID; + } + private: + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpecSocket; + + static const SFBInterfaceSpec scm_stFBInterfaceSpecPlug; + + FORTE_ADAPTER_DATA_ARRAY(1, 2, 0, 1, 0); + +public: + ADAPTER_CTOR(FORTE_ARTimeOut){ + }; + + virtual ~FORTE_ARTimeOut(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/ATimeOut.cpp b/src/stdfblib/events/ATimeOut.cpp new file mode 100644 index 000000000..8aa2819b7 --- /dev/null +++ b/src/stdfblib/events/ATimeOut.cpp @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "ATimeOut.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "ATimeOut_gen.cpp" +#endif + +DEFINE_ADAPTER_TYPE(FORTE_ATimeOut, g_nStringIdATimeOut) + +const CStringDictionary::TStringId FORTE_ATimeOut::scm_anDataOutputNames[] = {g_nStringIdDT}; + +const CStringDictionary::TStringId FORTE_ATimeOut::scm_anDataOutputTypeIds[] = {g_nStringIdTIME}; + +const TForteInt16 FORTE_ATimeOut::scm_anEIWithIndexes[] = {-1, -1}; +const CStringDictionary::TStringId FORTE_ATimeOut::scm_anEventInputNames[] = {g_nStringIdTimeOut}; + +const TDataIOID FORTE_ATimeOut::scm_anEOWith[] = {0, 255}; +const TForteInt16 FORTE_ATimeOut::scm_anEOWithIndexes[] = {0, -1, -1}; +const CStringDictionary::TStringId FORTE_ATimeOut::scm_anEventOutputNames[] = {g_nStringIdSTART, g_nStringIdSTOP}; + +const SFBInterfaceSpec FORTE_ATimeOut::scm_stFBInterfaceSpecSocket = { + 1, scm_anEventInputNames, 0, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 0, 0, 0, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +const SFBInterfaceSpec FORTE_ATimeOut::scm_stFBInterfaceSpecPlug = { + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, + 1, scm_anEventInputNames, 0, 0, 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0, 0, + 0, 0 +}; + + + diff --git a/src/stdfblib/events/ATimeOut.h b/src/stdfblib/events/ATimeOut.h new file mode 100644 index 000000000..5a4672217 --- /dev/null +++ b/src/stdfblib/events/ATimeOut.h @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _ATIMEOUT_H_ +#define _ATIMEOUT_H_ + +#include +#include +#include + +class FORTE_ATimeOut: public CAdapter{ + DECLARE_ADAPTER_TYPE(FORTE_ATimeOut) + +private: + private: + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + public: + CIEC_TIME &DT() { + return *static_cast((isSocket()) ? getDO(0) : getDI(0)); + }; + + public: + static const TEventID scm_nEventTimeOutID = 0; + int TimeOut() { + return m_nParentAdapterListEventID + scm_nEventTimeOutID; + } + private: + static const TForteInt16 scm_anEIWithIndexes[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + public: + static const TEventID scm_nEventSTARTID = 0; + int START() { + return m_nParentAdapterListEventID + scm_nEventSTARTID; + } + static const TEventID scm_nEventSTOPID = 1; + int STOP() { + return m_nParentAdapterListEventID + scm_nEventSTOPID; + } + private: + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpecSocket; + + static const SFBInterfaceSpec scm_stFBInterfaceSpecPlug; + + FORTE_ADAPTER_DATA_ARRAY(1, 2, 0, 1, 0); + +public: + ADAPTER_CTOR(FORTE_ATimeOut){ + }; + + virtual ~FORTE_ATimeOut(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/CMakeLists.txt b/src/stdfblib/events/CMakeLists.txt new file mode 100644 index 000000000..60ed5ec30 --- /dev/null +++ b/src/stdfblib/events/CMakeLists.txt @@ -0,0 +1,24 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2014 ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl, Monika Wenger +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +############################################################################# +# Event FB +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +SET(SOURCE_GROUP ${SOURCE_GROUP}\\events) + +forte_add_sourcefile_hcpp(E_CTU E_CTD E_CTUD E_DELAY E_D_FF E_MERGE) +forte_add_sourcefile_hcpp( E_REND E_RS E_SELECT E_SR) +forte_add_sourcefile_hcpp(E_CYCLE E_DEMUX E_F_TRIG E_PERMIT) +forte_add_sourcefile_hcpp(E_RDELAY E_RESTART E_R_TRIG E_SPLIT E_SWITCH) +forte_add_sourcefile_hcpp(GEN_E_DEMUX GEN_E_MUX) +forte_add_sourcefile_hcpp(ATimeOut E_TimeOut ARTimeOut E_RTimeOut) diff --git a/src/stdfblib/events/E_CTD.cpp b/src/stdfblib/events/E_CTD.cpp new file mode 100644 index 000000000..64ea404ef --- /dev/null +++ b/src/stdfblib/events/E_CTD.cpp @@ -0,0 +1,106 @@ +/******************************************************************************* + * Copyright (c) 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_CTD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_CTD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_E_CTD, g_nStringIdE_CTD) + +const CStringDictionary::TStringId FORTE_E_CTD::scm_anDataInputNames[] = {g_nStringIdPV}; + +const CStringDictionary::TStringId FORTE_E_CTD::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_E_CTD::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; + +const CStringDictionary::TStringId FORTE_E_CTD::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdUINT}; + +const TForteInt16 FORTE_E_CTD::scm_anEIWithIndexes[] = {-1, 0}; +const TDataIOID FORTE_E_CTD::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId FORTE_E_CTD::scm_anEventInputNames[] = {g_nStringIdCD, g_nStringIdLD}; + +const TDataIOID FORTE_E_CTD::scm_anEOWith[] = {0, 1, 255, 0, 1, 255}; +const TForteInt16 FORTE_E_CTD::scm_anEOWithIndexes[] = {0, 3, -1}; +const CStringDictionary::TStringId FORTE_E_CTD::scm_anEventOutputNames[] = {g_nStringIdCDO, g_nStringIdLDO}; + +const SFBInterfaceSpec FORTE_E_CTD::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +void FORTE_E_CTD::alg_CD(void){ +CV() = CV()-1; +Q() = ((CV() <= 0)); + + +} + +void FORTE_E_CTD::alg_LD(void){ +CV() = PV(); +Q() = ((CV() <= 0)); + +} + + +void FORTE_E_CTD::enterStateSTART(void){ + m_nECCState = scm_nStateSTART; +} + +void FORTE_E_CTD::enterStateCU(void){ + m_nECCState = scm_nStateCU; + alg_CD(); + sendOutputEvent( scm_nEventCDOID); +} + +void FORTE_E_CTD::enterStateLD(void){ + m_nECCState = scm_nStateLD; + alg_LD(); + sendOutputEvent( scm_nEventLDOID); +} + +void FORTE_E_CTD::executeEvent(int pa_nEIID){ + bool bTransitionCleared; + do{ + bTransitionCleared = true; + switch(m_nECCState){ + case scm_nStateSTART: + if((scm_nEventCDID == pa_nEIID) && (((CV() >= 1)))) + enterStateCU(); + else + if(scm_nEventLDID == pa_nEIID) + enterStateLD(); + else + bTransitionCleared = false; //no transition cleared + break; + case scm_nStateCU: + if(1) + enterStateSTART(); + else + bTransitionCleared = false; //no transition cleared + break; + case scm_nStateLD: + if(1) + enterStateSTART(); + else + bTransitionCleared = false; //no transition cleared + break; + default: + DEVLOG_ERROR("The state is not in the valid range! The state value is: %d. The max value can be: 2.", m_nECCState.operator TForteUInt16 ()); + m_nECCState = 0; //0 is always the initial state + break; + } + pa_nEIID = cg_nInvalidEventID; // we have to clear the event after the first check in order to ensure correct behavior + }while(bTransitionCleared); +} + + diff --git a/src/stdfblib/events/E_CTD.h b/src/stdfblib/events/E_CTD.h new file mode 100644 index 000000000..503fef274 --- /dev/null +++ b/src/stdfblib/events/E_CTD.h @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2014 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Monika Wenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_CTD_H_ +#define _E_CTD_H_ + +#include +#include +#include + +class FORTE_E_CTD: public CBasicFB{ + DECLARE_FIRMWARE_FB(FORTE_E_CTD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &PV() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &Q() { + return *static_cast(getDO(0)); + }; + + CIEC_UINT &CV() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventCDID = 0; + static const TEventID scm_nEventLDID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCDOID = 0; + static const TEventID scm_nEventLDOID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_BASIC_FB_DATA_ARRAY(2, 1, 2, 0, 0); + void alg_CD(void); + void alg_LD(void); + static const TForteInt16 scm_nStateSTART = 0; + static const TForteInt16 scm_nStateCU = 1; + static const TForteInt16 scm_nStateLD = 2; + + void enterStateSTART(void); + void enterStateCU(void); + void enterStateLD(void); + + virtual void executeEvent(int pa_nEIID); + +public: + FORTE_E_CTD(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CBasicFB(pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, + 0, m_anFBConnData, m_anFBVarsData){ + }; + + virtual ~FORTE_E_CTD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_CTU.cpp b/src/stdfblib/events/E_CTU.cpp new file mode 100644 index 000000000..0888c6b81 --- /dev/null +++ b/src/stdfblib/events/E_CTU.cpp @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_CTU.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_CTU_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_CTU, g_nStringIdE_CTU) + +const CStringDictionary::TStringId E_CTU::scm_anDataInputNames[] = {g_nStringIdPV}; + +const CStringDictionary::TStringId E_CTU::scm_anDataOutputNames[] = {g_nStringIdQ, g_nStringIdCV}; +const CStringDictionary::TStringId E_CTU::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdUINT}; +const CStringDictionary::TStringId E_CTU::scm_aunDIDataTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 E_CTU::scm_anEIWithIndexes[] = {0, -1}; +const TDataIOID E_CTU::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId E_CTU::scm_anEventInputNames[] = {g_nStringIdCU, g_nStringIdR}; + +const TDataIOID E_CTU::scm_anEOWith[] = {0, 1, 255, 0, 1, 255}; +const TForteInt16 E_CTU::scm_anEOWithIndexes[] = {0, 3}; +const CStringDictionary::TStringId E_CTU::scm_anEventOutputNames[] = {g_nStringIdCUO, g_nStringIdRO}; + +void E_CTU::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventCUID: + if(CV() < 65535){ + CV() = static_cast(CV() + 1); + Q() = (CV() >= PV()); + sendOutputEvent( scm_nEventCUOID); + } + break; + case scm_nEventRID: + CV() = 0; + Q() = false; + sendOutputEvent( scm_nEventROID); + break; + default: + break; + } +} + +const SFBInterfaceSpec E_CTU::scm_stFBInterfaceSpec = { + 2, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 2, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 2, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; diff --git a/src/stdfblib/events/E_CTU.h b/src/stdfblib/events/E_CTU.h new file mode 100644 index 000000000..3395e371c --- /dev/null +++ b/src/stdfblib/events/E_CTU.h @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_CTU_H_ +#define _E_CTU_H_ + +#include +#include +#include + +class E_CTU: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_CTU) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + + static const TEventID scm_nEventCUID = 0; + static const TEventID scm_nEventRID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCUOID = 0; + static const TEventID scm_nEventROID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2,1,2, 0); + + CIEC_UINT& PV() { + return *static_cast(getDI(0)); + } + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + CIEC_UINT& CV() { + return *static_cast(getDO(1)); + } + + +public: + FUNCTION_BLOCK_CTOR(E_CTU){}; + virtual ~E_CTU(){}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_CTUD.cpp b/src/stdfblib/events/E_CTUD.cpp new file mode 100644 index 000000000..77a811d09 --- /dev/null +++ b/src/stdfblib/events/E_CTUD.cpp @@ -0,0 +1,151 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_CTUD.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_CTUD_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_E_CTUD, g_nStringIdE_CTUD) + +const CStringDictionary::TStringId FORTE_E_CTUD::scm_anDataInputNames[] = {g_nStringIdPV}; + +const CStringDictionary::TStringId FORTE_E_CTUD::scm_anDataInputTypeIds[] = {g_nStringIdUINT}; + +const CStringDictionary::TStringId FORTE_E_CTUD::scm_anDataOutputNames[] = {g_nStringIdQU, g_nStringIdQD, g_nStringIdCV}; + +const CStringDictionary::TStringId FORTE_E_CTUD::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUINT}; + +const TForteInt16 FORTE_E_CTUD::scm_anEIWithIndexes[] = {0, -1, -1, 2}; +const TDataIOID FORTE_E_CTUD::scm_anEIWith[] = {0, 255, 0, 255}; +const CStringDictionary::TStringId FORTE_E_CTUD::scm_anEventInputNames[] = {g_nStringIdCU, g_nStringIdCD, g_nStringIdR, g_nStringIdLD}; + +const TDataIOID FORTE_E_CTUD::scm_anEOWith[] = {0, 2, 1, 255, 0, 2, 1, 255, 0, 1, 2, 255}; +const TForteInt16 FORTE_E_CTUD::scm_anEOWithIndexes[] = {0, 4, 8, -1}; +const CStringDictionary::TStringId FORTE_E_CTUD::scm_anEventOutputNames[] = {g_nStringIdCO, g_nStringIdRO, g_nStringIdLDO}; + +const SFBInterfaceSpec FORTE_E_CTUD::scm_stFBInterfaceSpec = { + 4, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 3, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +void FORTE_E_CTUD::alg_CountUp(void){ +CV() = CV()+1; + + +} + +void FORTE_E_CTUD::alg_Reset(void){ +CV() = 0; + +} + +void FORTE_E_CTUD::alg_Load(void){ +CV() = PV(); +} + +void FORTE_E_CTUD::alg_UpdateQUQD(void){ +QU() = ((CV() >= PV())); +QD() = ((CV() <= 0)); +} + +void FORTE_E_CTUD::alg_CountDown(void){ +CV() = CV()-1; +} + + +void FORTE_E_CTUD::enterStateSTART(void){ + m_nECCState = scm_nStateSTART; +} + +void FORTE_E_CTUD::enterStateCU(void){ + m_nECCState = scm_nStateCU; + alg_CountUp(); + alg_UpdateQUQD(); + sendOutputEvent( scm_nEventCOID); +} + +void FORTE_E_CTUD::enterStateR(void){ + m_nECCState = scm_nStateR; + alg_Reset(); + alg_UpdateQUQD(); + sendOutputEvent( scm_nEventROID); +} + +void FORTE_E_CTUD::enterStateCD(void){ + m_nECCState = scm_nStateCD; + alg_CountDown(); + alg_UpdateQUQD(); + sendOutputEvent( scm_nEventCOID); +} + +void FORTE_E_CTUD::enterStateLD(void){ + m_nECCState = scm_nStateLD; + alg_Load(); + alg_UpdateQUQD(); + sendOutputEvent( scm_nEventLDOID); +} + +void FORTE_E_CTUD::executeEvent(int pa_nEIID){ + bool bTransitionCleared; + do{ + bTransitionCleared = true; + switch(m_nECCState){ + case scm_nStateSTART: + if((scm_nEventCUID == pa_nEIID) && (((CV() < 65535)))) + enterStateCU(); + else + if(scm_nEventRID == pa_nEIID) + enterStateR(); + else + if((scm_nEventCDID == pa_nEIID) && (((CV() >= 1)))) + enterStateCD(); + else + if(scm_nEventLDID == pa_nEIID) + enterStateLD(); + else + bTransitionCleared = false; //no transition cleared + break; + case scm_nStateCU: + if(1) + enterStateSTART(); + else + bTransitionCleared = false; //no transition cleared + break; + case scm_nStateR: + if(1) + enterStateSTART(); + else + bTransitionCleared = false; //no transition cleared + break; + case scm_nStateCD: + if(1) + enterStateSTART(); + else + bTransitionCleared = false; //no transition cleared + break; + case scm_nStateLD: + if(1) + enterStateSTART(); + else + bTransitionCleared = false; //no transition cleared + break; + default: + DEVLOG_ERROR("The state is not in the valid range! The state value is: %d. The max value can be: 4.", m_nECCState.operator TForteUInt16 ()); + m_nECCState = 0; //0 is always the initial state + break; + } + pa_nEIID = cg_nInvalidEventID; // we have to clear the event after the first check in order to ensure correct behavior + }while(bTransitionCleared); +} + + diff --git a/src/stdfblib/events/E_CTUD.h b/src/stdfblib/events/E_CTUD.h new file mode 100644 index 000000000..a9044d141 --- /dev/null +++ b/src/stdfblib/events/E_CTUD.h @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_CTUD_H_ +#define _E_CTUD_H_ + +#include +#include +#include + +class FORTE_E_CTUD: public CBasicFB{ + DECLARE_FIRMWARE_FB(FORTE_E_CTUD) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_UINT &PV() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QU() { + return *static_cast(getDO(0)); + }; + + CIEC_BOOL &QD() { + return *static_cast(getDO(1)); + }; + + CIEC_UINT &CV() { + return *static_cast(getDO(2)); + }; + + static const TEventID scm_nEventCUID = 0; + static const TEventID scm_nEventCDID = 1; + static const TEventID scm_nEventRID = 2; + static const TEventID scm_nEventLDID = 3; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCOID = 0; + static const TEventID scm_nEventROID = 1; + static const TEventID scm_nEventLDOID = 2; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_BASIC_FB_DATA_ARRAY(3, 1, 3, 0, 0); + void alg_CountUp(void); + void alg_Reset(void); + void alg_Load(void); + void alg_UpdateQUQD(void); + void alg_CountDown(void); + static const TForteInt16 scm_nStateSTART = 0; + static const TForteInt16 scm_nStateCU = 1; + static const TForteInt16 scm_nStateR = 2; + static const TForteInt16 scm_nStateCD = 3; + static const TForteInt16 scm_nStateLD = 4; + + void enterStateSTART(void); + void enterStateCU(void); + void enterStateR(void); + void enterStateCD(void); + void enterStateLD(void); + + virtual void executeEvent(int pa_nEIID); + +public: + FORTE_E_CTUD(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CBasicFB(pa_poSrcRes, &scm_stFBInterfaceSpec, pa_nInstanceNameId, + 0, m_anFBConnData, m_anFBVarsData){ + }; + + virtual ~FORTE_E_CTUD(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_CYCLE.cpp b/src/stdfblib/events/E_CYCLE.cpp new file mode 100644 index 000000000..4d15e3221 --- /dev/null +++ b/src/stdfblib/events/E_CYCLE.cpp @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_CYCLE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_CYCLE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_CYCLE, g_nStringIdE_CYCLE) + diff --git a/src/stdfblib/events/E_CYCLE.h b/src/stdfblib/events/E_CYCLE.h new file mode 100644 index 000000000..5ce005b88 --- /dev/null +++ b/src/stdfblib/events/E_CYCLE.h @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_CYCLE_H_ +#define _E_CYCLE_H_ + +#include "../timedfb.h" + +/*! \brief Implementation of the E_CYCLE FB. + */ +class E_CYCLE : public CTimedFB{ + DECLARE_FIRMWARE_FB(E_CYCLE) +private: +public: + E_CYCLE(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : CTimedFB( pa_nInstanceNameId, pa_poSrcRes){ + m_stTimeListEntry.m_eType = e_Periodic; + }; + virtual ~E_CYCLE() {}; +}; + +#endif /*E_CYCLE_H_*/ diff --git a/src/stdfblib/events/E_DELAY.cpp b/src/stdfblib/events/E_DELAY.cpp new file mode 100644 index 000000000..943f1241d --- /dev/null +++ b/src/stdfblib/events/E_DELAY.cpp @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_DELAY.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_DELAY_gen.cpp" +#endif +#include "../../arch/timerha.h" + +DEFINE_FIRMWARE_FB(E_DELAY, g_nStringIdE_DELAY) + +E_DELAY::E_DELAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes): + CTimedFB( pa_nInstanceNameId, pa_poSrcRes){ + m_stTimeListEntry.m_eType = e_SingleShot; +} + +void E_DELAY::executeEvent(int pa_nEIID){ + if(cg_nExternalEventID == pa_nEIID ){ + sendOutputEvent(csm_nEOID); + m_bActive = false; + } + else{ + if(csm_nEventSTARTID == pa_nEIID ){ + if(!m_bActive){ + setEventChainExecutor(m_poInvokingExecEnv); // E_DELAY will execute in the same thread on as from where it has been triggered. + } + } + CTimedFB::executeEvent(pa_nEIID); + } +} + + diff --git a/src/stdfblib/events/E_DELAY.h b/src/stdfblib/events/E_DELAY.h new file mode 100644 index 000000000..78651ce57 --- /dev/null +++ b/src/stdfblib/events/E_DELAY.h @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_DELAY_H_ +#define _E_DELAY_H_ + +#include "../timedfb.h" + +/*! \brief Implementation of the E_DELAY FB. + * + * The E_DELAY block will delay the event propagation of the ec. In the current implementation it is not + * a busy wait. Instead it is implemented like an event source. The main difference to an event source + * is that it will not start in an own new ecexectuionthread (or background trhead of the resource). It + * will use the EC-Thread of the EC that sent the start command. + */ +class E_DELAY : public CTimedFB{ + DECLARE_FIRMWARE_FB(E_DELAY) +private: + + void executeEvent(int pa_nEIID); +public: + E_DELAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~E_DELAY(){}; + +}; + +#endif /*E_DELAY_H_*/ diff --git a/src/stdfblib/events/E_DEMUX.cpp b/src/stdfblib/events/E_DEMUX.cpp new file mode 100644 index 000000000..2c39d6768 --- /dev/null +++ b/src/stdfblib/events/E_DEMUX.cpp @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_DEMUX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_DEMUX_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_DEMUX, g_nStringIdE_DEMUX) + +const CStringDictionary::TStringId E_DEMUX::scm_anDataInputNames[] = {g_nStringIdK}; +const CStringDictionary::TStringId E_DEMUX::scm_aunDIDataTypeIds[] = {g_nStringIdUINT}; + +const TForteInt16 E_DEMUX::scm_anEIWithIndexes[] = {0}; +const TDataIOID E_DEMUX::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId E_DEMUX::scm_anEventInputNames[] = {g_nStringIdEI}; + +const CStringDictionary::TStringId E_DEMUX::scm_anEventOutputNames[] = {g_nStringIdEO0, g_nStringIdEO1, g_nStringIdEO2, g_nStringIdEO3}; + +const SFBInterfaceSpec E_DEMUX::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 4, + scm_anEventOutputNames, + 0, + 0, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 0, + 0, + 0, + 0, + 0 +}; + +void E_DEMUX::executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + if(K() <= 3){ + sendOutputEvent( K()); // the value of K corresponds to the outputevent ID; + // as a result of this we could make a generic E_DEMUX + // and even a generic E_MUX + } + } +} diff --git a/src/stdfblib/events/E_DEMUX.h b/src/stdfblib/events/E_DEMUX.h new file mode 100644 index 000000000..16e68c756 --- /dev/null +++ b/src/stdfblib/events/E_DEMUX.h @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_DEMUX_H_ +#define _E_DEMUX_H_ + +#include +#include + +class E_DEMUX: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_DEMUX) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + + static const TEventID scm_nEventEIID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEO0ID = 0; + static const TEventID scm_nEventEO1ID = 1; + static const TEventID scm_nEventEO2ID = 2; + static const TEventID scm_nEventEO3ID = 3; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + virtual void executeEvent(int pa_nEIID); + + CIEC_UINT& K() { + return *static_cast(getDI(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_DEMUX){ + }; + virtual ~E_DEMUX(){}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_D_FF.cpp b/src/stdfblib/events/E_D_FF.cpp new file mode 100644 index 000000000..b74fede24 --- /dev/null +++ b/src/stdfblib/events/E_D_FF.cpp @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_D_FF.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_D_FF_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_D_FF, g_nStringIdE_D_FF) + +const CStringDictionary::TStringId E_D_FF::scm_anDataInputNames[] = {g_nStringIdD}; + +const CStringDictionary::TStringId E_D_FF::scm_anDataOutputNames[] = {g_nStringIdQ}; +const CStringDictionary::TStringId E_D_FF::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; +const CStringDictionary::TStringId E_D_FF::scm_aunDODataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 E_D_FF::scm_anEIWithIndexes[] = {0}; +const TDataIOID E_D_FF::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId E_D_FF::scm_anEventInputNames[] = {g_nStringIdCLK}; + +const TDataIOID E_D_FF::scm_anEOWith[] = {0, 255}; +const TForteInt16 E_D_FF::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId E_D_FF::scm_anEventOutputNames[] = {g_nStringIdEO}; + +void E_D_FF::executeEvent(int pa_nEIID){ + if(scm_nEventCLKID == pa_nEIID){ + if(D() != Q()){ + Q() = D(); + sendOutputEvent( scm_nEventEOID); + } + } +} + +const SFBInterfaceSpec E_D_FF::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + + + diff --git a/src/stdfblib/events/E_D_FF.h b/src/stdfblib/events/E_D_FF.h new file mode 100644 index 000000000..eb2297431 --- /dev/null +++ b/src/stdfblib/events/E_D_FF.h @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_D_FF_H_ +#define _E_D_FF_H_ + +#include +#include + +class E_D_FF: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_D_FF) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + + + static const TEventID scm_nEventCLKID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + FORTE_FB_DATA_ARRAY(1,1,1, 0); + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + CIEC_BOOL& D() { + return *static_cast(getDI(0)); + } + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_D_FF){ + }; + + virtual ~E_D_FF(){ }; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_F_TRIG.cpp b/src/stdfblib/events/E_F_TRIG.cpp new file mode 100644 index 000000000..bce62b6c5 --- /dev/null +++ b/src/stdfblib/events/E_F_TRIG.cpp @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_F_TRIG.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_F_TRIG_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(E_F_TRIG, g_nStringIdE_F_TRIG) + +const CStringDictionary::TStringId E_F_TRIG::scm_anDataInputNames[] = {g_nStringIdQI}; +const CStringDictionary::TStringId E_F_TRIG::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 E_F_TRIG::scm_anEIWithIndexes[] = {0}; +const TDataIOID E_F_TRIG::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId E_F_TRIG::scm_anEventInputNames[] = {g_nStringIdEI}; + +const CStringDictionary::TStringId E_F_TRIG::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec E_F_TRIG::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + 0, + 0, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 0, + 0, + 0, + 0, + 0 +}; + +void E_F_TRIG::executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + if((m_bOldVal != QI()) && (false == QI())){ + //Falling edge + sendOutputEvent(scm_nEventEOID); + } + m_bOldVal = QI(); + } +} + + + diff --git a/src/stdfblib/events/E_F_TRIG.h b/src/stdfblib/events/E_F_TRIG.h new file mode 100644 index 000000000..b9b6c0371 --- /dev/null +++ b/src/stdfblib/events/E_F_TRIG.h @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_F_TRIG_H_ +#define _E_F_TRIG_H_ + +#include +#include + +class E_F_TRIG: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_F_TRIG) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + + static const TEventID scm_nEventEIID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,0, 0); + + bool m_bOldVal; + + + virtual void executeEvent(int pa_nEIID); + + CIEC_BOOL& QI() { + return *static_cast(getDI(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_F_TRIG), m_bOldVal(false) { + }; + + virtual ~E_F_TRIG(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_MERGE.cpp b/src/stdfblib/events/E_MERGE.cpp new file mode 100644 index 000000000..6dd7b6628 --- /dev/null +++ b/src/stdfblib/events/E_MERGE.cpp @@ -0,0 +1,43 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_MERGE.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_MERGE_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_MERGE, g_nStringIdE_MERGE) + +const CStringDictionary::TStringId E_MERGE::scm_anEventInputNames[] = {g_nStringIdEI1, g_nStringIdEI2}; + +const CStringDictionary::TStringId E_MERGE::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec E_MERGE::scm_stFBInterfaceSpec = { + 2, + scm_anEventInputNames, + 0, + 0, + 1, + scm_anEventOutputNames, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; + + + diff --git a/src/stdfblib/events/E_MERGE.h b/src/stdfblib/events/E_MERGE.h new file mode 100644 index 000000000..a98b59a88 --- /dev/null +++ b/src/stdfblib/events/E_MERGE.h @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_MERGE_H_ +#define _E_MERGE_H_ + +#include + +class E_MERGE: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_MERGE) + +private: + + static const TEventID scm_nEventEI1ID = 0; + static const TEventID scm_nEventEI2ID = 1; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + + virtual void executeEvent(int pa_nEIID){ + if((scm_nEventEI1ID == pa_nEIID)||(scm_nEventEI2ID == pa_nEIID)){ + sendOutputEvent(scm_nEventEOID); + } + }; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,0,0, 0); +public: + FUNCTION_BLOCK_CTOR(E_MERGE){ + }; + virtual ~E_MERGE() {}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_PERMIT.cpp b/src/stdfblib/events/E_PERMIT.cpp new file mode 100644 index 000000000..0fd282816 --- /dev/null +++ b/src/stdfblib/events/E_PERMIT.cpp @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_PERMIT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_PERMIT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_PERMIT, g_nStringIdE_PERMIT) + +const CStringDictionary::TStringId E_PERMIT::scm_anDataInputNames[] = {g_nStringIdPERMIT}; +const CStringDictionary::TStringId E_PERMIT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 E_PERMIT::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID E_PERMIT::scm_anEIWith[] = { 0, 255 }; +const CStringDictionary::TStringId E_PERMIT::scm_anEventInputNames[] = { g_nStringIdEI }; + +const CStringDictionary::TStringId E_PERMIT::scm_anEventOutputNames[] = { g_nStringIdEO }; + +const SFBInterfaceSpec + E_PERMIT::scm_stFBInterfaceSpec = { 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, 1, + scm_anEventOutputNames, 0, 0, 1, scm_anDataInputNames, scm_aunDIDataTypeIds, 0, 0, 0, + 0, + 0 +}; + +void E_PERMIT::executeEvent(int pa_nEIID){ + if((scm_nEventEIID == pa_nEIID) && (PERMIT())){ + sendOutputEvent(scm_nEventEOID); + } +} + diff --git a/src/stdfblib/events/E_PERMIT.h b/src/stdfblib/events/E_PERMIT.h new file mode 100644 index 000000000..8be9ad080 --- /dev/null +++ b/src/stdfblib/events/E_PERMIT.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_PERMIT_H_ +#define _E_PERMIT_H_ + +#include +#include + +class E_PERMIT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_PERMIT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + + static const TEventID scm_nEventEIID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,0, 0); + + CIEC_BOOL& PERMIT() { + return *static_cast(getDI(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_PERMIT) { + }; + virtual ~E_PERMIT(){}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_RDELAY.cpp b/src/stdfblib/events/E_RDELAY.cpp new file mode 100644 index 000000000..cf6703e62 --- /dev/null +++ b/src/stdfblib/events/E_RDELAY.cpp @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_RDELAY.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_RDELAY_gen.cpp" +#endif +#include "../../arch/timerha.h" + +DEFINE_FIRMWARE_FB(E_RDELAY, g_nStringIdE_RDELAY) + +E_RDELAY::E_RDELAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes): + CTimedFB( pa_nInstanceNameId, pa_poSrcRes){ + m_stTimeListEntry.m_eType = e_SingleShot; +} + +void E_RDELAY::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case cg_nExternalEventID: + sendOutputEvent(csm_nEOID); + m_bActive = false; + break; + case csm_nEventSTARTID: + if(m_bActive){ + //remove from the list as we want to be added with a new delay + CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); + } + setEventChainExecutor(m_poInvokingExecEnv); // E_RDELAY will execute in the same thread on as from where it has been triggered. + CTimerHandler::sm_poFORTETimer->registerTimedFB( &m_stTimeListEntry, DT()); + m_bActive = true; + break; + default: + CTimedFB::executeEvent(pa_nEIID); + break; + } +} + + diff --git a/src/stdfblib/events/E_RDELAY.h b/src/stdfblib/events/E_RDELAY.h new file mode 100644 index 000000000..d0c663c5d --- /dev/null +++ b/src/stdfblib/events/E_RDELAY.h @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_DELAY_H_ +#define _E_DELAY_H_ + +#include "../timedfb.h" + +/*! \brief Implementation of the E_RDELAY FB. + */ +class E_RDELAY : public CTimedFB{ + DECLARE_FIRMWARE_FB(E_RDELAY) +private: + + void executeEvent(int pa_nEIID); +public: + E_RDELAY(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~E_RDELAY(){}; + +}; + +#endif /*E_DELAY_H_*/ diff --git a/src/stdfblib/events/E_REND.cpp b/src/stdfblib/events/E_REND.cpp new file mode 100644 index 000000000..0d68d96ba --- /dev/null +++ b/src/stdfblib/events/E_REND.cpp @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_REND.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_REND_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_REND, g_nStringIdE_REND) + +const CStringDictionary::TStringId E_REND::scm_anEventInputNames[] = {g_nStringIdEI1, g_nStringIdEI2, g_nStringIdR}; + +const CStringDictionary::TStringId E_REND::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec E_REND::scm_stFBInterfaceSpec = { + 3, + scm_anEventInputNames, + 0, + 0, + 1, + scm_anEventOutputNames, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; + +void E_REND::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventEI1ID: + if(m_bE2Occ){ + m_bE2Occ = false; + sendOutputEvent( scm_nEventEOID); + } + else{ + m_bE1Occ = true; + } + break; + case scm_nEventEI2ID: + if(m_bE1Occ){ + m_bE1Occ = false; + sendOutputEvent( scm_nEventEOID); + } + else{ + m_bE2Occ = true; + } + break; + case scm_nEventRID: + m_bE1Occ = m_bE2Occ = false; + break; + default: + break; + } +} diff --git a/src/stdfblib/events/E_REND.h b/src/stdfblib/events/E_REND.h new file mode 100644 index 000000000..01eaff266 --- /dev/null +++ b/src/stdfblib/events/E_REND.h @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_REND_H_ +#define _E_REND_H_ + +#include + +class E_REND: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_REND) + +private: + + static const TEventID scm_nEventEI1ID = 0; + static const TEventID scm_nEventEI2ID = 1; + static const TEventID scm_nEventRID = 2; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const int scm_nStateSTART = 0; + static const int scm_nStateR = 1; + static const int scm_nStateR1 = 2; + static const int scm_nStateEI1 = 3; + static const int scm_nStateEO = 4; + static const int scm_nStateEI2 = 5; + static const int scm_nStateR2 = 6; + + bool m_bE1Occ; + bool m_bE2Occ; + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,0,0, 0); + +public: + FUNCTION_BLOCK_CTOR(E_REND), + m_bE1Occ(false), + m_bE2Occ(false){ + }; + virtual ~E_REND() {}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_RESTART.cpp b/src/stdfblib/events/E_RESTART.cpp new file mode 100644 index 000000000..b642dd5ef --- /dev/null +++ b/src/stdfblib/events/E_RESTART.cpp @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Gerhard Ebenhofer, + * Martin Melik Merkumians, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_RESTART.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_RESTART_gen.cpp" +#endif +#include "../../core/device.h" + +DEFINE_FIRMWARE_FB(E_RESTART, g_nStringIdE_RESTART) + +const CStringDictionary::TStringId E_RESTART::scm_aunEONameIds[] = {g_nStringIdCOLD, g_nStringIdWARM, g_nStringIdSTOP}; + +const TEventID E_RESTART::csmCOLDID; +const TEventID E_RESTART::csmWARMID; +const TEventID E_RESTART::csmSTOPID; + +const SFBInterfaceSpec E_RESTART::scm_stFBInterfaceSpec = { + 0, + 0, + 0, + 0, + 3, + scm_aunEONameIds, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; + +void E_RESTART::executeEvent(int pa_nEIID){ + if(cg_nExternalEventID == pa_nEIID){ + if(cg_nInvalidEventID != mEventToSend){ + sendOutputEvent(mEventToSend); + if(csmSTOPID == mEventToSend){ + //stop event is sent put the FB finally into the stopped state + CFunctionBlock::changeFBExecutionState(cg_nMGM_CMD_Stop); + } + } + } +} + +EMGMResponse E_RESTART::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse eRetVal = CFunctionBlock::changeFBExecutionState(pa_unCommand); + if(e_RDY == eRetVal){ + switch(pa_unCommand){ + case cg_nMGM_CMD_Start: + mEventToSend = (csmSTOPID == mEventToSend) ? csmWARMID : csmCOLDID; + getResource().getDevice().getDeviceExecution().startNewEventChain(this); + break; + case cg_nMGM_CMD_Stop: + mEventToSend = csmSTOPID; + CFunctionBlock::changeFBExecutionState(cg_nMGM_CMD_Start); //keep FB in running state until stop event is delivered. + getResource().getDevice().getDeviceExecution().startNewEventChain(this); + break; + default: + mEventToSend = cg_nInvalidEventID; + break; + } + } + return eRetVal; +} diff --git a/src/stdfblib/events/E_RESTART.h b/src/stdfblib/events/E_RESTART.h new file mode 100644 index 000000000..ae2ab4636 --- /dev/null +++ b/src/stdfblib/events/E_RESTART.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Gerhard Ebenhofer, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_RESTART_H_ +#define _E_RESTART_H_ + +#include "../core/esfb.h" +#include "../core/resource.h" + +/*! \brief Implementation of the E_RESTART FB. + */ + +class E_RESTART : public CEventSourceFB{ + DECLARE_FIRMWARE_FB(E_RESTART) +private: + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(3,0,0, 0); + + static const TEventID csmCOLDID = 0; + static const TEventID csmWARMID = 1; + static const TEventID csmSTOPID = 2; + + static const CStringDictionary::TStringId scm_aunEONameIds[]; + + bool m_bStartedOnce; + + TEventID mEventToSend; + + virtual void executeEvent(int pa_nEIID); + +public: + EVENT_SOURCE_FUNCTION_BLOCK_CTOR(E_RESTART), + mEventToSend(cg_nInvalidEventID) { + setEventChainExecutor(pa_poSrcRes->getResourceEventExecution()); + } + virtual ~E_RESTART() {}; + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); +}; + +#endif /*E_RESTART_H_*/ diff --git a/src/stdfblib/events/E_RS.cpp b/src/stdfblib/events/E_RS.cpp new file mode 100644 index 000000000..3f7dbc9d8 --- /dev/null +++ b/src/stdfblib/events/E_RS.cpp @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_RS.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_RS_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_RS, g_nStringIdE_RS) + +const CStringDictionary::TStringId E_RS::scm_anDataOutputNames[] = {g_nStringIdQ}; +const CStringDictionary::TStringId E_RS::scm_aunDODataTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId E_RS::scm_anEventInputNames[] = {g_nStringIdR, g_nStringIdS}; + +const TDataIOID E_RS::scm_anEOWith[] = {0, 255}; +const TForteInt16 E_RS::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId E_RS::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec E_RS::scm_stFBInterfaceSpec = { + 2, + scm_anEventInputNames, + 0, + 0, + 1, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 0, + 0, + 0, + 1, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + +void E_RS::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventRID: + if(true == Q()){ + Q() = false; + sendOutputEvent( scm_nEventEOID); + } + break; + case scm_nEventSID: + if(false == Q()){ + Q() = true; + sendOutputEvent( scm_nEventEOID); + } + break; + default: + break; + } +} + + + diff --git a/src/stdfblib/events/E_RS.h b/src/stdfblib/events/E_RS.h new file mode 100644 index 000000000..fd945b766 --- /dev/null +++ b/src/stdfblib/events/E_RS.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_RS_H_ +#define _E_RS_H_ + +#include +#include + +class E_RS: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_RS) + +private: + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + + static const TEventID scm_nEventRID = 0; + static const TEventID scm_nEventSID = 1; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,0,1, 0); + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_RS){ + }; + virtual ~E_RS() {}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_RTimeOut.cpp b/src/stdfblib/events/E_RTimeOut.cpp new file mode 100644 index 000000000..e37413471 --- /dev/null +++ b/src/stdfblib/events/E_RTimeOut.cpp @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_RTimeOut.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_RTimeOut_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_E_RTimeOut, g_nStringIdE_RTimeOut) + +const TForteInt16 FORTE_E_RTimeOut::scm_anEOWithIndexes[] = {-1}; +const SAdapterInstanceDef FORTE_E_RTimeOut::scm_astAdapterInstances[] = { +{g_nStringIdARTimeOut, g_nStringIdTimeOutSocket, false }}; + +const SFBInterfaceSpec FORTE_E_RTimeOut::scm_stFBInterfaceSpec = { + 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, + 1,scm_astAdapterInstances}; + + +const SCFB_FBInstanceData FORTE_E_RTimeOut::scm_astInternalFBs[] = { + {g_nStringIdDLY, g_nStringIdE_RDELAY}, +}; + +const SCFB_FBConnectionData FORTE_E_RTimeOut::scm_astEventConnections[] = { + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdTimeOutSocket, g_nStringIdSTART), CCompositeFB::scm_nAdapterMarker |0, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdDLY, g_nStringIdSTART), 0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdTimeOutSocket, g_nStringIdSTOP), CCompositeFB::scm_nAdapterMarker |0, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdDLY, g_nStringIdSTOP), 0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdDLY, g_nStringIdEO), 0, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdTimeOutSocket, g_nStringIdTimeOut), CCompositeFB::scm_nAdapterMarker |0}, +}; + +const SCFB_FBConnectionData FORTE_E_RTimeOut::scm_astDataConnections[] = { + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdTimeOutSocket, g_nStringIdDT), CCompositeFB::scm_nAdapterMarker |0, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdDLY, g_nStringIdDT), 0}, +}; + +const SCFB_FBNData FORTE_E_RTimeOut::scm_stFBNData = { + 1, scm_astInternalFBs, + 3, scm_astEventConnections, + 0, 0, + 1, scm_astDataConnections, + 0, 0, + 0, 0 +}; + + diff --git a/src/stdfblib/events/E_RTimeOut.h b/src/stdfblib/events/E_RTimeOut.h new file mode 100644 index 000000000..bc89e22d0 --- /dev/null +++ b/src/stdfblib/events/E_RTimeOut.h @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_RTIMEOUT_H_ +#define _E_RTIMEOUT_H_ + +#include +#include +#include "ARTimeOut.h" + +class FORTE_E_RTimeOut: public CCompositeFB{ + DECLARE_FIRMWARE_FB(FORTE_E_RTimeOut) + +private: + static const TForteInt16 scm_anEOWithIndexes[]; + static const SAdapterInstanceDef scm_astAdapterInstances[]; + + FORTE_ARTimeOut& TimeOutSocket() { + return (*static_cast(m_apoAdapters[0])); + }; + static const int scm_nTimeOutSocketAdpNum = 0; + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(0, 0, 0, 1); + + static const SCFB_FBInstanceData scm_astInternalFBs[]; + + static const SCFB_FBConnectionData scm_astEventConnections[]; + + static const SCFB_FBConnectionData scm_astDataConnections[]; + static const SCFB_FBNData scm_stFBNData; + +public: + COMPOSITE_FUNCTION_BLOCK_CTOR(FORTE_E_RTimeOut){ + }; + + virtual ~FORTE_E_RTimeOut(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_R_TRIG.cpp b/src/stdfblib/events/E_R_TRIG.cpp new file mode 100644 index 000000000..6d1fcbb72 --- /dev/null +++ b/src/stdfblib/events/E_R_TRIG.cpp @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_R_TRIG.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_R_TRIG_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(E_R_TRIG, g_nStringIdE_R_TRIG) + +const CStringDictionary::TStringId E_R_TRIG::scm_anDataInputNames[] = {g_nStringIdQI}; +const CStringDictionary::TStringId E_R_TRIG::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 E_R_TRIG::scm_anEIWithIndexes[] = {0}; +const TDataIOID E_R_TRIG::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId E_R_TRIG::scm_anEventInputNames[] = {g_nStringIdEI}; + +const CStringDictionary::TStringId E_R_TRIG::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec E_R_TRIG::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + 0, + 0, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 0, + 0, + 0, + 0, + 0 +}; + +void E_R_TRIG::executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + if((m_bOldVal != QI()) && (true == QI())){ + //Raising edge + sendOutputEvent(scm_nEventEOID); + } + m_bOldVal = QI(); + } +} diff --git a/src/stdfblib/events/E_R_TRIG.h b/src/stdfblib/events/E_R_TRIG.h new file mode 100644 index 000000000..6ff04dc4f --- /dev/null +++ b/src/stdfblib/events/E_R_TRIG.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2007 - 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_R_TRIG_H_ +#define _E_R_TRIG_H_ + +#include +#include + +class E_R_TRIG: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_R_TRIG) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const TEventID scm_nEventEIID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,1,0, 0); + + bool m_bOldVal; + + void executeEvent(int pa_nEIID); + + CIEC_BOOL& QI() { + return *static_cast(getDI(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_R_TRIG), m_bOldVal(false){ + }; + virtual ~E_R_TRIG(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_SELECT.cpp b/src/stdfblib/events/E_SELECT.cpp new file mode 100644 index 000000000..0c6fd7cca --- /dev/null +++ b/src/stdfblib/events/E_SELECT.cpp @@ -0,0 +1,64 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_SELECT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_SELECT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_SELECT, g_nStringIdE_SELECT) + +const CStringDictionary::TStringId E_SELECT::scm_anDataInputNames[] = {g_nStringIdG}; +const CStringDictionary::TStringId E_SELECT::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 E_SELECT::scm_anEIWithIndexes[] = {0, 2}; +const TDataIOID E_SELECT::scm_anEIWith[] = {0, 255, 0, 255}; +const CStringDictionary::TStringId E_SELECT::scm_anEventInputNames[] = {g_nStringIdEI0, g_nStringIdEI1}; + +const CStringDictionary::TStringId E_SELECT::scm_anEventOutputNames[] = {g_nStringIdEO}; + +const SFBInterfaceSpec E_SELECT::scm_stFBInterfaceSpec = { + 2, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_anEventOutputNames, + 0, + 0, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 0, + 0, + 0, + 0, + 0 +}; + +void E_SELECT::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventEI0ID: + if(false == G()){ + sendOutputEvent( scm_nEventEOID); + } + break; + case scm_nEventEI1ID: + if(true == G()){ + sendOutputEvent( scm_nEventEOID); + } + break; + default: + break; + } +} + + + diff --git a/src/stdfblib/events/E_SELECT.h b/src/stdfblib/events/E_SELECT.h new file mode 100644 index 000000000..eee5da3cb --- /dev/null +++ b/src/stdfblib/events/E_SELECT.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SELECT_H_ +#define _E_SELECT_H_ + +#include +#include + +class E_SELECT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_SELECT) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + + static const TEventID scm_nEventEI0ID = 0; + static const TEventID scm_nEventEI1ID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEOID = 0; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,0,1, 0); + + CIEC_BOOL& G() { + return *static_cast(getDI(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_SELECT){ + }; + virtual ~E_SELECT(){}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_SPLIT.cpp b/src/stdfblib/events/E_SPLIT.cpp new file mode 100644 index 000000000..e29285593 --- /dev/null +++ b/src/stdfblib/events/E_SPLIT.cpp @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_SPLIT.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_SPLIT_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_SPLIT, g_nStringIdE_SPLIT) + +const CStringDictionary::TStringId E_SPLIT::scm_anEventInputNames[] = {g_nStringIdEI}; + +const CStringDictionary::TStringId E_SPLIT::scm_anEventOutputNames[] = {g_nStringIdEO1, g_nStringIdEO2}; + +const SFBInterfaceSpec E_SPLIT::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + 0, + 0, + 2, + scm_anEventOutputNames, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; diff --git a/src/stdfblib/events/E_SPLIT.h b/src/stdfblib/events/E_SPLIT.h new file mode 100644 index 000000000..9285e4cf9 --- /dev/null +++ b/src/stdfblib/events/E_SPLIT.h @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SPLIT_H_ +#define _E_SPLIT_H_ + +#include + +class E_SPLIT: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_SPLIT) + +private: + static const TEventID scm_nEventEIID = 0; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEO1ID = 0; + static const TEventID scm_nEventEO2ID = 1; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + + virtual void executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + sendOutputEvent( scm_nEventEO1ID); + sendOutputEvent( scm_nEventEO2ID); + } + }; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2,0,0, 0); + +public: + FUNCTION_BLOCK_CTOR(E_SPLIT){ + }; + virtual ~E_SPLIT(){}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_SR.cpp b/src/stdfblib/events/E_SR.cpp new file mode 100644 index 000000000..011d2a4e4 --- /dev/null +++ b/src/stdfblib/events/E_SR.cpp @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_SR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_SR_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_SR, g_nStringIdE_SR) + +const CStringDictionary::TStringId E_SR::scm_aunDataOutputNameIds[] = {g_nStringIdQ}; + +const CStringDictionary::TStringId E_SR::scm_aunEventInputNameIds[] = {g_nStringIdS, g_nStringIdR}; + +const TDataIOID E_SR::scm_anEOWith[] = {0, 255}; +const TForteInt16 E_SR::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId E_SR::scm_aunEventOutputNameIds[] = {g_nStringIdEO}; + +const CStringDictionary::TStringId E_SR::scm_aunDataOutputDataTypeIds[] = {g_nStringIdBOOL}; + +const SFBInterfaceSpec E_SR::scm_stFBInterfaceSpec = { + 2, + scm_aunEventInputNameIds, + 0, + 0, + 1, + scm_aunEventOutputNameIds, + scm_anEOWith, + scm_anEOWithIndexes, + 0, + 0, + 0, + 1, + scm_aunDataOutputNameIds, + scm_aunDataOutputDataTypeIds, + 0, + 0 +}; + +void E_SR::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case scm_nEventSID: + if(false == Q()){ + Q() = true; + sendOutputEvent( scm_nEventEOID); + } + break; + case scm_nEventRID: + if(true == Q()){ + Q() = false; + sendOutputEvent( scm_nEventEOID); + } + break; + default: + break; + } +} + + + + + diff --git a/src/stdfblib/events/E_SR.h b/src/stdfblib/events/E_SR.h new file mode 100644 index 000000000..4a3cd9ef7 --- /dev/null +++ b/src/stdfblib/events/E_SR.h @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Gerhard Ebenhofer, + * Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SR_H_ +#define _E_SR_H_ + +#include +#include + +class E_SR: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_SR) + +private: + static const CStringDictionary::TStringId scm_aunDataOutputNameIds[]; + static const CStringDictionary::TStringId scm_aunDataOutputDataTypeIds[]; + + static const TEventID scm_nEventSID = 0; + static const TEventID scm_nEventRID = 1; + static const CStringDictionary::TStringId scm_aunEventInputNameIds[]; + + static const TEventID scm_nEventEOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_aunEventOutputNameIds[]; + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + FORTE_FB_DATA_ARRAY(1,0,1, 0); + + CIEC_BOOL& Q() { + return *static_cast(getDO(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_SR){ + }; + virtual ~E_SR(){ }; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_SWITCH.cpp b/src/stdfblib/events/E_SWITCH.cpp new file mode 100644 index 000000000..cd440157a --- /dev/null +++ b/src/stdfblib/events/E_SWITCH.cpp @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_SWITCH.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_SWITCH_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(E_SWITCH, g_nStringIdE_SWITCH) + +const CStringDictionary::TStringId E_SWITCH::scm_anDataInputNames[] = {g_nStringIdG}; +const CStringDictionary::TStringId E_SWITCH::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 E_SWITCH::scm_anEIWithIndexes[] = {0}; +const TDataIOID E_SWITCH::scm_anEIWith[] = {0, 255}; +const CStringDictionary::TStringId E_SWITCH::scm_anEventInputNames[] = {g_nStringIdEI}; + +const CStringDictionary::TStringId E_SWITCH::scm_anEventOutputNames[] = {g_nStringIdEO0, g_nStringIdEO1}; + +const SFBInterfaceSpec E_SWITCH::scm_stFBInterfaceSpec = { + 1, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 2, + scm_anEventOutputNames, + 0, + 0, + 1, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 0, + 0, + 0, + 0, + 0 +}; + +void E_SWITCH::executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + //sendOutputEvent( (true == G) ? scm_nEventEO1ID : scm_nEventEO0ID); + if(true == G()){ + sendOutputEvent(scm_nEventEO1ID); + } + else{ + sendOutputEvent(scm_nEventEO0ID); + } + } +} diff --git a/src/stdfblib/events/E_SWITCH.h b/src/stdfblib/events/E_SWITCH.h new file mode 100644 index 000000000..e505acf2c --- /dev/null +++ b/src/stdfblib/events/E_SWITCH.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SWITCH_H_ +#define _E_SWITCH_H_ + +#include +#include + +class E_SWITCH: public CFunctionBlock{ + DECLARE_FIRMWARE_FB(E_SWITCH) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const TEventID scm_nEventEIID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventEO0ID = 0; + static const TEventID scm_nEventEO1ID = 1; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + + virtual void executeEvent(int pa_nEIID); + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2,1,0, 0); + + CIEC_BOOL& G() { + return *static_cast(getDI(0)); + } + +public: + FUNCTION_BLOCK_CTOR(E_SWITCH){ + }; + virtual ~E_SWITCH(){}; + +}; +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/events/E_TimeOut.cpp b/src/stdfblib/events/E_TimeOut.cpp new file mode 100644 index 000000000..af56c3514 --- /dev/null +++ b/src/stdfblib/events/E_TimeOut.cpp @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_TimeOut.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_TimeOut_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_E_TimeOut, g_nStringIdE_TimeOut) + +const TForteInt16 FORTE_E_TimeOut::scm_anEOWithIndexes[] = { -1 }; +const SAdapterInstanceDef FORTE_E_TimeOut::scm_astAdapterInstances[] = { { g_nStringIdATimeOut, g_nStringIdTimeOutSocket, false } }; + +const SFBInterfaceSpec FORTE_E_TimeOut::scm_stFBInterfaceSpec = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, scm_astAdapterInstances }; + +void FORTE_E_TimeOut::executeEvent(int pa_nEIID){ + if(cg_nExternalEventID == pa_nEIID){ + m_bActive = false; + sendAdapterEvent(scm_nTimeOutSocketAdpNum, FORTE_ATimeOut::scm_nEventTimeOutID); + } + else if(TimeOutSocket().START() == pa_nEIID){ + if(!m_bActive){ + setEventChainExecutor(m_poInvokingExecEnv); // delay notification should be execute in the same thread on as from where it has been triggered. + CTimerHandler::sm_poFORTETimer->registerTimedFB(&m_stTimeListEntry, TimeOutSocket().DT()); + m_bActive = true; + } + } + else if(TimeOutSocket().STOP() == pa_nEIID){ + if(m_bActive){ + CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); + m_bActive = false; + } + } +} + +EMGMResponse FORTE_E_TimeOut::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse eRetVal = CFunctionBlock::changeFBExecutionState(pa_unCommand); + if((e_RDY == eRetVal) && ((cg_nMGM_CMD_Stop == pa_unCommand) || (cg_nMGM_CMD_Kill == pa_unCommand))){ + if(m_bActive){ + CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); + m_bActive = false; + } + } + return eRetVal; +} + diff --git a/src/stdfblib/events/E_TimeOut.h b/src/stdfblib/events/E_TimeOut.h new file mode 100644 index 000000000..3ee3cf246 --- /dev/null +++ b/src/stdfblib/events/E_TimeOut.h @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_TIMEOUT_H_ +#define _E_TIMEOUT_H_ + +#include +#include +#include "../arch/timerha.h" +#include "ATimeOut.h" + +class FORTE_E_TimeOut : public CEventSourceFB{ + DECLARE_FIRMWARE_FB(FORTE_E_TimeOut) + + private: + static const TForteInt16 scm_anEOWithIndexes[]; + static const SAdapterInstanceDef scm_astAdapterInstances[]; + + FORTE_ATimeOut& TimeOutSocket(){ + return (*static_cast(m_apoAdapters[0])); + } + ; + static const int scm_nTimeOutSocketAdpNum = 0; + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(0, 0, 0, 1) + ; + + bool m_bActive; //!> flag to indicate that the timed fb is currently active + STimedFBListEntry m_stTimeListEntry; //!> The Timer list entry of this timed FB + + virtual void executeEvent(int pa_nEIID); + + public: + EVENT_SOURCE_FUNCTION_BLOCK_CTOR(FORTE_E_TimeOut){ + m_bActive = false; + m_stTimeListEntry.m_stTimeOut.m_nLowerValue = 0; + m_stTimeListEntry.m_stTimeOut.m_nUpperValue = 0; + m_stTimeListEntry.m_nInterval = 0; + m_stTimeListEntry.m_pstNext = 0; + m_stTimeListEntry.m_eType = e_SingleShot; + m_stTimeListEntry.m_poTimedFB = this; + }; + + virtual ~FORTE_E_TimeOut(){}; + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/events/GEN_E_DEMUX.cpp b/src/stdfblib/events/GEN_E_DEMUX.cpp new file mode 100644 index 000000000..2dea55e28 --- /dev/null +++ b/src/stdfblib/events/GEN_E_DEMUX.cpp @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_E_DEMUX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_E_DEMUX_gen.cpp" +#endif +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_E_DEMUX, g_nStringIdGEN_E_DEMUX) + +const CStringDictionary::TStringId GEN_E_DEMUX::scm_anDataInputNames[] = { g_nStringIdK }; +const CStringDictionary::TStringId GEN_E_DEMUX::scm_aunDIDataTypeIds[] = { g_nStringIdUINT }; + +const TForteInt16 GEN_E_DEMUX::scm_anEIWithIndexes[] = { 0 }; +const TDataIOID GEN_E_DEMUX::scm_anEIWith[] = { 0, 255 }; +const CStringDictionary::TStringId GEN_E_DEMUX::scm_anEventInputNames[] = { g_nStringIdEI }; + +GEN_E_DEMUX::GEN_E_DEMUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ + +} + +GEN_E_DEMUX::~GEN_E_DEMUX(){ + delete[] m_anEventOutputNames; +} + +void GEN_E_DEMUX::executeEvent(int pa_nEIID){ + if(scm_nEventEIID == pa_nEIID){ + if(K() < m_pstInterfaceSpec->m_nNumEOs){ + sendOutputEvent(K()); // the value of K corresponds to the output event ID; + } + } +} + +bool GEN_E_DEMUX::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + + const char *acPos = strrchr(pa_acConfigString, '_'); + + if(0 != acPos){ + ++acPos; + if('D' != *acPos){ + //we have an underscore and it is not the first underscore after E + unsigned int nNumEOs = static_cast(forte::core::util::strtoul(acPos, 0, 10)); + + if(nNumEOs < CFunctionBlock::scm_nMaxInterfaceEvents){ + m_anEventOutputNames = new CStringDictionary::TStringId[nNumEOs]; + + generateGenericInterfacePointNameArray("EO", m_anEventOutputNames, nNumEOs); + + SFBInterfaceSpecforGenerics *pstInterfaceSpec = new SFBInterfaceSpecforGenerics( + 1, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + static_cast(nNumEOs), m_anEventOutputNames, 0, 0, + 1, scm_anDataInputNames, scm_aunDIDataTypeIds, + 0, 0, 0); + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize(pstInterfaceSpec->m_nNumEOs, pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize(pstInterfaceSpec->m_nNumDIs, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + } + } + return bRetVal; +} diff --git a/src/stdfblib/events/GEN_E_DEMUX.h b/src/stdfblib/events/GEN_E_DEMUX.h new file mode 100644 index 000000000..5b994a584 --- /dev/null +++ b/src/stdfblib/events/GEN_E_DEMUX.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_E_DEMUX_H_ +#define _GEN_E_DEMUX_H_ + +#include +#include + +class GEN_E_DEMUX : public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_E_DEMUX) + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + + static const TEventID scm_nEventEIID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + CStringDictionary::TStringId *m_anEventOutputNames; + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void executeEvent(int pa_nEIID); + + CIEC_UINT& K(){ + return *static_cast(getDI(0)); + } + + GEN_E_DEMUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_E_DEMUX(); + public: + + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); + + +}; +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/events/GEN_E_MUX.cpp b/src/stdfblib/events/GEN_E_MUX.cpp new file mode 100644 index 000000000..85ecd3603 --- /dev/null +++ b/src/stdfblib/events/GEN_E_MUX.cpp @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Matthias Plasch + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_E_MUX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "GEN_E_MUX_gen.cpp" +#endif +#include + +DEFINE_GENERIC_FIRMWARE_FB(GEN_E_MUX, g_nStringIdGEN_E_MUX); + +const CStringDictionary::TStringId GEN_E_MUX::scm_anDataOutputNames[] = { g_nStringIdK }; +const CStringDictionary::TStringId GEN_E_MUX::scm_aunDODataTypeIds[] = { g_nStringIdUINT }; + +const TForteInt16 GEN_E_MUX::scm_anEOWithIndexes[] = { 0 }; +const TDataIOID GEN_E_MUX::scm_anEOWith[] = { 0, 255 }; +const CStringDictionary::TStringId GEN_E_MUX::scm_anEventOutputNames[] = { g_nStringIdEO }; + +GEN_E_MUX::GEN_E_MUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CFunctionBlock(pa_poSrcRes, 0, pa_nInstanceNameId, 0, 0){ +} + +GEN_E_MUX::~GEN_E_MUX(){ + delete[] m_anEventInputNames; +} + +void GEN_E_MUX::executeEvent(int pa_nEIID){ + if(pa_nEIID < m_pstInterfaceSpec->m_nNumEIs){ + K() = pa_nEIID; + sendOutputEvent(scm_nEventEOID); + } +} + +bool GEN_E_MUX::configureFB(const char *pa_acConfigString){ + bool bRetVal = false; + + m_nConfiguredFBTypeNameId = CStringDictionary::getInstance().insert(pa_acConfigString); + + const char *acPos = strrchr(pa_acConfigString, '_'); + + if(0 != acPos){ + ++acPos; + if('M' != *acPos){ + //we have an underscore and it is not the first underscore after E + unsigned int nNumEIs = static_cast(forte::core::util::strtoul(acPos, 0, 10)); + + if(nNumEIs < CFunctionBlock::scm_nMaxInterfaceEvents && nNumEIs >= 2){ + m_anEventInputNames = new CStringDictionary::TStringId[nNumEIs]; + + generateGenericInterfacePointNameArray("EI", m_anEventInputNames, nNumEIs); + + SFBInterfaceSpecforGenerics *pstInterfaceSpec = new SFBInterfaceSpecforGenerics( + static_cast(nNumEIs), m_anEventInputNames, 0, 0, + 1, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, + 0, 0, 0, + 1, scm_anDataOutputNames, scm_aunDODataTypeIds); + + TForteByte *acFBConnData = new TForteByte[genFBConnDataSize(1, 0, pstInterfaceSpec->m_nNumDOs)]; + TForteByte *acFBVarsData = new TForteByte[genFBVarsDataSize(0, pstInterfaceSpec->m_nNumDOs)]; + + setupFBInterface(pstInterfaceSpec, acFBConnData, acFBVarsData, true); + bRetVal = true; + } + else{ + if(nNumEIs >= CFunctionBlock::scm_nMaxInterfaceEvents){ + DEVLOG_ERROR("Cannot configure FB-Instance E_MUX_%d. Number of event inputs exceeds maximum of %d.\n", nNumEIs, CFunctionBlock::scm_nMaxInterfaceEvents); + } + else{ + DEVLOG_ERROR("Cannot configure FB-Instance E_MUX_%d. Number of event inputs smaller than minimum of 2.\n", nNumEIs); + } + } + } + } + return bRetVal; +} diff --git a/src/stdfblib/events/GEN_E_MUX.h b/src/stdfblib/events/GEN_E_MUX.h new file mode 100644 index 000000000..320bed354 --- /dev/null +++ b/src/stdfblib/events/GEN_E_MUX.h @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_E_MUX_H_ +#define _GEN_E_MUX_H_ + +#include +#include + +class GEN_E_MUX : public CFunctionBlock{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_E_MUX) + + private: + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + + static const TEventID scm_nEventEOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + CStringDictionary::TStringId *m_anEventInputNames; + CStringDictionary::TStringId m_nConfiguredFBTypeNameId; + + virtual void executeEvent(int pa_nEIID); + + CIEC_UINT& K(){ + return *static_cast(getDO(0)); + } + + GEN_E_MUX(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_E_MUX(); + public: + + CStringDictionary::TStringId getFBTypeId(void) const{ + return m_nConfiguredFBTypeNameId; + } + + bool configureFB(const char *pa_acConfigString); + + +}; +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/io/IW.cpp b/src/stdfblib/io/IW.cpp new file mode 100644 index 000000000..e4f0afab7 --- /dev/null +++ b/src/stdfblib/io/IW.cpp @@ -0,0 +1,67 @@ +/************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz - initial API and implementation and/or initial documentation + *************************************************************************/ + +#include "IW.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "IW_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_IW, g_nStringIdIW) + +const CStringDictionary::TStringId FORTE_IW::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdPARAMS}; + +const CStringDictionary::TStringId FORTE_IW::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_IW::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS, g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_IW::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdWORD}; + +const TForteInt16 FORTE_IW::scm_anEIWithIndexes[] = {0, 3}; +const TDataIOID FORTE_IW::scm_anEIWith[] = {0, 1, 255, 0, 255}; +const CStringDictionary::TStringId FORTE_IW::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_IW::scm_anEOWith[] = {0, 1, 255, 0, 1, 2, 255}; +const TForteInt16 FORTE_IW::scm_anEOWithIndexes[] = {0, 3, -1}; +const CStringDictionary::TStringId FORTE_IW::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_IW::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_IW::executeEvent(int pa_nEIID){ + QO() = QI(); + switch(pa_nEIID){ + case cg_nExternalEventID: + sendOutputEvent(scm_nEventINDID); + break; + case scm_nEventINITID: + if(true == QI()){ + QO() = CProcessInterface::initialise(true); //initialise as input + } + else{ + QO() = CProcessInterface::deinitialise(); + } + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(true == QI()){ + QO() = CProcessInterface::readWord(); + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + diff --git a/src/stdfblib/io/IW.h b/src/stdfblib/io/IW.h new file mode 100644 index 000000000..e63371f09 --- /dev/null +++ b/src/stdfblib/io/IW.h @@ -0,0 +1,98 @@ +/************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz - initial API and implementation and/or initial documentation + *************************************************************************/ + +#ifndef _IW_H_ +#define _IW_H_ + +#include +#include +#include +#include + +//TODO add compile time check that CWordAccess inherits from CWordAccessBase + +/*! /brief generic class for IW function blocks providing access to one word physical input + * + * In order that this FB can be used implementations need to provide a class CWordAccess + * this class needs to inherit from CWordAccessBase and provide the following functions + * + * - bool initialise(bool paInput) + * Initialize the physical input identified with the value of the PARAMS input + * - @param paInput: if true it should be an input, if false it should be an output + * - @return true on success, false on error + * + * - bool deinitialise() + * Deinitialize the physical port + * - @return true on success, false on error + * + * - bool readWord() + * Read the value of the physical input word and apply it to the function block's OUT() data output + * - @return true on success, false on error + * + * TODO a higher flexibility and easier use could be achieve if the base class would be a template parameter. However + * currently it is very hard to templatize a function block class. + */ +class FORTE_IW: public CProcessInterface{ + DECLARE_FIRMWARE_FB(FORTE_IW) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_STRING &PARAMS() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_STRING &STATUS() { + return *static_cast(getDO(1)); + }; + + CIEC_WORD &IN() { + return *static_cast(getDO(2)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TEventID scm_nEventINDID = 2; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 2, 3, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR_WITH_BASE_CLASS(FORTE_IW, CProcessInterface){ + }; + + virtual ~FORTE_IW(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/io/IX.cpp b/src/stdfblib/io/IX.cpp new file mode 100644 index 000000000..4ca877cbd --- /dev/null +++ b/src/stdfblib/io/IX.cpp @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Waldemar Eisenmenger, Monika Wenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "IX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "IX_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_IX, g_nStringIdIX) + +const CStringDictionary::TStringId FORTE_IX::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdPARAMS}; + +const CStringDictionary::TStringId FORTE_IX::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING}; + +const CStringDictionary::TStringId FORTE_IX::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS, g_nStringIdIN}; + +const CStringDictionary::TStringId FORTE_IX::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdBOOL}; + +const TForteInt16 FORTE_IX::scm_anEIWithIndexes[] = {0, 3}; +const TDataIOID FORTE_IX::scm_anEIWith[] = {0, 1, 255, 0, 255}; +const CStringDictionary::TStringId FORTE_IX::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_IX::scm_anEOWith[] = {0, 1, 255, 0, 1, 2, 255, 0, 1, 2, 255}; +const TForteInt16 FORTE_IX::scm_anEOWithIndexes[] = {0, 3, 7, -1}; +const CStringDictionary::TStringId FORTE_IX::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF, g_nStringIdIND}; + +const SFBInterfaceSpec FORTE_IX::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 3, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 2, scm_anDataInputNames, scm_anDataInputTypeIds, + 3, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_IX::executeEvent(int pa_nEIID){ + QO() = QI(); + switch(pa_nEIID){ + case cg_nExternalEventID: + sendOutputEvent(scm_nEventINDID); + break; + case scm_nEventINITID: + if(true == QI()){ + QO() = CProcessInterface::initialise(true); //initialise as input + } + else{ + QO() = CProcessInterface::deinitialise(); + } + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(true == QI()){ + QO() = CProcessInterface::readPin(); + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + + diff --git a/src/stdfblib/io/IX.h b/src/stdfblib/io/IX.h new file mode 100644 index 000000000..c7eaa4d53 --- /dev/null +++ b/src/stdfblib/io/IX.h @@ -0,0 +1,97 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Waldemar Eisenmenger, Monika Wenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _IX_H_ +#define _IX_H_ + +#include +#include +#include + +//TODO add compile time check that CProcessInterface inherits from CProcessInterfaceBase + +/*! /brief generic class for IX function blocks providing access to one boolean physical input + * + * In order that this FB can be used implementations need to provide a class CProcessInterface + * this class needs to inherit from CProcessInterfaceBase and provide the following functions + * + * - bool initialise(bool paInput) + * Initialize the physical input identified with the value of the PARAMS input + * - @param paInput: if true it should be an input, if false it should be an output + * - @return true on success, false on error + * + * - bool deinitialise() + * Deinitalize the physical port + * - @return true on success, false on error + * + * - bool readPin() + * Read the value of the physical input and apply it to the function block's OUT() data output + * - @return true on success, false on error + * + * TODO a higher flexibility and easier use could be achieve if the base class would be a template parameter. However + * currently it is very hard to templatize a function block class. + */ +class FORTE_IX: public CProcessInterface{ + DECLARE_FIRMWARE_FB(FORTE_IX) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_STRING &PARAMS() { + return *static_cast(getDI(1)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_STRING &STATUS() { + return *static_cast(getDO(1)); + }; + + CIEC_BOOL &IN() { + return *static_cast(getDO(2)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TEventID scm_nEventINDID = 2; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(3, 2, 3, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR_WITH_BASE_CLASS(FORTE_IX, CProcessInterface){ + }; + + virtual ~FORTE_IX(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/io/QW.cpp b/src/stdfblib/io/QW.cpp new file mode 100644 index 000000000..5207d9d38 --- /dev/null +++ b/src/stdfblib/io/QW.cpp @@ -0,0 +1,64 @@ +/************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz - initial API and implementation and/or initial documentation + *************************************************************************/ + +#include "QW.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "QW_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_QW, g_nStringIdQW) + +const CStringDictionary::TStringId FORTE_QW::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdPARAMS, g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_QW::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdWORD}; + +const CStringDictionary::TStringId FORTE_QW::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_QW::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING}; + +const TForteInt16 FORTE_QW::scm_anEIWithIndexes[] = {0, 3}; +const TDataIOID FORTE_QW::scm_anEIWith[] = {0, 1, 255, 0, 2, 255}; +const CStringDictionary::TStringId FORTE_QW::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_QW::scm_anEOWith[] = {0, 1, 255, 0, 1, 255}; +const TForteInt16 FORTE_QW::scm_anEOWithIndexes[] = {0, 3, -1}; +const CStringDictionary::TStringId FORTE_QW::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_QW::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +void FORTE_QW::executeEvent(int pa_nEIID){ + QO() = QI(); + switch(pa_nEIID){ + case scm_nEventINITID: + if(true == QI()){ + QO() = CProcessInterface::initialise(false); //initialise as output + } + else{ + QO() = CProcessInterface::deinitialise(); + } + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(true == QI()){ + QO() = CProcessInterface::writeWord(); + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + diff --git a/src/stdfblib/io/QW.h b/src/stdfblib/io/QW.h new file mode 100644 index 000000000..6f917dc0e --- /dev/null +++ b/src/stdfblib/io/QW.h @@ -0,0 +1,97 @@ +/************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gerd Kainz - initial API and implementation and/or initial documentation + *************************************************************************/ + +#ifndef _QW_H_ +#define _QW_H_ + +#include +#include +#include +#include + +//TODO add compile time check that CProcessInterface inherits from CWordAccessBase + +/*! /brief generic class for QW function blocks providing access to one word physical output + * + * In order that this FB can be used implementations need to provide a class CWordAccess + * this class needs to inherit from CWordAccessBase and provide the following functions + * + * - bool initialise(bool paInput) + * Initialize the physical output identified with the value of the PARAMS FB input + * - @param paInput: if true it should be an input, if false it should be an output + * - @return true on success, false on error + * + * - bool deinitialise() + * Deinitalize the physical port + * - @return true on success, false on error + * + * - bool writeWord() + * Write the value of function block's IN() data input to the physical input + * - @return true on success, false on error + * + * TODO a higher flexibility and easier use could be achieve if the base class would be a template parameter. However + * currently it is very hard to templatize a function block class. + */ +class FORTE_QW: public CProcessInterface{ + DECLARE_FIRMWARE_FB(FORTE_QW) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_STRING &PARAMS() { + return *static_cast(getDI(1)); + }; + + CIEC_WORD &OUT() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_STRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 2, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR_WITH_BASE_CLASS(FORTE_QW, CProcessInterface){ + }; + + virtual ~FORTE_QW(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/io/QX.cpp b/src/stdfblib/io/QX.cpp new file mode 100644 index 000000000..0ee0135a7 --- /dev/null +++ b/src/stdfblib/io/QX.cpp @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Waldemar Eisenmenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "QX.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "QX_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_QX, g_nStringIdQX) + +const CStringDictionary::TStringId FORTE_QX::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdPARAMS, g_nStringIdOUT}; + +const CStringDictionary::TStringId FORTE_QX::scm_anDataInputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_QX::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const CStringDictionary::TStringId FORTE_QX::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING}; + +const TForteInt16 FORTE_QX::scm_anEIWithIndexes[] = {0, 3}; +const TDataIOID FORTE_QX::scm_anEIWith[] = {0, 1, 255, 0, 2, 255}; +const CStringDictionary::TStringId FORTE_QX::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdREQ}; + +const TDataIOID FORTE_QX::scm_anEOWith[] = {0, 1, 255, 0, 1, 255}; +const TForteInt16 FORTE_QX::scm_anEOWithIndexes[] = {0, 3, -1}; +const CStringDictionary::TStringId FORTE_QX::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdCNF}; + +const SFBInterfaceSpec FORTE_QX::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 3, scm_anDataInputNames, scm_anDataInputTypeIds, + 2, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + +void FORTE_QX::executeEvent(int pa_nEIID){ + QO() = QI(); + switch(pa_nEIID){ + case scm_nEventINITID: + if(true == QI()){ + QO() = CProcessInterface::initialise(false); //initialise as output + } + else{ + QO() = CProcessInterface::deinitialise(); + } + sendOutputEvent(scm_nEventINITOID); + break; + case scm_nEventREQID: + if(true == QI()){ + QO() = CProcessInterface::writePin(); + } + sendOutputEvent(scm_nEventCNFID); + break; + } +} + + diff --git a/src/stdfblib/io/QX.h b/src/stdfblib/io/QX.h new file mode 100644 index 000000000..e663a4e7c --- /dev/null +++ b/src/stdfblib/io/QX.h @@ -0,0 +1,96 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Waldemar Eisenmenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _QX_H_ +#define _QX_H_ + +#include +#include +#include +#include + +//TODO add compile time check that CProcessInterface inherits from CProcessInterfaceBase + +/*! /brief generic class for QX function blocks providing access to one boolean physical output + * + * In order that this FB can be used implementations need to provide a class CProcessInterface + * this class needs to inherit from CProcessInterfaceBase and provide the following functions + * + * - bool initialise(bool paInput) + * Initialize the physical output identified with the value of the PARAMS FB input + * - @param paInput: if true it should be an input, if false it should be an output + * - @return true on success, false on error + * + * - bool deinitialise() + * Deinitalize the physical port + * - @return true on success, false on error + * + * - bool writePin() + * Write the value of function block's IN() data input to the physical input + * - @return true on success, false on error + * + * TODO a higher flexibility and easier use could be achieve if the base class would be a template parameter. However + * currently it is very hard to templatize a function block class. + */ +class FORTE_QX: public CProcessInterface{ + DECLARE_FIRMWARE_FB(FORTE_QX) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + CIEC_STRING &PARAMS() { + return *static_cast(getDI(1)); + }; + + CIEC_BOOL &OUT() { + return *static_cast(getDI(2)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &QO() { + return *static_cast(getDO(0)); + }; + + CIEC_STRING &STATUS() { + return *static_cast(getDO(1)); + }; + + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventREQID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventCNFID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 2, 0); + + void executeEvent(int pa_nEIID); + +public: + FUNCTION_BLOCK_CTOR_WITH_BASE_CLASS(FORTE_QX, CProcessInterface){ + }; + + virtual ~FORTE_QX(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/io/processinterfacebase.h b/src/stdfblib/io/processinterfacebase.h new file mode 100644 index 000000000..622bb9249 --- /dev/null +++ b/src/stdfblib/io/processinterfacebase.h @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2014 - 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Monika Wenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include +#include +#include + +#ifndef PROCESSINTERFACEBASE_H_ +#define PROCESSINTERFACEBASE_H_ + + +class CProcessInterfaceBase : public CEventSourceFB{ + public: + CProcessInterfaceBase(CResource *paSrcRes, const SFBInterfaceSpec *paInterfaceSpec, + const CStringDictionary::TStringId paInstanceNameId, TForteByte *paFBConnData, TForteByte *paFBVarsData) : + CEventSourceFB(paSrcRes, paInterfaceSpec, paInstanceNameId, paFBConnData, paFBVarsData){ + setEventChainExecutor(paSrcRes->getResourceEventExecution()); + } + + virtual ~CProcessInterfaceBase(){ + } + + protected: + CIEC_BOOL &QI(){ + return *static_cast(getDI(0)); + } + + CIEC_STRING &PARAMS(){ + return *static_cast(getDI(1)); + } + + CIEC_BOOL &QO(){ + return *static_cast(getDO(0)); + } + + CIEC_STRING &STATUS(){ + return *static_cast(getDO(1)); + } + + CIEC_BOOL &IN_X(){ + return *static_cast(getDO(2)); + } + + CIEC_BOOL &OUT_X() { + return *static_cast(getDI(2)); + }; + + CIEC_WORD &IN_W(){ + return *static_cast(getDO(2)); + } + + CIEC_WORD &OUT_W() { + return *static_cast(getDI(2)); + }; + + //TODO move pin checking and managing code into this class. Can be solved with recurring template pattern +}; + +#endif diff --git a/src/stdfblib/ita/CMakeLists.txt b/src/stdfblib/ita/CMakeLists.txt new file mode 100644 index 000000000..171ea67f7 --- /dev/null +++ b/src/stdfblib/ita/CMakeLists.txt @@ -0,0 +1,17 @@ +#******************************************************************************* +# * Copyright (c) 2010 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Ita FB +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +SET(SOURCE_GROUP ${SOURCE_GROUP}\\ita) +forte_add_sourcefile_hcpp(DEV_MGR DM_KRNL EMB_RES RMT_DEV RMT_RES) diff --git a/src/stdfblib/ita/DEV_MGR.cpp b/src/stdfblib/ita/DEV_MGR.cpp new file mode 100644 index 000000000..1398bddbe --- /dev/null +++ b/src/stdfblib/ita/DEV_MGR.cpp @@ -0,0 +1,741 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Thomas Strasser, Gerhard Ebenhofer, + * Oliver Hummer, Ingo Hegny, Michael Hofmann, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + * Monika Wenger + * - fix: apostrophes are deleted in parseWriteConnectionData + *******************************************************************************/ +#include +#include "DEV_MGR.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "DEV_MGR_gen.cpp" +#endif +#include "../../core/device.h" +#include +#include + + +DEFINE_FIRMWARE_FB(DEV_MGR, g_nStringIdDEV_MGR) + +const CStringDictionary::TStringId DEV_MGR::scm_aunEINameIds[2] = { g_nStringIdINIT, g_nStringIdREQ }; +const TDataIOID DEV_MGR::scm_anEIWith[6] = { 0, 255, 0, 1, 2, 255 }; +const TForteInt16 DEV_MGR::scm_anEIWithIndexes[2] = { 0, 2 }; +const CStringDictionary::TStringId DEV_MGR::scm_aunEONameIds[2] = { g_nStringIdINITO, g_nStringIdCNF }; +const TDataIOID DEV_MGR::scm_anEOWith[4] = { 0, 255, 1, 255 }; +const TForteInt16 DEV_MGR::scm_anEOWithIndexes[3] = { 0, 2 }; +const CStringDictionary::TStringId DEV_MGR::scm_aunDINameIds[3] = { g_nStringIdQI, g_nStringIdDST, g_nStringIdRQST }; +const CStringDictionary::TStringId DEV_MGR::scm_aunDIDataTypeIds[] = { g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdSTRING }; +const CStringDictionary::TStringId DEV_MGR::scm_aunDONameIds[2] = { g_nStringIdQO, g_nStringIdRESP }; +const CStringDictionary::TStringId DEV_MGR::scm_aunDODataTypeIds[] = { g_nStringIdBOOL, g_nStringIdSTRING }; + +const SFBInterfaceSpec DEV_MGR::scm_stFBInterfaceSpec = { 2, scm_aunEINameIds, scm_anEIWith, scm_anEIWithIndexes, 2, scm_aunEONameIds, scm_anEOWith, scm_anEOWithIndexes, 3, scm_aunDINameIds, scm_aunDIDataTypeIds, 2, scm_aunDONameIds, scm_aunDODataTypeIds, 0, 0 }; + +const char * const DEV_MGR::scm_sMGMResponseTexts[13] = { "RDY", "BAD_PARAMS", "LOCAL_TERMINATION", "SYSTEM_TERMINATION", "NOT_READY", "UNSUPPORTED_CMD", "UNSUPPORTED_TYPE", "NO_SUCH_OBJECT", "INVALID_OBJECT", "INVALID_OPERATION", "INVALID_STATE", "OVERFLOW", "INVALID_DST" }; + +void DEV_MGR::executeEvent(int pa_nEIID){ + + if(csm_nEventINITID == pa_nEIID){ +#ifdef FORTE_SUPPORT_BOOT_FILE + if((true == QI()) && (false == QO())){ + //this is the first time init is called try to load a boot file + loadForteBootFile(); + } +#endif + QO() = QI(); + sendOutputEvent(csm_nEventINITOID); + } + else if(csm_nEventREQID == pa_nEIID){ + QO() = QI(); + if(true == QI()){ + executeRQST(); + }else{ + RESP().clear(); + } + sendOutputEvent(csm_nEventCNFID); + } +} + +void DEV_MGR::executeRQST(void){ + m_stCommand.mAdditionalParams.clear(); + EMGMResponse resp = parseAndExecuteMGMCommand(DST().getValue(), RQST().getValue()); + + #ifdef FORTE_SUPPORT_MONITORING + if (0 != m_stCommand.mMonitorResponse.length()) { + generateMonitorResponse(resp, m_stCommand); + } else +#endif //FORTE_SUPPORT_MONITORING + if(0 < m_stCommand.mAdditionalParams.length()){ + generateLongResponse(resp, m_stCommand); + } + else{ + generateResponse(m_stCommand.mID, resp); + } +} + +char *DEV_MGR::parseRequest(char *pa_acRequestString, forte::core::SManagementCMD &pa_rstCommand){ +//first check if it is an management request + char *acCommandStart = 0; + static const int scnCommandLength[] = {7, 7, 6, 5, 5, 6, 5, 6, 6}; + + if(!strncmp("= 7){ + return 0; + } + } + pa_acRequestString[i] = '\0'; //close ID + ++i; + acCommandStart = strchr((&pa_acRequestString[i]), '\"'); + if(acCommandStart != 0){ + acCommandStart++; //this is the real start of the command + if(!strncmp("CREATE", acCommandStart, 6)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Create_Group; + } + else if(!strncmp("DELETE", acCommandStart, 6)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Delete_Group; + } + else if(!strncmp("START", acCommandStart, 5)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Start; + } + else if(!strncmp("STOP", acCommandStart, 4)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Stop; + } + else if(!strncmp("KILL", acCommandStart, 4)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Kill; + } + else if(!strncmp("RESET", acCommandStart, 5)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Reset; + } + else if(!strncmp("READ", acCommandStart, 4)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Read; + } + else if(!strncmp("WRITE", acCommandStart, 5)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Write; + } +#ifdef FORTE_SUPPORT_QUERY_CMD + else if(!strncmp("QUERY", acCommandStart, 5)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Query_Group; + } +#endif + else{ + return 0; + } + acCommandStart += scnCommandLength[pa_rstCommand.mCMD]; + } + } + + return acCommandStart; +} + +bool DEV_MGR::parseFBData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + bool bRetVal = false; + + if(!strncmp("FB Name=\"", pa_acRequestPartLeft, 9)){ + if(strstr("EventIn=\"", pa_acRequestPartLeft) != 0){ + // TODO parse all parameters + } + else{ + char *acBuf = &(pa_acRequestPartLeft[9]); + int i = 0; + if(acBuf[0] != '*'){ + i = parseIdentifier(acBuf, pa_rstCommand.mFirstParam); + acBuf = (-1 == i) ? 0 : strchr(&(acBuf[i + 1]), '\"'); + } + else{ + acBuf = strchr(&(acBuf[i + 2]), '\"'); + } + + if(acBuf != 0){ + if(acBuf[1] != '*'){ + ++acBuf; + i = parseIdentifier(acBuf, pa_rstCommand.mSecondParam); + if(-1 != i){ + acBuf = strchr(&(acBuf[i + 1]), '\"'); + if(acBuf != 0){ + // We have an application name given + ++acBuf; + i = 0; + TForteUInt16 nBufLength = static_cast(strcspn(acBuf, "\"") + 1); + pa_rstCommand.mAdditionalParams.assign(acBuf, nBufLength); + } + } else{ + return false; + } + } + bRetVal = true; + } + } + } + return bRetVal; +} + +int DEV_MGR::parseIdentifier(char *paIdentifierStart, forte::core::TNameIdentifier &paIdentifier){ + for(char *runner = paIdentifierStart, *start = paIdentifierStart; '\0' != runner; ++runner){ + if('.' == *runner){ + *runner = '\0'; + if(!paIdentifier.pushBack(CStringDictionary::getInstance().insert(start))){ + return -1; + } + *runner = '.'; + start = runner + 1; + } else if ('"' == *runner){ + *runner = '\0'; + if(!paIdentifier.pushBack(CStringDictionary::getInstance().insert(start))){ + return -1; + } + *runner = '"'; + return static_cast(runner - paIdentifierStart); + } + } + return -1; +} + +bool DEV_MGR::parseConnectionData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + bool bRetVal = false; + if(!strncmp("Connection Source=\"", pa_acRequestPartLeft, 19)){ + int i= parseIdentifier(&(pa_acRequestPartLeft[19]), pa_rstCommand.mFirstParam); + if(-1 != i){ + char *acBuf = strchr(&(pa_acRequestPartLeft[i + 21]), '\"'); + if(acBuf != 0){ + parseIdentifier(&(acBuf[1]), pa_rstCommand.mSecondParam); + bRetVal = (-1 != i); + } + } + } + return bRetVal; +} + +bool DEV_MGR::parseWriteConnectionData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + bool bRetVal = false; + char cBuffer[255] = ""; + if(!strncmp("Connection Source=\"", pa_acRequestPartLeft, 19)){ + pa_acRequestPartLeft = &(pa_acRequestPartLeft[19]); + //first retreive the data for the param + if('&' == *pa_acRequestPartLeft){ + do{ + pa_acRequestPartLeft++; + } while(';' != *pa_acRequestPartLeft); + pa_acRequestPartLeft++; + } + // TODO: check if "-character should also be trimmed from pa_acRequestPartLeft + unsigned int i = 0; + for(; *pa_acRequestPartLeft != '\"'; ++pa_acRequestPartLeft, ++i){ + if('\0' == *pa_acRequestPartLeft){ + return false; + } + if('&' == *pa_acRequestPartLeft){ + do{ + pa_acRequestPartLeft++; + } while(';' != *pa_acRequestPartLeft); + pa_acRequestPartLeft += 2; //go beyound the ; and the following " + break; + } + cBuffer[i] = *pa_acRequestPartLeft; + } + + cBuffer[i + 1] = '\0'; + pa_rstCommand.mAdditionalParams.assign(cBuffer, static_cast(i)); + + pa_acRequestPartLeft = strchr(&(pa_acRequestPartLeft[1]), '\"'); + if(pa_acRequestPartLeft != 0){ + int nCharsUsed = parseIdentifier(&(pa_acRequestPartLeft[1]), pa_rstCommand.mFirstParam); + bRetVal = (-1 != nCharsUsed); + } + } + return bRetVal; +} + +void DEV_MGR::parseCreateData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + pa_rstCommand.mCMD = cg_nMGM_CMD_INVALID; + if(0 != pa_acRequestPartLeft){ + switch (pa_acRequestPartLeft[0]){ + case 'F': // we have an FB to Create + if(parseFBData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Create_FBInstance; + } + else{ + pa_rstCommand.mCMD = cg_nMGM_CMD_Create_FBType; + } + break; + case 'C': // we have an Connection to Create + if(parseConnectionData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Create_Connection; + } + break; + #ifdef FORTE_SUPPORT_MONITORING + case 'W': // we have an Watch to Add + if(parseMonitoringData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_Add_Watch; + } + break; + #endif // FORTE_SUPPORT_MONITORING + default: + break; + } + } +} + +void DEV_MGR::parseDeleteData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + pa_rstCommand.mCMD = cg_nMGM_CMD_INVALID; + if(0 != pa_acRequestPartLeft){ + switch (pa_acRequestPartLeft[0]){ + case 'F': // we have an FB to delete + if(parseFBData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Delete_FBInstance; + } + break; + case 'C': // we have an Connection to delete + if(parseConnectionData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Delete_Connection; + } + break; + #ifdef FORTE_SUPPORT_MONITORING + case 'W': // we have an Watch to remove + if(parseMonitoringData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_Remove_Watch; + } + break; + #endif // FORTE_SUPPORT_MONITORING + default: + break; + } + } +} + +void DEV_MGR::parseAdditionalStateCommandData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + if(0 != pa_acRequestPartLeft){ + if('/' != pa_acRequestPartLeft[0]){ + //if we have an additional xml token parse if it is an FB definition + if(!parseFBData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_INVALID; + } + } + } +} + +void DEV_MGR::parseReadData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + pa_rstCommand.mCMD = cg_nMGM_CMD_INVALID; + if(0 != pa_acRequestPartLeft){ +#ifdef FORTE_SUPPORT_MONITORING + if('W' == pa_acRequestPartLeft[0]){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_Read_Watches; + } else if (!strncmp(pa_acRequestPartLeft, "Connection Source=\"*\" Destination=\"*\"", 37)) { + if (!parseConnectionStarStarData(pa_acRequestPartLeft + 37, pa_rstCommand)) { + pa_rstCommand.mCMD = cg_nMGM_CMD_INVALID; + } else { + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_Get_Watches; + } + } else +#endif // FORTE_SUPPORT_MONITORING + if(parseConnectionData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Read; + } + } +} + +void DEV_MGR::parseWriteData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + //We need an additional xml connection token parse if it is an connection definition + pa_rstCommand.mCMD = cg_nMGM_CMD_INVALID; + if(0 != pa_acRequestPartLeft){ + if(parseWriteConnectionData(pa_acRequestPartLeft, pa_rstCommand)) { +#ifdef FORTE_SUPPORT_MONITORING + char *pch = strstr(pa_acRequestPartLeft, "force=\""); + if (0 != pch) { + if (!strncmp(&pch[7], "true", 4)) { + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_Force; + } else if (!strncmp(&pch[7], "false", 5)) { + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_ClearForce; + } + } else if ((2 == pa_rstCommand.mAdditionalParams.length()) && + (('$' == pa_rstCommand.mAdditionalParams.getValue()[0]) && + (('e' == pa_rstCommand.mAdditionalParams.getValue()[1]) ||('E' == pa_rstCommand.mAdditionalParams.getValue()[1]) ))){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_Trigger_Event; + }else if ((3 == pa_rstCommand.mAdditionalParams.length()) && + (('$' == pa_rstCommand.mAdditionalParams.getValue()[0]) && + (('e' == pa_rstCommand.mAdditionalParams.getValue()[1]) ||('E' == pa_rstCommand.mAdditionalParams.getValue()[1]) ) && + (('r' == pa_rstCommand.mAdditionalParams.getValue()[2]) ||('R' == pa_rstCommand.mAdditionalParams.getValue()[2]) ) )){ + pa_rstCommand.mCMD = cg_nMGM_CMD_Monitoring_Reset_Event_Count; + }else +#endif // FORTE_SUPPORT_MONITORING + pa_rstCommand.mCMD = cg_nMGM_CMD_Write; + } + } +} + +#ifdef FORTE_SUPPORT_QUERY_CMD +void DEV_MGR::parseQueryData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + pa_rstCommand.mCMD = cg_nMGM_CMD_INVALID; + if(0 != pa_acRequestPartLeft){ + switch (pa_acRequestPartLeft[0]){ + case 'F': // query fb or fb type list + if(!strncmp(pa_acRequestPartLeft, "FBT", 3)){ + if(parseTypeListData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_QUERY_FBTypes; + } else { + pa_rstCommand.mCMD = cg_nMGM_CMD_Query_Group; + } + }else if(parseFBData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_QUERY_FB; + } + break; + case 'C': // query connection list + if(parseConnectionData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_QUERY_Connection; + } + break; + case 'D': // query datatype list + if(!strncmp(pa_acRequestPartLeft, "DataType", 8)){ + if(parseTypeListData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_QUERY_DTTypes; + } else { + pa_rstCommand.mCMD = cg_nMGM_CMD_Query_Group; + } + } + break; + case 'A': // query adaptertype list + if(!strncmp(pa_acRequestPartLeft, "AdapterT", 8)){ + if(parseTypeListData(pa_acRequestPartLeft, pa_rstCommand)){ + pa_rstCommand.mCMD = cg_nMGM_CMD_QUERY_AdapterTypes; + } else { + pa_rstCommand.mCMD = cg_nMGM_CMD_Query_Group; + } + } + + break; + default: + break; + } + } +} + +bool DEV_MGR::parseTypeListData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &){ + bool bRetVal = true; + + if (!strncmp("DataType Name=\"", pa_acRequestPartLeft, 15)) { + if(pa_acRequestPartLeft[15] != '*'){ //does not support query for DataType-Declaration + bRetVal = false; + } + } + else if(!strncmp("FBType Name=\"", pa_acRequestPartLeft, 13)){ + if(pa_acRequestPartLeft[13] != '*'){ //does not support query for DataType-Declaration + bRetVal = false; + } + } + else if(!strncmp("AdapterType Name=\"", pa_acRequestPartLeft, 18)){ + if(pa_acRequestPartLeft[18] != '*'){ //does not support query for DataType-Declaration + bRetVal = false; + } + } + return bRetVal; +} +#endif + +void DEV_MGR::generateResponse(const char *pa_acID, EMGMResponse pa_eResp){ + RESP().clear(); + RESP().append(""); +} + +void DEV_MGR::generateLongResponse(EMGMResponse pa_eResp, forte::core::SManagementCMD &pa_stCMD){ + RESP().clear(); + RESP().reserve(static_cast(255+(pa_stCMD.mAdditionalParams.length()))); + RESP().append("\n "); + } + else{ + RESP().append(">\n "); + if(pa_stCMD.mCMD == cg_nMGM_CMD_Read){ + RESP().append(""); + } +#ifdef FORTE_SUPPORT_QUERY_CMD + else if(pa_stCMD.mCMD == cg_nMGM_CMD_QUERY_Connection){ + if ((pa_stCMD.mFirstParam.isEmpty()) && + (pa_stCMD.mSecondParam.isEmpty())) { //src & dst = * + RESP().append(pa_stCMD.mAdditionalParams.getValue()); + } + else { //either src or dst = * (both != * should be treated by generateResponse + RESP().append("\n "); + RESP().append(pa_stCMD.mAdditionalParams.getValue()); + RESP().append("\n "); + } + } + else if(pa_stCMD.mCMD == cg_nMGM_CMD_QUERY_FB){ + if(!pa_stCMD.mFirstParam.isEmpty()) { //Name != "*" + if(!pa_stCMD.mSecondParam.isEmpty()){ //Type != "*" + RESP().append(""); + } else { //Type == "*" + RESP().append(""); + } + } + else{ + RESP().append("\n "); + RESP().append(pa_stCMD.mAdditionalParams.getValue()); + RESP().append("\n "); + } + } + else if(pa_stCMD.mCMD == cg_nMGM_CMD_QUERY_FBTypes){ + RESP().append("\n "); + RESP().append(pa_stCMD.mAdditionalParams.getValue()); + RESP().append("\n "); + } + else if(pa_stCMD.mCMD == cg_nMGM_CMD_QUERY_DTTypes){ + RESP().append("\n "); + RESP().append(pa_stCMD.mAdditionalParams.getValue()); + RESP().append("\n "); + } + else if(pa_stCMD.mCMD == cg_nMGM_CMD_QUERY_AdapterTypes){ + RESP().append("\n "); + RESP().append(pa_stCMD.mAdditionalParams.getValue()); + RESP().append("\n "); + } +#endif + } + RESP().append("\n"); +} + +void DEV_MGR::appedIdentifierName(CIEC_STRING& paDest, forte::core::TNameIdentifier &paIdentifier){ + if(!paIdentifier.isEmpty()){ + for(forte::core::TNameIdentifier::CIterator runner(paIdentifier.begin()); + runner != paIdentifier.end(); ++runner){ + paDest.append(CStringDictionary::getInstance().get(*runner)); + paDest.append("."); + } + paDest.append(CStringDictionary::getInstance().get(paIdentifier.back())); + } +} + +DEV_MGR::~DEV_MGR(){ +} + + +#ifdef FORTE_SUPPORT_BOOT_FILE +void DEV_MGR::loadForteBootFile(){ + char acLineBuf[cg_unBootFileLineBufSize]; //TODO maybe move it out of the stack + + char* bootFileName; + bootFileName = getenv ("FORTE_BOOT_FILE"); + FILE *bootfile = 0; + if(bootFileName != 0){ + bootfile = fopen(bootFileName, "r"); + }else{ + bootfile = fopen(FORTE_BOOT_FILE_LOCATION, "r"); + } + + if(0 != bootfile){ + DEVLOG_INFO("Boot file %s opened\n", (0 != bootFileName) ? bootFileName : FORTE_BOOT_FILE_LOCATION); + //we could open the file try to load it + int nLineCount = 1; + EMGMResponse eResp; + char *cmdStart; + + while(0 != fgets(acLineBuf, cg_unBootFileLineBufSize, bootfile)){ + if('\n' != acLineBuf[strlen(acLineBuf) - 1]){ + //the line has been longer than our buffer + DEVLOG_ERROR("Boot file line longer than configured buffer size: %d\n", cg_unBootFileLineBufSize); + //As we were not able to load the bootfile clean any created resources and FBs and start an empty device + m_stCommand.mCMD = cg_nMGM_CMD_Delete_AllFBInstances; + m_stCommand.mDestination = CStringDictionary::scm_nInvalidStringId; + m_poDevice.executeMGMCommand(m_stCommand); + break; + } + + cmdStart = strchr(acLineBuf, ';'); + if(0 == cmdStart){ + DEVLOG_ERROR("Boot file line does not contain separating ';'. Line: %d\n", nLineCount); + break; + } + *cmdStart = '\0'; + cmdStart++; + + eResp = parseAndExecuteMGMCommand(acLineBuf, cmdStart); + if(e_RDY != eResp){ + //command was not successful + DEVLOG_ERROR("Boot file command could not be executed. Line: %d: %s, Response %s\n", nLineCount, cmdStart, scm_sMGMResponseTexts[eResp]); + break; + } + nLineCount++; + } + + fclose(bootfile); + } + else{ + if(bootFileName != 0){ + DEVLOG_WARNING("Boot file %s could not be opened\n", bootFileName); + }else{ + DEVLOG_WARNING("Boot file forte.fboot could not be opened\n"); + } + } +} +#endif + +EMGMResponse DEV_MGR::parseAndExecuteMGMCommand(char *pa_acDest, char *pa_acCommand){ + EMGMResponse eResp = e_INVALID_OBJECT; + + if(0 != strchr(pa_acCommand, '>')){ + m_stCommand.mDestination = (strlen(pa_acDest) != 0) ? CStringDictionary::getInstance().insert(pa_acDest) : CStringDictionary::scm_nInvalidStringId; + m_stCommand.mFirstParam.clear(); + m_stCommand.mSecondParam.clear(); + if ( 255 <= m_stCommand.mAdditionalParams.getCapacity()) { + m_stCommand.mAdditionalParams.reserve(255); + } + m_stCommand.mID=0; +#ifdef FORTE_SUPPORT_MONITORING + m_stCommand.mMonitorResponse.clear(); +#endif // FORTE_SUPPORT_MONITORING + char *acRequestPartLeft = parseRequest(pa_acCommand, m_stCommand); + if(0 != acRequestPartLeft){ + acRequestPartLeft = strchr(acRequestPartLeft, '<'); + if(0 != acRequestPartLeft){ + acRequestPartLeft++; //point to the next character after the < + } + // we got the command for execution + // now check the rest of the data + switch (m_stCommand.mCMD){ + case cg_nMGM_CMD_Create_Group: // create something + parseCreateData(acRequestPartLeft, m_stCommand); + break; + case cg_nMGM_CMD_Delete_Group: //delete something + parseDeleteData(acRequestPartLeft, m_stCommand); + break; + case cg_nMGM_CMD_Start: + case cg_nMGM_CMD_Stop: + case cg_nMGM_CMD_Kill: + case cg_nMGM_CMD_Reset: + parseAdditionalStateCommandData(acRequestPartLeft, m_stCommand); + break; + case cg_nMGM_CMD_Read: + parseReadData(acRequestPartLeft, m_stCommand); + break; + case cg_nMGM_CMD_Write: + parseWriteData(acRequestPartLeft, m_stCommand); + break; +#ifdef FORTE_SUPPORT_QUERY_CMD + case cg_nMGM_CMD_Query_Group: // query something + parseQueryData(acRequestPartLeft, m_stCommand); +#endif + break; + default: + break; + } + + if(cg_nMGM_CMD_INVALID != m_stCommand.mCMD) { + eResp = m_poDevice.executeMGMCommand(m_stCommand); + } + } + else { + eResp = e_UNSUPPORTED_CMD; + } + } + + return eResp; +} + +#ifdef FORTE_SUPPORT_MONITORING + +bool DEV_MGR::parseConnectionStarStarData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + bool bRetVal = false; + + DEVLOG_DEBUG(pa_acRequestPartLeft); + + if(!strncmp(" forced=\"", pa_acRequestPartLeft, 9)){ + + if (pa_acRequestPartLeft[9]=='*' && pa_acRequestPartLeft[10] =='\"') { + pa_rstCommand.mAdditionalParams.assign("*",1); + bRetVal = true; + } else if (!strncmp(&pa_acRequestPartLeft[9], "true", 4)) { + pa_rstCommand.mAdditionalParams.assign("true", 4); + bRetVal = true; + } else if (!strncmp(&pa_acRequestPartLeft[9],"false", 5)) { + pa_rstCommand.mAdditionalParams.assign("false", 5); + bRetVal = true; + } + } + + if (!bRetVal) { + pa_rstCommand.mAdditionalParams.clear(); + } + return bRetVal; +} + +bool DEV_MGR::parseMonitoringData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand){ + bool bRetVal = false; + if(!strncmp("Watch Source=\"", pa_acRequestPartLeft, 14)){ + int i= parseIdentifier(&(pa_acRequestPartLeft[14]), pa_rstCommand.mFirstParam); + if(-1 != i){ + char *acBuf = strchr(&(pa_acRequestPartLeft[i + 16]), '\"'); + if(acBuf != 0){ + parseIdentifier(&(acBuf[1]), pa_rstCommand.mSecondParam); + bRetVal = (-1 != i); + } + } + } + return bRetVal; +} + +void DEV_MGR::generateMonitorResponse(EMGMResponse pa_eResp, forte::core::SManagementCMD &pa_stCMD){ + RESP().clear(); + if(e_RDY != pa_eResp){ + RESP().append("\n "); + RESP().append("\n"); + }else{ + TForteUInt16 size = static_cast(pa_stCMD.mMonitorResponse.length() + strlen(pa_stCMD.mID) + 74); + RESP().reserve(size); + + RESP().clear(); + RESP().append("\n "); + if((pa_stCMD.mCMD == cg_nMGM_CMD_Monitoring_Read_Watches) || + (pa_stCMD.mCMD == cg_nMGM_CMD_Monitoring_Get_Watches)){ + RESP().append("\n "); + RESP().append(pa_stCMD.mMonitorResponse.getValue()); + RESP().append("\n "); + } + RESP().append("\n"); + } + pa_stCMD.mMonitorResponse.clear(); +} + +#endif // FORTE_SUPPORT_MONITORING diff --git a/src/stdfblib/ita/DEV_MGR.h b/src/stdfblib/ita/DEV_MGR.h new file mode 100644 index 000000000..fbb5df3b9 --- /dev/null +++ b/src/stdfblib/ita/DEV_MGR.h @@ -0,0 +1,168 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Thomas Strasser, Gerhard Ebenhofer, + * Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _DEV_MGR_H_ +#define _DEV_MGR_H_ + +#include +#include "../../core/resource.h" +#include +#include +#include + +/*! \brief Implementation of the DEV_MGR FB. + */ +class DEV_MGR: public CFunctionBlock { + DECLARE_FIRMWARE_FB(DEV_MGR) + + private: + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + static const CStringDictionary::TStringId scm_aunEINameIds[2]; + static const TDataIOID scm_anEIWith[6]; + static const TForteInt16 scm_anEIWithIndexes[2]; + static const CStringDictionary::TStringId scm_aunEONameIds[2]; + static const TDataIOID scm_anEOWith[4]; + static const TForteInt16 scm_anEOWithIndexes[3]; + static const CStringDictionary::TStringId scm_aunDONameIds[2]; + static const CStringDictionary::TStringId scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_aunDINameIds[3]; + static const CStringDictionary::TStringId scm_aunDODataTypeIds[]; + + static const TEventID csm_nEventINITOID = 0; + static const TEventID csm_nEventCNFID = 1; + + static const TEventID csm_nEventINITID = 0; + static const TEventID csm_nEventREQID = 1; + + FORTE_FB_DATA_ARRAY(2, 3, 2, 0); + + //! The device the block is contained in + CDevice &m_poDevice; + + void executeRQST(void); + /*! \brief Parse the given request header to determine the ID and the requested command + * + * \param pa_acRequestString data of the request + * \param pa_rstCommand the command structure for holding command information + * \return pointer to the next part of the command zero on error + */ + static char* parseRequest(char *pa_acRequestString, forte::core::SManagementCMD &pa_rstCommand); + /*! \brief Parse the given request that is left after parsing the header to parse FB data + * + * \param pa_acRequestPartLeft data of the request that has been left after parsing the header + * \param pa_rstCommand the command structure for holding command information + * \return true if the FB data could be parsed + */ + static bool parseFBData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + /*! \brief Parse the given request that is left after parsing the header to parse connection data + * + * \param pa_acRequestPartLeft data of the request that has been left after parsing the header + * \param pa_rstCommand the command structure for holding command information + * \return true if the connection data could be parsed + */ + static bool parseConnectionData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + static bool parseWriteConnectionData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + + + static void parseCreateData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + static void parseDeleteData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + //! Check if an FB is given for a state change command (i.e., START, STOP, KILL, RESET) + static void parseAdditionalStateCommandData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + static void parseReadData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + static void parseWriteData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + +#ifdef FORTE_SUPPORT_QUERY_CMD + static void parseQueryData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + static bool parseTypeListData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); +#endif + + + /*! \brief parse a hierarchical identifier list + * + * The identifiers are separated by '.' and the end character for the list is '\"' + * + * @param paIdentifierStart pointer to the start of the identifier that will be parsed + * @param paIdentifier identifier vector where to write the parsed identifiers to + * @return number of bytes used from the character array or -1 if the identifier could not be parsed + */ + static int parseIdentifier(char *paIdentifierStart, forte::core::TNameIdentifier &paIdentifier); + + virtual void executeEvent(int pa_nEIID); + +#ifdef FORTE_SUPPORT_MONITORING + static bool parseMonitoringData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); + void generateMonitorResponse(EMGMResponse pa_eResp, forte::core::SManagementCMD &pa_stCMD); + static bool parseConnectionStarStarData(char *pa_acRequestPartLeft, forte::core::SManagementCMD &pa_rstCommand); +#endif //FORTE_SUPPORT_MONITORING virtual void executeEvent(int pa_nEIID); + + /*! \brief set the RESP output of the DEV_MGR according to the given response data + * + * \param pa_acID id of the response + * \param pa_eResp qualifier of the response + */ + void generateResponse(const char *pa_acID, EMGMResponse pa_eResp); + /*! \brief set the RESP output of the DEV_MGR according to the given response data + * + * \param pa_acID id of the response + * \param pa_eResp qualifier of the response + * \param pa_stCMD the command type + */ + void generateLongResponse(EMGMResponse pa_eResp, forte::core::SManagementCMD &pa_stCMD); + void appedIdentifierName(CIEC_STRING& paDest, forte::core::TNameIdentifier &paIdentifier); + + CIEC_BOOL& QI() { + return *static_cast(getDI(0)); + } + + CIEC_STRING& DST() { + return *static_cast(getDI(1)); + } + + CIEC_STRING& RQST() { + return *static_cast(getDI(2)); + } + + CIEC_BOOL& QO() { + return *static_cast(getDO(0)); + } + + CIEC_STRING& RESP() { + return *static_cast(getDO(1)); + } + + + public: + /*!\brief Type for the response of MGM command messages + * + * TODO fully define all responses as defined in IEC 61499 inc. numbers. + */ + static const char * const scm_sMGMResponseTexts[13]; + + FUNCTION_BLOCK_CTOR(DEV_MGR), + m_poDevice(pa_poSrcRes->getDevice()) { + m_stCommand.mAdditionalParams.reserve(255); + m_stCommand.mAdditionalParams.clear(); + }; + virtual ~DEV_MGR(); + + private: +#ifdef FORTE_SUPPORT_BOOT_FILE + void loadForteBootFile(); +#endif + EMGMResponse parseAndExecuteMGMCommand(char *pa_acDest, char *pa_acCommand); + + forte::core::SManagementCMD m_stCommand; + + }; + +#endif /*DEV_MGR_H_*/ diff --git a/src/stdfblib/ita/DM_KRNL.cpp b/src/stdfblib/ita/DM_KRNL.cpp new file mode 100644 index 000000000..3862fdd7c --- /dev/null +++ b/src/stdfblib/ita/DM_KRNL.cpp @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH, nxtControl GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Gerhard Ebenhofer, Ingo Hegny, + * Stanislav Meduna, Micheal Hofmann + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "DM_KRNL.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "DM_KRNL_gen.cpp" +#endif +#include + +DEFINE_FIRMWARE_FB(DM_KRNL, g_nStringIdDM_KRNL) + +const CStringDictionary::TStringId DM_KRNL::scm_aunDataInputNameIds[] = {g_nStringIdQI, g_nStringIdID}; + +const CStringDictionary::TStringId DM_KRNL::scm_aunDataOutputNameIds[] = {g_nStringIdQO, g_nStringIdSTATUS}; + +const TForteInt16 DM_KRNL::scm_anEIWithIndexes[] = {0}; +const TDataIOID DM_KRNL::scm_anEIWith[] = {0, 1, 255}; +const CStringDictionary::TStringId DM_KRNL::scm_aunEventInputNameIds[] = {g_nStringIdINIT}; + +const TDataIOID DM_KRNL::scm_anEOWith[] = {0, 1, 255}; +const TForteInt16 DM_KRNL::scm_anEOWithIndexes[] = {0}; +const CStringDictionary::TStringId DM_KRNL::scm_aunEventOutputNameIds[] = {g_nStringIdINITO}; + +const CStringDictionary::TStringId DM_KRNL::scm_aunDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdWSTRING}; + + +const SFBInterfaceSpec DM_KRNL::scm_stFBInterfaceSpec = { + 1, + scm_aunEventInputNameIds, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_aunEventOutputNameIds, + scm_anEOWith, + scm_anEOWithIndexes, + 2, + scm_aunDataInputNameIds, + scm_aunDataTypeIds, + 2, + scm_aunDataOutputNameIds, + scm_aunDataTypeIds, + 0, + 0 +}; + +#define replace_1(name) g_nStringId##name + +#define FORTE_GEN_DEV_MGR_NAME(name) replace_1(name) + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP + extern const CStringDictionary::TStringId FORTE_GEN_DEV_MGR_NAME(FORTE_MGM_COMMAND_PROTOCOL); +#endif + +const SCFB_FBInstanceData DM_KRNL::scm_astInternalFBs[] = { + {g_nStringIdSVR, g_nStringIdSERVER_1_2}, + {g_nStringIdMGR, FORTE_GEN_DEV_MGR_NAME(FORTE_MGM_COMMAND_PROTOCOL)}}; + +const SCFB_FBConnectionData DM_KRNL::scm_astEventConnections[] = { + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR, g_nStringIdINITO), 0, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdINITO), -1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR, g_nStringIdIND), 0, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR,g_nStringIdREQ), 1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR, g_nStringIdCNF), 1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR,g_nStringIdRSP), 0}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdINIT), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR,g_nStringIdINIT), 1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR,g_nStringIdINITO), 1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR,g_nStringIdINIT), 0} +}; + +const SCFB_FBConnectionData DM_KRNL::scm_astDataConnections[] = { + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdQI), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR, g_nStringIdQI),1}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdID),-1,GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR, g_nStringIdID),0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR,g_nStringIdSTATUS), 0, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdSTATUS),-1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR,g_nStringIdQO), 0,GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdQO),-1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR,g_nStringIdRD_2),0,GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR, g_nStringIdRQST),1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR,g_nStringIdQO),1,GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR, g_nStringIdQI),0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR,g_nStringIdRESP),1,GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR, g_nStringIdSD_1),0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSVR,g_nStringIdRD_1),0,GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdMGR, g_nStringIdDST),1} +}; + +const SCFB_FBNData DM_KRNL::scm_stFBNData = { + 2, + scm_astInternalFBs, + 5, + scm_astEventConnections, + 0, + 0, + 8, + scm_astDataConnections, + 0, + 0, + 0, + 0 +}; + +DM_KRNL::~DM_KRNL(){ +} + + + diff --git a/src/stdfblib/ita/DM_KRNL.h b/src/stdfblib/ita/DM_KRNL.h new file mode 100644 index 000000000..9a54a2732 --- /dev/null +++ b/src/stdfblib/ita/DM_KRNL.h @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Gerhard Ebenhofer, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _DM_KRNL_H_ +#define _DM_KRNL_H_ + +#include +#include +#include + +class DM_KRNL: public CCompositeFB{ + DECLARE_FIRMWARE_FB(DM_KRNL) + +private: + static const CStringDictionary::TStringId scm_aunDataInputNameIds[]; + static const CStringDictionary::TStringId scm_aunDataOutputNameIds[]; + static const CStringDictionary::TStringId scm_aunDataTypeIds[]; + + static const TEventID scm_nEventINITID = 0; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_aunEventInputNameIds[]; + + static const TEventID scm_nEventINITOID = 0; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_aunEventOutputNameIds[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(1,2,2, 0); + + static const SCFB_FBInstanceData scm_astInternalFBs[]; + static const SCFB_FBConnectionData scm_astEventConnections[]; + static const SCFB_FBConnectionData scm_astDataConnections[]; + static const SCFB_FBNData scm_stFBNData; + + + +public: + COMPOSITE_FUNCTION_BLOCK_CTOR(DM_KRNL){}; + virtual ~DM_KRNL(); + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/ita/EMB_RES.cpp b/src/stdfblib/ita/EMB_RES.cpp new file mode 100644 index 000000000..ed4d5dae6 --- /dev/null +++ b/src/stdfblib/ita/EMB_RES.cpp @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Gerhard Ebenhofer, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "EMB_RES.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "EMB_RES_gen.cpp" +#endif + + +DEFINE_FIRMWARE_FB(EMB_RES, g_nStringIdEMB_RES) +; + +EMB_RES::EMB_RES(CStringDictionary::TStringId pa_nInstanceNameId, + CResource* pa_poDevice) : + CResource(pa_poDevice, 0, pa_nInstanceNameId, 0, 0){ + + addFB(CTypeLib::createFB(g_nStringIdSTART, g_nStringIdE_RESTART, this)); +} + +EMB_RES::~EMB_RES(){ +} + diff --git a/src/stdfblib/ita/EMB_RES.h b/src/stdfblib/ita/EMB_RES.h new file mode 100644 index 000000000..d5aea3589 --- /dev/null +++ b/src/stdfblib/ita/EMB_RES.h @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EMB_RES_H_ +#define _EMB_RES_H_ + +#include + + +class EMB_RES : public CResource{ + DECLARE_FIRMWARE_FB(EMB_RES); + + public: + EMB_RES(CStringDictionary::TStringId pa_nInstanceNameId, + CResource* pa_poDevice); + virtual ~EMB_RES(); + + private: +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/src/stdfblib/ita/EMB_RMT_DEV.cpp b/src/stdfblib/ita/EMB_RMT_DEV.cpp new file mode 100644 index 000000000..3eb83c7fe --- /dev/null +++ b/src/stdfblib/ita/EMB_RMT_DEV.cpp @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EMB_RMT_DEV.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "EMB_RMT_DEV_gen.cpp" +#endif +#include + +const SFBInterfaceSpec EMB_RMT_DEV::scm_stFBInterfaceSpec = { 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, + 0}; + +EMB_RMT_DEV::EMB_RMT_DEV(const char * pa_acId) : + CDevice(&scm_stFBInterfaceSpec, CStringDictionary::scm_nInvalidStringId, 0, 0), + MGR(g_nStringIdMGR, this, pa_acId){ + + //Perform reset command normally done by the typelib during the creation process + changeFBExecutionState(cg_nMGM_CMD_Reset); +} + +EMB_RMT_DEV::~EMB_RMT_DEV(){ +} + +int EMB_RMT_DEV::startDevice(void){ + CDevice::startDevice(); + MGR.changeFBExecutionState(cg_nMGM_CMD_Start); + return 0; +} + +EMGMResponse EMB_RMT_DEV::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse eRetVal = CDevice::changeFBExecutionState(pa_unCommand); + if((e_RDY == eRetVal) && (cg_nMGM_CMD_Kill == pa_unCommand)){ + MGR.changeFBExecutionState(cg_nMGM_CMD_Kill); + } + return eRetVal; +} diff --git a/src/stdfblib/ita/EMB_RMT_DEV.h b/src/stdfblib/ita/EMB_RMT_DEV.h new file mode 100644 index 000000000..b38175140 --- /dev/null +++ b/src/stdfblib/ita/EMB_RMT_DEV.h @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2013, 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _LMS_DEV_H_ +#define _LMS_DEV_H_ + +#include +#include "EMB_RMT_RES.h" + +class EMB_RMT_DEV : public CDevice{ + + +public: + EMB_RMT_RES MGR; + + EMB_RMT_DEV(const char * pa_acId); + virtual ~EMB_RMT_DEV(); + +/*! \brief Adds additional functionality to the originals execute func of the device. + * + * This is that it waits till the thread of the MGR resource has anded + */ + virtual int startDevice(void); + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); + +private: + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + +}; + +#endif /*EMB_RMT_DEV_H_*/ diff --git a/src/stdfblib/ita/EMB_RMT_RES.cpp b/src/stdfblib/ita/EMB_RMT_RES.cpp new file mode 100644 index 000000000..810523d42 --- /dev/null +++ b/src/stdfblib/ita/EMB_RMT_RES.cpp @@ -0,0 +1,164 @@ +/******************************************************************************* + * Copyright (c) 2013, 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "EMB_RMT_RES.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "EMB_RMT_RES_gen.cpp" +#endif +#include "../events/E_RESTART.h" +#include "../ita/DEV_MGR.h" +#include "../events/E_SR.h" +#include + + +//DEFINE_FIRMWARE_FB(EMB_RMT_RES, g_nStringIdEMB_RMT_RES); + +const SFBInterfaceSpec EMB_RMT_RES::scm_stRESInterfaceSpec = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 +}; + +//const char * const EMB_RMT_RES::scm_acId = "fbdk[].ip[localhost:61499]"; + +EMB_RMT_RES::EMB_RMT_RES(const CStringDictionary::TStringId pa_nInstanceNameId, CResource* pa_poDevice, const char * pa_acId): + CResource(pa_poDevice, &scm_stRESInterfaceSpec, pa_nInstanceNameId, 0, 0){ + + addFB(CTypeLib::createFB(g_nStringIdSTART, g_nStringIdE_RESTART, this)); + addFB(CTypeLib::createFB(g_nStringIdMGR_FF, g_nStringIdE_SR, this)); + CFunctionBlock *poFB = CTypeLib::createFB(g_nStringIdSVR, g_nStringIdSERVER_1_2, this); + addFB(poFB); + static_cast(poFB)->ID() = pa_acId; + + addFB(CTypeLib::createFB(g_nStringIdMGR, g_nStringIdDEV_MGR, this)); + + forte::core::SManagementCMD command; + + command.mFirstParam.pushBack(g_nStringIdSTART); + command.mFirstParam.pushBack(g_nStringIdCOLD); + command.mSecondParam.pushBack(g_nStringIdMGR_FF); + command.mSecondParam.pushBack(g_nStringIdS); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSTART); + command.mFirstParam.pushBack(g_nStringIdwARM); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR_FF); + command.mSecondParam.pushBack(g_nStringIdS); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSTART); + command.mFirstParam.pushBack(g_nStringIdSTOP); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR_FF); + command.mSecondParam.pushBack(g_nStringIdR); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdMGR_FF); + command.mFirstParam.pushBack(g_nStringIdEO); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdSVR); + command.mSecondParam.pushBack(g_nStringIdINIT); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSVR); + command.mFirstParam.pushBack(g_nStringIdINITO); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR); + command.mSecondParam.pushBack(g_nStringIdINIT); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSVR); + command.mFirstParam.pushBack(g_nStringIdIND); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR); + command.mSecondParam.pushBack(g_nStringIdREQ); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdMGR); + command.mFirstParam.pushBack(g_nStringIdCNF); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdSVR); + command.mSecondParam.pushBack(g_nStringIdRSP); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdMGR_FF); + command.mFirstParam.pushBack(g_nStringIdQ); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdSVR); + command.mSecondParam.pushBack(g_nStringIdQI); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSVR); + command.mFirstParam.pushBack(g_nStringIdQO); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR); + command.mSecondParam.pushBack(g_nStringIdQI); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSVR); + command.mFirstParam.pushBack(g_nStringIdRD_1); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR); + command.mSecondParam.pushBack(g_nStringIdDST); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSVR); + command.mFirstParam.pushBack(g_nStringIdRD_2); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR); + command.mSecondParam.pushBack(g_nStringIdRQST); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdMGR); + command.mFirstParam.pushBack(g_nStringIdRESP); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdSVR); + command.mSecondParam.pushBack(g_nStringIdSD_1); + createConnection(command); + + //Perform reset command normally done by the typelib during the creation process + changeFBExecutionState(cg_nMGM_CMD_Reset); +} + +EMB_RMT_RES::~EMB_RMT_RES(){ +} + +CStringDictionary::TStringId EMB_RMT_RES::getFBTypeId(void) const { + return g_nStringIdEMB_RMT_RES; +} + + + diff --git a/src/stdfblib/ita/EMB_RMT_RES.h b/src/stdfblib/ita/EMB_RMT_RES.h new file mode 100644 index 000000000..3407daaeb --- /dev/null +++ b/src/stdfblib/ita/EMB_RMT_RES.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2013, 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _EMB_RMT_RES_H_ +#define _EMB_RMT_RES_H_ + +#include + +class EMB_RMT_RES : public CResource{ + //DECLARE_FIRMWARE_FB(EMB_RMT_RES) + + public: + EMB_RMT_RES(CStringDictionary::TStringId pa_nInstanceNameId, CResource* pa_roDevice, const char * pa_acId); + + virtual ~EMB_RMT_RES(); + + virtual CStringDictionary::TStringId getFBTypeId(void) const; + + private: + static const SFBInterfaceSpec scm_stRESInterfaceSpec; +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/ita/RMT_DEV.cpp b/src/stdfblib/ita/RMT_DEV.cpp new file mode 100644 index 000000000..7b171263d --- /dev/null +++ b/src/stdfblib/ita/RMT_DEV.cpp @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Rene Smodic, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RMT_DEV.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RMT_DEV_gen.cpp" +#endif +#include + +const CStringDictionary::TStringId RMT_DEV::scm_aunDINameIds[] = { g_nStringIdMGR_ID }; +const CStringDictionary::TStringId RMT_DEV::scm_aunDIDataTypeIds[] = {g_nStringIdWSTRING}; + +const SFBInterfaceSpec RMT_DEV::scm_stFBInterfaceSpec = { 0, 0, 0, 0, 0, 0, 0, + 0, 1, scm_aunDINameIds, scm_aunDIDataTypeIds, 0, 0, 0, + 0, + 0}; + +RMT_DEV::RMT_DEV() : + CDevice(&scm_stFBInterfaceSpec, CStringDictionary::scm_nInvalidStringId, m_anFBConnData, m_anFBVarsData), + MGR(g_nStringIdMGR, this){ + + MGR_ID().fromString("localhost:61499"); + + //we nee to manually crate this interface2internal connection as the MGR is not managed by device + m_oDConnMGR_ID.setSource(this, 0); + m_oDConnMGR_ID.connect(&MGR, g_nStringIdMGR_ID); + + //Perform reset command normally done by the typelib during the creation process + changeFBExecutionState(cg_nMGM_CMD_Reset); +} + +RMT_DEV::~RMT_DEV(){ +} + +int RMT_DEV::startDevice(void){ + CDevice::startDevice(); + MGR.changeFBExecutionState(cg_nMGM_CMD_Start); + return 0; +} + +EMGMResponse RMT_DEV::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse eRetVal = CDevice::changeFBExecutionState(pa_unCommand); + if((e_RDY == eRetVal) && (cg_nMGM_CMD_Kill == pa_unCommand)){ + MGR.changeFBExecutionState(cg_nMGM_CMD_Kill); + } + return eRetVal; +} + +void RMT_DEV::setMGR_ID(const char * const pa_acConn){ + MGR_ID().fromString(pa_acConn); +} diff --git a/src/stdfblib/ita/RMT_DEV.h b/src/stdfblib/ita/RMT_DEV.h new file mode 100644 index 000000000..e2077345a --- /dev/null +++ b/src/stdfblib/ita/RMT_DEV.h @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Gerhard Ebenhofer, Rene Smodic, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RMT_DEV_H_ +#define _RMT_DEV_H_ + +#include +#include +#include +#include "RMT_RES.h" + +/*! \brief Implementation of the RMT_DEV. + */ + + +class RMT_DEV : public CDevice{ + + +public: + RMT_RES MGR; + + RMT_DEV(); + virtual ~RMT_DEV(); + +/*! \brief Adds additional functionality to the originals execute func of the device. + * + * This is that it waits till the thread of the MGR resource has anded + */ + virtual int startDevice(void); + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); + + void setMGR_ID(const char * const pa_acConn); + +private: + CInterface2InternalDataConnection m_oDConnMGR_ID; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(0,1,0, 0); + + static const CStringDictionary::TStringId scm_aunDINameIds[]; + static const CStringDictionary::TStringId scm_aunDIDataTypeIds[]; + + CIEC_WSTRING& MGR_ID() { + return *static_cast(getDI(0)); + } +}; + +#endif /*RMT_DEV_H_*/ diff --git a/src/stdfblib/ita/RMT_RES.cpp b/src/stdfblib/ita/RMT_RES.cpp new file mode 100644 index 000000000..ca597bff2 --- /dev/null +++ b/src/stdfblib/ita/RMT_RES.cpp @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2015 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Rene Smodic, Thomas Strasser, + * Martin Melik Merkumians, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "RMT_RES.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "RMT_RES_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(RMT_RES, g_nStringIdRMT_RES); + +const CStringDictionary::TStringId RMT_RES::scm_aunVarInputNameIds[] = {g_nStringIdMGR_ID}; +const CStringDictionary::TStringId RMT_RES::scm_aunDIDataTypeIds[] = {g_nStringIdWSTRING}; + + +const SFBInterfaceSpec RMT_RES::scm_stRESInterfaceSpec = { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + scm_aunVarInputNameIds, + scm_aunDIDataTypeIds, + 0, + 0, + 0, + 0, + 0 + }; + + +RMT_RES::RMT_RES(CStringDictionary::TStringId pa_nInstanceNameId, CResource* pa_poDevice): + CResource(pa_poDevice, &scm_stRESInterfaceSpec, pa_nInstanceNameId, m_anFBConnData, m_anFBVarsData){ + addFB(CTypeLib::createFB(g_nStringIdSTART, g_nStringIdE_RESTART, this)); + addFB(CTypeLib::createFB(g_nStringIdMGR_FF, g_nStringIdE_SR, this)); + addFB(CTypeLib::createFB(g_nStringIdKERNEL, g_nStringIdDM_KRNL, this)); + + forte::core::SManagementCMD command; + + command.mFirstParam.pushBack(g_nStringIdSTART); + command.mFirstParam.pushBack(g_nStringIdCOLD); + command.mSecondParam.pushBack(g_nStringIdMGR_FF); + command.mSecondParam.pushBack(g_nStringIdS); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSTART); + command.mFirstParam.pushBack(g_nStringIdWARM); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR_FF); + command.mSecondParam.pushBack(g_nStringIdS); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdSTART); + command.mFirstParam.pushBack(g_nStringIdSTOP); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdMGR_FF); + command.mSecondParam.pushBack(g_nStringIdR); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdMGR_FF); + command.mFirstParam.pushBack(g_nStringIdEO); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdKERNEL); + command.mSecondParam.pushBack(g_nStringIdINIT); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdMGR_FF); + command.mFirstParam.pushBack(g_nStringIdQ); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdKERNEL); + command.mSecondParam.pushBack(g_nStringIdQI); + createConnection(command); + + command.mFirstParam.clear(); + command.mFirstParam.pushBack(g_nStringIdMGR_ID); + command.mSecondParam.clear(); + command.mSecondParam.pushBack(g_nStringIdKERNEL); + command.mSecondParam.pushBack(g_nStringIdID); + createConnection(command); + + //Perform reset command normally done by the typelib during the creation process + changeFBExecutionState(cg_nMGM_CMD_Reset); +} + +RMT_RES::~RMT_RES(){ +} + + + diff --git a/src/stdfblib/ita/RMT_RES.h b/src/stdfblib/ita/RMT_RES.h new file mode 100644 index 000000000..4a14214d9 --- /dev/null +++ b/src/stdfblib/ita/RMT_RES.h @@ -0,0 +1,35 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gerhard Ebenhofer, Thomas Strasser, + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _RMT_RES_H_ +#define _RMT_RES_H_ + +#include +#include + +class RMT_RES : public CResource{ + DECLARE_FIRMWARE_FB(RMT_RES) + + public: + RMT_RES(CStringDictionary::TStringId pa_nInstanceNameId, CResource* pa_roDevice); + virtual ~RMT_RES(); + + private: + static const SFBInterfaceSpec scm_stRESInterfaceSpec; + + FORTE_FB_DATA_ARRAY(0,1,0, 0); + + static const CStringDictionary::TStringId scm_aunVarInputNameIds[]; + static const CStringDictionary::TStringId scm_aunDIDataTypeIds[]; + +}; + +#endif //close the ifdef sequence from the beginning of the file diff --git a/src/stdfblib/ita/SERVER_1_2.cpp b/src/stdfblib/ita/SERVER_1_2.cpp new file mode 100644 index 000000000..733611595 --- /dev/null +++ b/src/stdfblib/ita/SERVER_1_2.cpp @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "SERVER_1_2.h" + +DEFINE_FIRMWARE_FB(SERVER_1_2, g_nStringIdSERVER_1_2) + +const CStringDictionary::TStringId SERVER_1_2::scm_anDataInputNames[] = {g_nStringIdQI, g_nStringIdID, g_nStringIdSD_1}; + +const CStringDictionary::TStringId SERVER_1_2::scm_anDataOutputNames[] = {g_nStringIdQO, g_nStringIdSTATUS, g_nStringIdRD_1, g_nStringIdRD_2}; +const CStringDictionary::TStringId SERVER_1_2::scm_aunDIDataTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdANY}; +const CStringDictionary::TStringId SERVER_1_2::scm_aunDODataTypeIds[] = {g_nStringIdBOOL, g_nStringIdSTRING, g_nStringIdANY, g_nStringIdANY}; + +const TForteInt16 SERVER_1_2::scm_anEIWithIndexes[] = {0, 3}; +const TDataIOID SERVER_1_2::scm_anEIWith[] = {0, 1, 255, 0, 2, 3, 255}; +const CStringDictionary::TStringId SERVER_1_2::scm_anEventInputNames[] = {g_nStringIdINIT, g_nStringIdRSP}; + +const TDataIOID SERVER_1_2::scm_anEOWith[] = {0, 1, 255, 0, 1, 2, 3, 255}; +const TForteInt16 SERVER_1_2::scm_anEOWithIndexes[] = {0, 3}; +const CStringDictionary::TStringId SERVER_1_2::scm_anEventOutputNames[] = {g_nStringIdINITO, g_nStringIdIND}; + +const SFBInterfaceSpec SERVER_1_2::scm_stFBInterfaceSpec = { + 2, + scm_anEventInputNames, + scm_anEIWith, + scm_anEIWithIndexes, + 2, + scm_anEventOutputNames, + scm_anEOWith, + scm_anEOWithIndexes, + 3, + scm_anDataInputNames, scm_aunDIDataTypeIds, + 4, + scm_anDataOutputNames, scm_aunDODataTypeIds, + 0, + 0 +}; + + +SERVER_1_2::SERVER_1_2(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + CCommFB(pa_nInstanceNameId, pa_poSrcRes, &scm_stFBInterfaceSpec, m_anFBConnData, m_anFBVarsData, forte::com_infra::e_Server){ +} + +SERVER_1_2::~SERVER_1_2(){ + +} + diff --git a/src/stdfblib/ita/SERVER_1_2.h b/src/stdfblib/ita/SERVER_1_2.h new file mode 100644 index 000000000..22695b5e8 --- /dev/null +++ b/src/stdfblib/ita/SERVER_1_2.h @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2012, 2013 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef SERVER_1_2_H_ +#define SERVER_1_2_H_ + +#include "commfb.h" + +/*!\brief implementation of server_1_2 block with static interface which is more + * memory efficient on small platforms like LMS + */ + +class SERVER_1_2 : public forte::com_infra::CCommFB{ + DECLARE_FIRMWARE_FB(SERVER_1_2) + + public: + SERVER_1_2(CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~SERVER_1_2(); + + CIEC_BOOL& QI(){ + return *static_cast(getDI(0)); + } + + CIEC_STRING& ID(){ + return *static_cast(getDI(2)); + } + + CIEC_STRING& SD_1(){ + return *static_cast(getDI(2)); + } + + CIEC_BOOL& QO(){ + return *static_cast(getDO(0)); + } + + + CIEC_STRING& RD_1(){ + return *static_cast(getDO(2)); + } + CIEC_STRING& RD_2(){ + return *static_cast(getDO(3)); + } + + private: + static const CStringDictionary::TStringId scm_anDataInputNames[], scm_aunDIDataTypeIds[]; + static const CStringDictionary::TStringId scm_anDataOutputNames[], scm_aunDODataTypeIds[]; + static const TEventID scm_nEventINITID = 0; + static const TEventID scm_nEventRSPID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventINITOID = 0; + static const TEventID scm_nEventINDID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 3, 4, 0) + ; + +}; + +#endif /* SERVER_1_2_H_ */ diff --git a/src/stdfblib/net/CMakeLists.txt b/src/stdfblib/net/CMakeLists.txt new file mode 100644 index 000000000..b758c0678 --- /dev/null +++ b/src/stdfblib/net/CMakeLists.txt @@ -0,0 +1,21 @@ +#******************************************************************************* +# * Copyright (c) 2010 - 2012 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl +# * - initial API and implementation and/or initial documentation +# *******************************************************************************/ +############################################################################# +# Net FB +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +SET(SOURCE_GROUP ${SOURCE_GROUP}\\net) +forte_add_sourcefile_hcpp(GEN_CLIENT GEN_PUBLISH GEN_SERVER GEN_SUBSCRIBE) + +if (FORTE_COM_LOCAL) + forte_add_sourcefile_hcpp(GEN_PUBL GEN_SUBL) +endif(FORTE_COM_LOCAL) diff --git a/src/stdfblib/net/GEN_CLIENT.cpp b/src/stdfblib/net/GEN_CLIENT.cpp new file mode 100644 index 000000000..7909b0197 --- /dev/null +++ b/src/stdfblib/net/GEN_CLIENT.cpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Gerhard Ebenhofer, Ingo Hegny, + * Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_CLIENT.h" + +DEFINE_GENERIC_FIRMWARE_FB(GEN_CLIENT, g_nStringIdGEN_CLIENT) + +GEN_CLIENT::GEN_CLIENT(const CStringDictionary::TStringId pa_nInstanceNameId, + CResource *pa_poSrcRes): + forte::com_infra::CCommFB(pa_nInstanceNameId, pa_poSrcRes, forte::com_infra::e_Client){ + //CCommFB(pa_nInstanceNameId, pa_poSrcRes, true, scm_nSendBufferSize, scm_nRecvBufferSize, CCommFB::e_Client){ +} diff --git a/src/stdfblib/net/GEN_CLIENT.h b/src/stdfblib/net/GEN_CLIENT.h new file mode 100644 index 000000000..181a4bc46 --- /dev/null +++ b/src/stdfblib/net/GEN_CLIENT.h @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Gerhard Ebenhofer, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_CLIENT_H_ +#define _GEN_CLIENT_H_ + +#include "../../core/cominfra/commfb.h" + +/*! \brief Implementation of the CLIENT_* SIFB. + * + */ + +class GEN_CLIENT : public forte::com_infra::CCommFB { + DECLARE_GENERIC_FIRMWARE_FB(GEN_CLIENT) + +public: + GEN_CLIENT(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_CLIENT(){}; + +}; + +#endif //_GEN_CLIENT_H_ diff --git a/src/stdfblib/net/GEN_PUBL.cpp b/src/stdfblib/net/GEN_PUBL.cpp new file mode 100644 index 000000000..2878060c7 --- /dev/null +++ b/src/stdfblib/net/GEN_PUBL.cpp @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Rene Smodic, Ingo Hegny, + * Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_PUBL.h" + +DEFINE_GENERIC_FIRMWARE_FB(GEN_PUBL, g_nStringIdGEN_PUBL) + +GEN_PUBL::GEN_PUBL(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes): + GEN_PUBLISH( pa_nInstanceNameId, pa_poSrcRes) { +} + +bool GEN_PUBL::configureFB(const char *pa_acConfigString){ + bool bRetVal = GEN_PUBLISH::configureFB(pa_acConfigString); + //publs normally don't show the QI in the tool + QI() = true; + return bRetVal; +} + + diff --git a/src/stdfblib/net/GEN_PUBL.h b/src/stdfblib/net/GEN_PUBL.h new file mode 100644 index 000000000..06f451663 --- /dev/null +++ b/src/stdfblib/net/GEN_PUBL.h @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Gerhard Ebenhofer, Ingo Hegny, + * Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef GEN_PUBL_H_ +#define GEN_PUBL_H_ + +#include "GEN_PUBLISH.h" +#include + +/*! \brief Implementation of the PUBL SIFB. + * + */ + +class GEN_PUBL : public GEN_PUBLISH{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_PUBL) + public: + GEN_PUBL(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + virtual bool configureFB(const char *pa_acConfigString); + + private: + + virtual char * getDefaultIDString(){ + return forte::com_infra::CLocalComLayer::getDefaultLocalCommIdString(ID().getValue()); + }; +}; + +#endif /*GEN_PUBL_H_*/ diff --git a/src/stdfblib/net/GEN_PUBLISH.cpp b/src/stdfblib/net/GEN_PUBLISH.cpp new file mode 100644 index 000000000..08bd52fe3 --- /dev/null +++ b/src/stdfblib/net/GEN_PUBLISH.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, THomas Strasser, Gerhard Ebenhofer, Ingo Hegny, + * Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_PUBLISH.h" + +DEFINE_GENERIC_FIRMWARE_FB(GEN_PUBLISH, g_nStringIdGEN_PUBLISH) + +GEN_PUBLISH::GEN_PUBLISH(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes): +forte::com_infra::CCommFB( pa_nInstanceNameId, pa_poSrcRes, forte::com_infra::e_Publisher){ + //CNetCommFB( pa_nInstanceNameId, pa_poSrcRes, true, scm_nSendBufferSize, 0, CCommFB::e_Publisher){ +} diff --git a/src/stdfblib/net/GEN_PUBLISH.h b/src/stdfblib/net/GEN_PUBLISH.h new file mode 100644 index 000000000..169f07e98 --- /dev/null +++ b/src/stdfblib/net/GEN_PUBLISH.h @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Rene Smodic, Gerhard Ebenhofer, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_PUBLISH_H_ +#define _GEN_PUBLISH_H_ + +#include "../../core/cominfra/commfb.h" + +/*! \brief Implementation of the PUBLISH SIFB. + */ + +class GEN_PUBLISH : public forte::com_infra::CCommFB { +DECLARE_GENERIC_FIRMWARE_FB(GEN_PUBLISH) + +public: + GEN_PUBLISH(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_PUBLISH(){}; +}; + +#endif //_GEN_PUBLISH_H_ + + diff --git a/src/stdfblib/net/GEN_SERVER.cpp b/src/stdfblib/net/GEN_SERVER.cpp new file mode 100644 index 000000000..abc0d669c --- /dev/null +++ b/src/stdfblib/net/GEN_SERVER.cpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, THomas Strasser, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_SERVER.h" + +DEFINE_GENERIC_FIRMWARE_FB(GEN_SERVER, g_nStringIdGEN_SERVER) + +GEN_SERVER::GEN_SERVER(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes) : + forte::com_infra::CCommFB(pa_nInstanceNameId, pa_poSrcRes, forte::com_infra::e_Server){ + + //CNetCommFB( pa_nInstanceNameId, pa_poSrcRes, false, scm_nSendBufferSize, scm_nRecvBufferSize, CCommFB::e_Server) { +} diff --git a/src/stdfblib/net/GEN_SERVER.h b/src/stdfblib/net/GEN_SERVER.h new file mode 100644 index 000000000..54eff4e62 --- /dev/null +++ b/src/stdfblib/net/GEN_SERVER.h @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_SERVER_H_ +#define _GEN_SERVER_H_ + +#include "../../core/cominfra/commfb.h" + +/*! \brief Implementation of the SERVER_* SIFB. + * + */ + +class GEN_SERVER: public forte::com_infra::CCommFB { + DECLARE_GENERIC_FIRMWARE_FB(GEN_SERVER) + public: + GEN_SERVER(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_SERVER(){}; + +}; + +#endif //_GEN_SERVER_H_ diff --git a/src/stdfblib/net/GEN_SUBL.cpp b/src/stdfblib/net/GEN_SUBL.cpp new file mode 100644 index 000000000..a52b70359 --- /dev/null +++ b/src/stdfblib/net/GEN_SUBL.cpp @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Thomas Strasser, Alois Zoitl, Gerhard Ebenhofer, + * Ingo Hegny, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_SUBL.h" + +DEFINE_GENERIC_FIRMWARE_FB(GEN_SUBL, g_nStringIdGEN_SUBL) + + +GEN_SUBL::GEN_SUBL(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes): + GEN_SUBSCRIBE( pa_nInstanceNameId, pa_poSrcRes){ +} + +bool GEN_SUBL::configureFB(const char *pa_acConfigString){ + bool bRetVal = GEN_SUBSCRIBE::configureFB(pa_acConfigString); + //subls normally don't show the QI in the tool + QI() = true; + return bRetVal; +} + diff --git a/src/stdfblib/net/GEN_SUBL.h b/src/stdfblib/net/GEN_SUBL.h new file mode 100644 index 000000000..d23c51f35 --- /dev/null +++ b/src/stdfblib/net/GEN_SUBL.h @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Alois Zoitl, Gerhard Ebenhofer, Ingo Hegny, + * Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef GEN_SUBL_H_ +#define GEN_SUBL_H_ + +#include "GEN_SUBSCRIBE.h" +#include + +/*! \brief Implementation of the SUBL SIFB. + * + */ + +class GEN_SUBL : public GEN_SUBSCRIBE{ + DECLARE_GENERIC_FIRMWARE_FB(GEN_SUBL) + public: + GEN_SUBL(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + + virtual bool configureFB(const char *pa_acConfigString); + + private: + virtual char * getDefaultIDString(){ + return forte::com_infra::CLocalComLayer::getDefaultLocalCommIdString(ID().getValue()); + } + ; +}; + +#endif /*GEN_SUBL_H_*/ diff --git a/src/stdfblib/net/GEN_SUBSCRIBE.cpp b/src/stdfblib/net/GEN_SUBSCRIBE.cpp new file mode 100644 index 000000000..05ad48cf5 --- /dev/null +++ b/src/stdfblib/net/GEN_SUBSCRIBE.cpp @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, THomas Strasser, Alois Zoitl, Gerhard Ebenhofer, + * Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "GEN_SUBSCRIBE.h" + +DEFINE_GENERIC_FIRMWARE_FB(GEN_SUBSCRIBE, g_nStringIdGEN_SUBSCRIBE) + +GEN_SUBSCRIBE::GEN_SUBSCRIBE(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes): +forte::com_infra::CCommFB( pa_nInstanceNameId, pa_poSrcRes, forte::com_infra::e_Subscriber){ +//CNetCommFB( pa_nInstanceNameId, pa_poSrcRes, false, 0, scm_nRecvBufferSize, CCommFB::e_Subscriber){ +} + diff --git a/src/stdfblib/net/GEN_SUBSCRIBE.h b/src/stdfblib/net/GEN_SUBSCRIBE.h new file mode 100644 index 000000000..11738bbf2 --- /dev/null +++ b/src/stdfblib/net/GEN_SUBSCRIBE.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2006 - 2011 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Rene Smodic, Alois Zoitl, Gerhard Ebenhofer, Martin Melik Merkumians + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _GEN_SUBSCRIBE_H_ +#define _GEN_SUBSCRIBE_H_ + +#include "../../core/cominfra/commfb.h" + +/*! \brief Implementation of the SUBSCRIBER SIFB. + */ + + +class GEN_SUBSCRIBE : public forte::com_infra::CCommFB { + DECLARE_GENERIC_FIRMWARE_FB(GEN_SUBSCRIBE) + + public: + GEN_SUBSCRIBE(const CStringDictionary::TStringId pa_nInstanceNameId, CResource *pa_poSrcRes); + virtual ~GEN_SUBSCRIBE(){}; + +}; + +#endif //_GEN_SUBSCRIBE_H_ + diff --git a/src/stdfblib/timedfb.cpp b/src/stdfblib/timedfb.cpp new file mode 100644 index 000000000..f3ecf3ca0 --- /dev/null +++ b/src/stdfblib/timedfb.cpp @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2013 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Gunnar Grabmair, Ingo Hegny, GErhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "timedfb.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "timedfb_gen.cpp" +#endif + +const CStringDictionary::TStringId CTimedFB::scm_aunEINameIds[] = {g_nStringIdSTART, g_nStringIdSTOP}; +const TDataIOID CTimedFB::scm_anEIWith[] = {0, 255}; +const TForteInt16 CTimedFB::scm_anEIWithIndexes[] = {0, -1}; +const CStringDictionary::TStringId CTimedFB::scm_aunEONameIds[] = {g_nStringIdEO}; + +const CStringDictionary::TStringId CTimedFB::scm_aunDINameIds[] = {g_nStringIdDT}; +const CStringDictionary::TStringId CTimedFB::scm_aunDIDataTypeNameIds[] = {g_nStringIdTIME}; + +const SFBInterfaceSpec CTimedFB::scm_stFBInterfaceSpec = { + 2, + scm_aunEINameIds, + scm_anEIWith, + scm_anEIWithIndexes, + 1, + scm_aunEONameIds, + 0, + 0, + 1, + scm_aunDINameIds, + scm_aunDIDataTypeNameIds, + 0, + 0, + 0, + 0, + 0 +}; + + +void CTimedFB::executeEvent(int pa_nEIID){ + switch(pa_nEIID){ + case cg_nExternalEventID: + sendOutputEvent(csm_nEOID); + break; + case csm_nEventSTOPID: + if(m_bActive){ + CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); + m_bActive = false; + } + break; + case csm_nEventSTARTID: + if(!m_bActive){ + CTimerHandler::sm_poFORTETimer->registerTimedFB( &m_stTimeListEntry, DT()); + m_bActive = true; + } + break; + default: + break; + } +} + +EMGMResponse CTimedFB::changeFBExecutionState(EMGMCommandType pa_unCommand){ + EMGMResponse eRetVal = CFunctionBlock::changeFBExecutionState(pa_unCommand); + if((e_RDY == eRetVal) && + ((cg_nMGM_CMD_Stop == pa_unCommand) || (cg_nMGM_CMD_Kill == pa_unCommand))){ + if(m_bActive){ + CTimerHandler::sm_poFORTETimer->unregisterTimedFB(this); + m_bActive = false; + } + } + return eRetVal; +} diff --git a/src/stdfblib/timedfb.h b/src/stdfblib/timedfb.h new file mode 100644 index 000000000..3c4b3602f --- /dev/null +++ b/src/stdfblib/timedfb.h @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2005 - 2014 ACIN, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Thomas Strasser, Gunnar Grabmair, Martin Melik Merkumians, + * Ingo Hegny, Gerhard Ebenhofer + * - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _TIMEDFB_H_ +#define _TIMEDFB_H_ + +#include "../core/esfb.h" +#include "../core/datatypes/forte_time.h" +#include "../arch/timerha.h" +#include "../core/resource.h" + +/*!\brief Base class for timed function block like E_CYCLE or E_DELAY providing this interface + */ +class CTimedFB : public CEventSourceFB{ +private: +protected: + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + static const CStringDictionary::TStringId scm_aunEINameIds[]; + static const TDataIOID scm_anEIWith[]; + static const TForteInt16 scm_anEIWithIndexes[]; + static const CStringDictionary::TStringId scm_aunEONameIds[]; + static const TForteInt16 scm_anEOWithIndexes[]; + static const CStringDictionary::TStringId scm_aunDINameIds[]; + static const CStringDictionary::TStringId scm_aunDIDataTypeNameIds[]; + + static const TEventID csm_nEventSTARTID = 0; + static const TEventID csm_nEventSTOPID = 1; + + static const TEventID csm_nEOID = 0; + + FORTE_FB_DATA_ARRAY(1,1,0, 0); + + bool m_bActive; //!> flag to indicate that the timed fb is currently active + STimedFBListEntry m_stTimeListEntry; //!> The Timer list entry of this timed FB +/*!\brief execute the input events of timed FBs as far it is possible + * + * Derived Timed FBs only normaly need only the start event es this is different for each timed FB type (e.g. periodic vs. onetimeshot) + */ + virtual void executeEvent(int pa_nEIID); + + CIEC_TIME& DT() { + return *static_cast(getDI(0)); + } +public: + EVENT_SOURCE_FUNCTION_BLOCK_CTOR(CTimedFB){ + setEventChainExecutor(pa_poSrcRes->getResourceEventExecution()); + m_bActive = false; + m_stTimeListEntry.m_stTimeOut.m_nLowerValue = 0; + m_stTimeListEntry.m_stTimeOut.m_nUpperValue = 0; + m_stTimeListEntry.m_nInterval = 0; + m_stTimeListEntry.m_pstNext = 0; + m_stTimeListEntry.m_poTimedFB = this; + }; + virtual ~CTimedFB() {}; + + virtual EMGMResponse changeFBExecutionState(EMGMCommandType pa_unCommand); + +}; + +#endif /*TIMEDFB_H_*/ diff --git a/src/stringlist.cpp.in b/src/stringlist.cpp.in new file mode 100644 index 000000000..9912a2fa6 --- /dev/null +++ b/src/stringlist.cpp.in @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2010 - 2012 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Hofmann, Alois Zoitl, Ingo Hegny + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +//!!!autogenerated code - DO NOT EDIT!!! +#include "stringlist.h" + +${STRINGLIST_CPP} + +#ifdef FORTE_STRING_DICT_FIXED_MEMORY + CStringDictionary::TStringId CStringDictionary::scm_aunIdList[cg_unFORTE_StringDictInitialMaxNrOfStrings] +#else + const CStringDictionary::TStringId CStringDictionary::scm_aunIdList[] +#endif + = {${scm_aunIdList_Str}}; + +#ifdef FORTE_STRING_DICT_FIXED_MEMORY + char CStringDictionary::scm_acConstStringBuf[cg_unFORTE_StringDictInitialStringBufSize] +#else + const char CStringDictionary::scm_acConstStringBuf[] +#endif + = {"${scm_acConstStringBuf_Str}"}; + +${ErrorStringBuf} \ No newline at end of file diff --git a/src/stringlist.h.in b/src/stringlist.h.in new file mode 100644 index 000000000..c56ee23e5 --- /dev/null +++ b/src/stringlist.h.in @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2010, 2012 ACIN, Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Michael Hofmann, Alois Zoitl + * - initial API and implementation and/or initial documentation + *******************************************************************************/ + +//!!!autogenerated code - DO NOT EDIT!!! + +#ifndef STRINGLIST_H_ +#define STRINGLIST_H_ +#include + +${STRINGLIST_H} + +#endif /*STRINGLIST_H_*/ diff --git a/systemtests/CMakeLists.txt b/systemtests/CMakeLists.txt new file mode 100644 index 000000000..699b394e1 --- /dev/null +++ b/systemtests/CMakeLists.txt @@ -0,0 +1,12 @@ + +SET(SOURCE_GROUP ${SOURCE_GROUP}\\systemtests) + +if(FORTE_SYSTEM_TESTS) + +SET(CTEST_OUTPUT_ON_FAILURE TRUE) + +forte_add_test(Test1 forte_test_1.fboot 5) +set_tests_properties (Test1 PROPERTIES WILL_FAIL true) +forte_add_test(Test2 forte_test_2.fboot 5) + +endif(FORTE_SYSTEM_TESTS) \ No newline at end of file diff --git a/systemtests/forte_test_1.fboot b/systemtests/forte_test_1.fboot new file mode 100644 index 000000000..63a021acf --- /dev/null +++ b/systemtests/forte_test_1.fboot @@ -0,0 +1,22 @@ +; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; diff --git a/systemtests/forte_test_2.fboot b/systemtests/forte_test_2.fboot new file mode 100644 index 000000000..238e20de7 --- /dev/null +++ b/systemtests/forte_test_2.fboot @@ -0,0 +1,22 @@ +; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; +EMB_RES; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..49f20ff96 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,239 @@ +#******************************************************************************* +# * Copyright (c) 2011- 201 ACIN, nxtControl, Profactor GmbH, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Ingo Hegny, Alois Zoitl, Stanislav Meduna, Micheal Hofmann, +# * Martin Melik-Merkumians - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +SET(SOURCE_GROUP ${SOURCE_GROUP}\\tests) + + +####################################################################################### +# functions for test generation +####################################################################################### +MACRO(forte_test_add_subdirectory DIRECTORY) + SET(SOURCE_GROUP_BACKUP ${SOURCE_GROUP}) + SET(SOURCE_GROUP ${SOURCE_GROUP}\\${DIRECTORY}) + add_subdirectory(${DIRECTORY}) + SET(SOURCE_GROUP ${SOURCE_GROUP_BACKUP}) +ENDMACRO(forte_test_add_subdirectory) + +FUNCTION(forte_test_add_sourcefile_with_path_cpp) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_TEST_SOURCE_CPP ${ARG}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_TEST_SOURCE_CPP_GROUP ${SOURCE_GROUP}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_test_add_sourcefile_with_path_cpp) + +FUNCTION(forte_test_add_sourcefile_cpp) + FOREACH(ARG ${ARGV}) + forte_test_add_sourcefile_with_path_cpp(${CMAKE_CURRENT_SOURCE_DIR}/${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_test_add_sourcefile_cpp) + +FUNCTION(forte_test_add_link_directories) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_TEST_LINK_DIRECTORIES ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_test_add_link_directories) + +FUNCTION(forte_test_add_inc_directories) + FOREACH(ARG ${ARGV}) + SET_PROPERTY(GLOBAL APPEND PROPERTY FORTE_TEST_INC_DIRECTORIES ${ARG}) + ENDFOREACH(ARG) +ENDFUNCTION(forte_test_add_inc_directories) + +####################################################################################### +# set include directories +####################################################################################### +GET_PROPERTY(INCLUDE_DIRECTORIES GLOBAL PROPERTY FORTE_INCLUDE_DIRECTORIES) + +LIST(APPEND INCLUDE_DIRECTORIES ${FORTE_TESTS_INC_DIRS}) + +####################################################################################### +# set library path +####################################################################################### + GET_PROPERTY(FORTE_TEST_LINK_DIRECTORIES GLOBAL PROPERTY FORTE_LINK_DIRECTORIES) + forte_test_add_link_directories(${FORTE_TESTS_LINK_DIRS}) + + forte_test_add_link_directories(${CMAKE_BINARY_DIR}/src) + + GET_PROPERTY(FORTE_TEST_SOURCE_H GLOBAL PROPERTY FORTE_SOURCE_H) + + SET_PROPERTY(GLOBAL PROPERTY FORTE_TEST_SOURCE_CPP "") + +####################################################################################### +# add subdirectories +####################################################################################### + +forte_test_add_sourcefile_cpp(forte_boost_tester.cpp) + +forte_test_add_subdirectory(core) +forte_test_add_subdirectory(stdfblib) + + +####################################################################################### +# include generated stringlist (initial values for stringdict) +####################################################################################### +SET_SOURCE_FILES_PROPERTIES(${FORTE_BINARY_DIR}/stringlist.cpp PROPERTIES GENERATED TRUE) +forte_test_add_sourcefile_with_path_cpp(${FORTE_BINARY_DIR}/stringlist.cpp) + +####################################################################################### +# update includes +####################################################################################### + +LIST(APPEND INCLUDE_DIRECTORIES ${FORTE_TEST_INC_DIRECTORIES}) + +LIST(LENGTH INCLUDE_DIRECTORIES len) +IF(len GREATER 0) + LIST(REMOVE_DUPLICATES INCLUDE_DIRECTORIES) + LIST(REVERSE INCLUDE_DIRECTORIES) # bugfix, for replaced include files +ENDIF(len GREATER 0) +INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES}) +INCLUDE_DIRECTORIES(./) +INCLUDE_DIRECTORIES(${FORTE_BINARY_DIR}) +INCLUDE_DIRECTORIES(${FORTE_BINARY_DIR}/src_gen) + +####################################################################################### +# Setup Forte-Executeable with all Functionblocks +####################################################################################### + +GET_PROPERTY(SOURCE_H GLOBAL PROPERTY FORTE_TEST_SOURCE_H) +GET_PROPERTY(SOURCE_H_GROUP GLOBAL PROPERTY FORTE_TEST_SOURCE_H_GROUP) +#LIST(APPEND SOURCE_FILES ${SOURCE_H}) +#LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_H_GROUP}) + +GET_PROPERTY(SOURCE_CPP GLOBAL PROPERTY FORTE_TEST_SOURCE_CPP) +GET_PROPERTY(SOURCE_CPP_GROUP_STRUCT GLOBAL PROPERTY FORTE_TEST_SOURCE_CPP_GROUP) +#LIST(APPEND SOURCE_FILES ${SOURCE_CPP}) +#LIST(APPEND SOURCE_FILES_GROUP ${SOURCE_CPP_GROUP_STRUCT}) + + +SET(WRITE_FILE "") +FOREACH(FILE ${SOURCE_CPP} ${SOURCE_H}) + SET(WRITE_FILE "${WRITE_FILE}${FILE}\n") +ENDFOREACH(FILE) +FILE(WRITE ${CMAKE_BINARY_DIR}/file_test_list.txt "${WRITE_FILE}") + +####################################################################################### +# Create Exe File +####################################################################################### +GET_PROPERTY(DEFINITION GLOBAL PROPERTY FORTE_DEFINITION) + +ADD_DEFINITIONS (${DEFINITION}) +if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") +ADD_DEFINITIONS (-DBOOST_TEST_DYN_LINK) +ADD_DEFINITIONS (-g -O0 --coverage -fno-inline -fno-elide-constructors) +endif("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + +if("${FORTE_ARCHITECTURE}" STREQUAL "Win32") +ADD_DEFINITIONS (-DBOOST_TEST_NO_LIB) +ADD_DEFINITIONS (-D_CRT_SECURE_NO_DEPRECATE) +ADD_DEFINITIONS (-D_CRT_NONSTDC_NO_DEPRECATE) +ADD_DEFINITIONS (-D_SCL_SECURE_NO_WARNINGS) +ADD_DEFINITIONS (-D_CRT_SECURE_NO_WARNINGS) +endif("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + +LINK_DIRECTORIES(${FORTE_TEST_LINK_DIRECTORIES}) + +ADD_EXECUTABLE (forte_test ${SOURCE_CPP} ${SOURCE_H}) + +add_dependencies(forte_test forte) + +ADD_DEPENDENCIES (forte_test forte_stringlist_generator) + +SET_TARGET_PROPERTIES(forte_test PROPERTIES LINKER_LANGUAGE CXX) + +get_target_property(existing_link_flags_test forte_test LINK_FLAGS) +if(existing_link_flags_test) + set_property(GLOBAL APPEND PROPERTY FORTE_TEST_LINK_FLAGS ${existing_link_flags_test}) +endif() + +GET_PROPERTY(link_flags_test GLOBAL PROPERTY FORTE_TEST_LINK_FLAGS) + +if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") +remove_definitions (-fno-rtti) +remove_definitions (-fno-exceptions) +add_definitions (-fexceptions) + +set_target_properties(forte_test PROPERTIES LINK_FLAGS "${link_flags_test} --coverage -lpthread") +endif() + +add_test(forte_test ${EXECUTABLE_OUTPUT_PATH}/forte_test) + +if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + set(FORTE_TEST_CODE_COVERAGE_ANALYSIS OFF CACHE BOOL "Perform code coverage analyis with GCOV and presentation with LCOV") + mark_as_advanced(FORTE_TEST_CODE_COVERAGE_ANALYSIS) + if(FORTE_TEST_CODE_COVERAGE_ANALYSIS) + INCLUDE(${FORTE_BUILDSUPPORT_DIRECTORY}/GCov.cmake) + SETUP_GCOV(TestCoverage forte_test coverage) + endif() +endif() + +####################################################################################### +# Generate stringlist for every source file +####################################################################################### +if(FORTE_LINKED_STRINGDICT) + set(ENABLE_GENERATED_SOURCE_CPP ON) + ADD_DEPENDENCIES (forte_test forte_stringlist_externals) +endif(FORTE_LINKED_STRINGDICT) + +####################################################################################### +# Enable autogenerated source files +####################################################################################### +if(ENABLE_GENERATED_SOURCE_CPP) + ADD_DEFINITIONS ("-DFORTE_ENABLE_GENERATED_SOURCE_CPP") +endif(ENABLE_GENERATED_SOURCE_CPP) + +####################################################################################### +# Link Libraries to the Executeable +####################################################################################### + +get_property(LINK_TEST_LIBRARY GLOBAL PROPERTY FORTE_LINK_LIBRARY) + +if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + SET_PROPERTY(GLOBAL APPEND PROPERTY LINK_TEST_LIBRARY "-lboost_unit_test_framework -lboost_prg_exec_monitor -lboost_test_exec_monitor") +endif("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + + +TARGET_LINK_LIBRARIES (forte_test ${LINK_TEST_LIBRARY} ) + + +# check if correct... +GET_PROPERTY(LINK_DIRECTORIES GLOBAL PROPERTY FORTE_TEST_LINK_DIRECTORIES) +LIST(LENGTH LINK_DIRECTORIES len) +IF(len GREATER 0) + LIST(REMOVE_DUPLICATES LINK_DIRECTORIES) +ENDIF(len GREATER 0) +LINK_DIRECTORIES(${LINK_DIRECTORIES}) + +file(WRITE sources.log "${FORTE_TEST_SOURCE_CPP}" ) + +#else() +# +# if(EXISTS ${FORTE_BINARY_DIR}/file_test_list.txt) +# file(REMOVE ${FORTE_BINARY_DIR}/file_test_list.txt) +# endif() +# +#endif(FORTE_TESTS) + +#export FORTE_CPPFLAGS="-W -Wall -DLOGDEBUG -DFORTE_LITTLE_ENDIAN -DBOOST_TEST_DYN_LINK\ +# -I `pwd`/.. \ +# -I `pwd`/../../../src \ +# -I `pwd`/../../../src/arch \ +# -I `pwd`/../../../src/arch/posix \ +# -I `pwd`/../../../src/core \ +# -I `pwd`/../../../src/core/datatypes \ +# -I `pwd`/../../../src/fblib/events \ +# -I `pwd`/../../../src/fblib/ita \ +# -I `pwd`/../../../src/fblib/math \ +# -I `pwd`/../../../src/fblib/net \ +# -I `pwd`/../../../bin/posix \ +# -I /home/acon/Boost/include" +# export FORTE_CXXFLAGS="-O2 -ggdb" +# export FORTE_LIBS="-lpthread" diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt new file mode 100644 index 000000000..52adaa13f --- /dev/null +++ b/tests/core/CMakeLists.txt @@ -0,0 +1,73 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2015 ACIN, nxtControl, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +#SET(SOURCE_GROUP ${SOURCE_GROUP}\\core) + + forte_test_add_inc_directories(${CMAKE_CURRENT_SOURCE_DIR}) + forte_test_add_link_directories(${CMAKE_BINARY_DIR}/src/core) + + forte_test_add_sourcefile_cpp(../../src/core/typelib.cpp) + forte_test_add_sourcefile_cpp(../../src/core/stringdict.cpp) + forte_test_add_sourcefile_cpp(../../src/core/funcbloc.cpp) + forte_test_add_sourcefile_cpp(../../src/core/cfb.cpp) + forte_test_add_sourcefile_cpp(../../src/core/eventconn.cpp) + forte_test_add_sourcefile_cpp(../../src/core/conn.cpp) + forte_test_add_sourcefile_cpp(../../src/core/ecet.cpp) + forte_test_add_sourcefile_cpp(../../src/core/resource.cpp) + + if(FORTE_SUPPORT_MONITORING) + forte_test_add_sourcefile_cpp(../../src/core/monitoring.cpp) + endif(FORTE_SUPPORT_MONITORING) + + forte_test_add_sourcefile_cpp(../../src/core/fbcontainer.cpp) + forte_test_add_sourcefile_cpp(../../src/core/device.cpp) + forte_test_add_sourcefile_cpp(../../src/core/dataconn.cpp) + forte_test_add_sourcefile_cpp(../../src/core/adapterconn.cpp) + forte_test_add_sourcefile_cpp(../../src/core/if2indco.cpp) + forte_test_add_sourcefile_cpp(../../src/core/adapter.cpp) + + forte_test_add_sourcefile_cpp(../../src/core/devexec.cpp) + forte_test_add_sourcefile_cpp(../../src/core/extevhan.cpp) + + forte_test_add_sourcefile_cpp(../../src/core/utils/string_utils.cpp) + + forte_test_add_sourcefile_cpp(../../src/stdfblib/ita/EMB_RES.cpp) + + #TODO add here architecture specific adds in order to allow testrunns also on other platforms + forte_test_add_sourcefile_cpp(../../src/arch/timerha.cpp) + +if("${FORTE_ARCHITECTURE}" STREQUAL "Posix") + forte_test_add_sourcefile_cpp(../../src/arch/posix/sync.cpp) + forte_test_add_sourcefile_cpp(../../src/arch/posix/thread.cpp) + forte_test_add_sourcefile_cpp(../../src/arch/posix/pctimeha.cpp) +endif() + +if("${FORTE_ARCHITECTURE}" STREQUAL "Win32") + forte_test_add_sourcefile_cpp(../../src/arch/win32/sync.cpp) + forte_test_add_sourcefile_cpp(../../src/arch/win32/thread.cpp) + forte_test_add_sourcefile_cpp(../../src/arch/win32/pctimeha.cpp) +endif() + + + #forte_add_sourcefile_hcpp(thread pctimeha sync) + #forte_add_sourcefile_cpp(main.cpp) + #forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +forte_test_add_sourcefile_cpp(../../src/core/stringdict.cpp) +forte_test_add_sourcefile_cpp(stringdicttests.cpp) +forte_test_add_sourcefile_cpp(typelibdatatypetests.cpp) +forte_test_add_sourcefile_cpp(nameidentifiertest.cpp) +forte_test_add_sourcefile_cpp(mgmstatemachinetest.cpp) + +forte_test_add_subdirectory(datatypes) +forte_test_add_subdirectory(cominfra) +forte_test_add_subdirectory(fbtests) +forte_test_add_subdirectory(utils) diff --git a/tests/core/cominfra/CMakeLists.txt b/tests/core/cominfra/CMakeLists.txt new file mode 100644 index 000000000..b8ec526b4 --- /dev/null +++ b/tests/core/cominfra/CMakeLists.txt @@ -0,0 +1,26 @@ +#******************************************************************************* +# * Copyright (c) 2011 ACIN +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +#SET(SOURCE_GROUP ${SOURCE_GROUP}\\core) + + forte_test_add_inc_directories(${CMAKE_CURRENT_SOURCE_DIR}) + forte_test_add_link_directories(${CMAKE_BINARY_DIR}/src/core/cominfra) + + + forte_test_add_sourcefile_cpp(fbdkasn1layerser_test.cpp) + forte_test_add_sourcefile_cpp(fbdkasn1layerdeser_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/cominfra/comlayer.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/cominfra/fbdkasn1layer.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/cominfra/commfb.cpp) + forte_test_add_sourcefile_cpp(devlogtestmock.cpp) + forte_test_add_sourcefile_cpp(comlayermantestmock.cpp) + + #forte_test_add_sourcefile_cpp(../../../bin/posix/core/cominfra/comlayersmanager.cpp) diff --git a/tests/core/cominfra/comlayermantestmock.cpp b/tests/core/cominfra/comlayermantestmock.cpp new file mode 100644 index 000000000..35980f5b5 --- /dev/null +++ b/tests/core/cominfra/comlayermantestmock.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "comlayersmanager.h" +#include "commfb.h" + +using namespace forte::com_infra; + +CComLayer* CComLayersManager::createCommunicationLayer(char *, CComLayer* , CCommFB * ){ + CComLayer* m_poNewLayer = 0; + + return m_poNewLayer; +} diff --git a/tests/core/cominfra/devlogtestmock.cpp b/tests/core/cominfra/devlogtestmock.cpp new file mode 100644 index 000000000..78ed89d3c --- /dev/null +++ b/tests/core/cominfra/devlogtestmock.cpp @@ -0,0 +1,15 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "../../../src/arch/devlog.h" + +void logMessage(E_MsgLevel , const char *, ...){ + +} diff --git a/tests/core/cominfra/fbdkasn1layer_serdeserdata.h b/tests/core/cominfra/fbdkasn1layer_serdeserdata.h new file mode 100644 index 000000000..bf59b288c --- /dev/null +++ b/tests/core/cominfra/fbdkasn1layer_serdeserdata.h @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN and nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "../../../src/arch/datatype.h" + + +//Testdata +//BOOL +const unsigned int cg_unBoolSerSize = 1; +const TForteByte cg_abBoolFalse = 0x40; +const TForteByte cg_abBoolTrue = 0x41; + +//BYTE +const unsigned int cg_unByteSerSize = 2; +const TForteByte cg_abByte0[2] = {0x51, 0}; +const TForteByte cg_abByte12[2] = {0x51, 12}; +const TForteByte cg_abByte128[2] = {0x51, 128}; +const TForteByte cg_abByte255[2] = {0x51, 255}; + +//WORD +const unsigned int cg_unWordSerSize = 3; +const TForteByte cg_abWord0[3] = {0x52, 0, 0}; +const TForteByte cg_abWord255[3] = {0x52, 0, 255}; +const TForteByte cg_abWord256[3] = {0x52, 1, 0}; +const TForteByte cg_abWord65535[3] = {0x52, 0xFF, 0xFF}; +const TForteByte cg_abWord40396[3] = {0x52, 0x9D, 0xCC}; + +//DWORD +const unsigned int cg_unDWordSerSize = 5; +const TForteByte cg_abDWord0[5] = {0x53, 0, 0, 0, 0}; +const TForteByte cg_abDWord255[5] = {0x53, 0, 0, 0, 0xFF}; +const TForteByte cg_abDWord256[5] = {0x53, 0, 0, 1, 0}; +const TForteByte cg_abDWord65535[5] = {0x53, 0, 0, 0xFF, 0xFF}; +const TForteByte cg_abDWord65536[5] = {0x53, 0, 1, 0, 0}; +const TForteByte cg_abDWord4294967295[5] = {0x53, 0xFF, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abDWord690586453[5] = {0x53, 0x29, 0x29, 0x83, 0x55}; + +#ifdef FORTE_USE_64BIT_DATATYPES +//LWORD +const unsigned int cg_unLWordSerSize = 9; +const TForteByte cg_abLWord0[9] = {0x54, 0, 0, 0, 0, 0, 0, 0, 0}; +const TForteByte cg_abLWord255[9] = {0x54, 0, 0, 0, 0, 0, 0, 0, 0xFF}; +const TForteByte cg_abLWord256[9] = {0x54, 0, 0, 0, 0, 0, 0, 1, 0}; +const TForteByte cg_abLWord65535[9] = {0x54, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}; +const TForteByte cg_abLWord65536[9] = {0x54, 0, 0, 0, 0, 0, 1, 0, 0}; +const TForteByte cg_abLWord4294967295[9] = {0x54, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abLWord4294967296[9] = {0x54, 0, 0, 0, 1, 0, 0, 0, 0}; +const TForteByte cg_abLWord18446744073709551615[9] = {0x54, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abLWord3544923647067170873[9] = {0x54, 0x31, 0x32, 0x19, 0x46, 0x73, 0x52, 0x28, 0x39}; +#endif + +//USINT +const unsigned int cg_unUSIntSerSize = 2; +const TForteByte cg_abUSInt0[2] = {0x46, 0}; +const TForteByte cg_abUSInt12[2] = {0x46, 12}; +const TForteByte cg_abUSInt128[2] = {0x46, 128}; +const TForteByte cg_abUSInt255[2] = {0x46, 255}; + +//UINT +const unsigned int cg_unUIntSerSize = 3; +const TForteByte cg_abUInt0[3] = {0x47, 0, 0}; +const TForteByte cg_abUInt255[3] = {0x47, 0, 255}; +const TForteByte cg_abUInt256[3] = {0x47, 1, 0}; +const TForteByte cg_abUInt65535[3] = {0x47, 0xFF, 0xFF}; +const TForteByte cg_abUInt40396[3] = {0x47, 0x9D, 0xCC}; + +//UDINT +const unsigned int cg_unUDIntSerSize = 5; +const TForteByte cg_abUDInt0[5] = {0x48, 0, 0, 0, 0}; +const TForteByte cg_abUDInt255[5] = {0x48, 0, 0, 0, 0xFF}; +const TForteByte cg_abUDInt256[5] = {0x48, 0, 0, 1, 0}; +const TForteByte cg_abUDInt65535[5] = {0x48, 0, 0, 0xFF, 0xFF}; +const TForteByte cg_abUDInt65536[5] = {0x48, 0, 1, 0, 0}; +const TForteByte cg_abUDInt4294967295[5] = {0x48, 0xFF, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abUDInt690586453[5] = {0x48, 0x29, 0x29, 0x83, 0x55}; + +#ifdef FORTE_USE_64BIT_DATATYPES +//ULINT +const unsigned int cg_unULIntSerSize = 9; +const TForteByte cg_abULInt0[9] = {0x49, 0, 0, 0, 0, 0, 0, 0, 0}; +const TForteByte cg_abULInt255[9] = {0x49, 0, 0, 0, 0, 0, 0, 0, 0xFF}; +const TForteByte cg_abULInt256[9] = {0x49, 0, 0, 0, 0, 0, 0, 1, 0}; +const TForteByte cg_abULInt65535[9] = {0x49, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}; +const TForteByte cg_abULInt65536[9] = {0x49, 0, 0, 0, 0, 0, 1, 0, 0}; +const TForteByte cg_abULInt4294967295[9] = {0x49, 0, 0, 0, 0, 0xFF, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abULInt4294967296[9] = {0x49, 0, 0, 0, 1, 0, 0, 0, 0}; +const TForteByte cg_abULInt18446744073709551615[9] = {0x49, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abULInt3544923647067170873[9] = {0x49, 0x31, 0x32, 0x19, 0x46, 0x73, 0x52, 0x28, 0x39}; +#endif + + +//SINT +const unsigned int cg_unSIntSerSize = 2; +const TForteByte cg_abSInt0[2] = {0x42, 0}; +const TForteByte cg_abSIntm128[2] = {0x42, 0x80}; +const TForteByte cg_abSInt127[2] = {0x42, 127}; +const TForteByte cg_abSIntm90[2] = {0x42, 0xA6}; +const TForteByte cg_abSInt90[2] = {0x42, 0x5A }; + +//INT +const unsigned int cg_unIntSerSize = 3; +const TForteByte cg_abInt0[3] = {0x43, 0, 0}; +const TForteByte cg_abIntm128[3] = {0x43, 0xff, 0x80}; +const TForteByte cg_abIntm129[3] = {0x43, 0xff, 0x7F}; +const TForteByte cg_abInt127[3] = {0x43, 0, 127}; +const TForteByte cg_abInt128[3] = {0x43, 0, 128}; +const TForteByte cg_abIntm32768[3] = {0x43, 0x80, 0x00}; +const TForteByte cg_abInt32767[3] = {0x43, 0x7F, 0xFF}; +const TForteByte cg_abInt10934[3] = {0x43, 0x2A, 0xB6}; +const TForteByte cg_abIntm10934[3] = {0x43, 0xD5, 0x4A}; + +//DINT +const unsigned int cg_unDIntSerSize = 5; +const TForteByte cg_abDInt0[5] = {0x44, 0, 0, 0, 0}; +const TForteByte cg_abDIntm128[5] = {0x44, 0xff, 0xff, 0xff, 0x80}; +const TForteByte cg_abDIntm129[5] = {0x44, 0xff, 0xff, 0xff, 0x7F}; +const TForteByte cg_abDInt127[5] = {0x44, 0, 0, 0, 127}; +const TForteByte cg_abDInt128[5] = {0x44, 0, 0, 0, 128}; +const TForteByte cg_abDIntm32768[5] = {0x44, 0xff, 0xff, 0x80, 0x00}; +const TForteByte cg_abDIntm32769[5] = {0x44, 0xff, 0xff, 0x7F, 0xFF}; +const TForteByte cg_abDInt32767[5] = {0x44, 0, 0, 0x7F, 0xFF}; +const TForteByte cg_abDInt32768[5] = {0x44, 0, 0, 0x80, 0x00}; +const TForteByte cg_abDIntm2147483648[5] = {0x44, 0x80, 0, 0x0, 0x0}; +const TForteByte cg_abDInt2147483647[5] = {0x44, 0x7F, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abDInt800058586[5] = {0x44, 0x2F, 0xAF, 0xEC, 0xDA}; +const TForteByte cg_abDIntm800058586[5] = {0x44, 0xD0, 0x50, 0x13, 0x26}; + +#ifdef FORTE_USE_64BIT_DATATYPES +//LINT +const unsigned int cg_unLIntSerSize = 9; +const TForteByte cg_abLInt0[9] = {0x45, 0, 0, 0, 0, 0, 0, 0, 0}; +const TForteByte cg_abLIntm128[9] = {0x45, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80}; +const TForteByte cg_abLIntm129[9] = {0x45, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7F}; +const TForteByte cg_abLInt127[9] = {0x45, 0, 0, 0, 0, 0, 0, 0, 127}; +const TForteByte cg_abLInt128[9] = {0x45, 0, 0, 0, 0, 0, 0, 0, 128}; +const TForteByte cg_abLIntm32768[9] = {0x45, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00}; +const TForteByte cg_abLIntm32769[9] = {0x45, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7F, 0xFF}; +const TForteByte cg_abLInt32767[9] = {0x45, 0, 0, 0, 0, 0, 0, 0x7F, 0xFF}; +const TForteByte cg_abLInt32768[9] = {0x45, 0, 0, 0, 0, 0, 0, 0x80, 0x00}; +const TForteByte cg_abLIntm2147483648[9] = {0x45, 0xff, 0xff, 0xff, 0xff, 0x80, 0, 0x0, 0x0}; +const TForteByte cg_abLIntm2147483649[9] = {0x45, 0xff, 0xff, 0xff, 0xff, 0x7F, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abLInt2147483647[9] = {0x45, 0, 0, 0, 0, 0x7F, 0xFF, 0xFF, 0xFF}; +const TForteByte cg_abLInt2147483648[9] = {0x45, 0, 0, 0, 0, 0x80, 0, 0x0, 0x0}; +const TForteByte cg_abLIntm9223372036854775808[9] = {0x45, 0x80, 0, 0x0, 0x0, 0, 0, 0, 0}; +const TForteByte cg_abLInt9223372036854775807[9] = {0x45, 0x7F, 0xFF, 0xFF, 0xFF, 0xff, 0xff, 0xff, 0xff}; +const TForteByte cg_abLInt800058586[9] = {0x45, 0, 0, 0, 0, 0x2F, 0xAF, 0xEC, 0xDA}; +const TForteByte cg_abLIntm800058586[9] = {0x45, 0xff, 0xff, 0xff, 0xff, 0xD0, 0x50, 0x13, 0x26}; +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +//REAL +const unsigned int cg_unRealSerSize = 5; +const TForteByte cg_abReal0[5] = {0x4A, 0, 0, 0, 0}; +const TForteByte cg_abReal2_2874e6[5] = {0x4A, 0x4a, 0x0b, 0x9c, 0xa0}; +const TForteByte cg_abRealm6_2587em4[5] = {0x4A, 0xba, 0x24, 0x11, 0x6d}; +const TForteByte cg_abReal1_0Em37[5] = {0x4A, 0x02, 0x08, 0x1c, 0xea}; +const TForteByte cg_abReal36_0[5] = {0x4A, 0x42, 0x10, 0x00, 0x00}; + +#ifdef FORTE_USE_64BIT_DATATYPES +//LREAL +const unsigned int cg_unLRealSerSize = 9; +const TForteByte cg_abLReal0[9] = {0x4B, 0, 0, 0, 0, 0, 0, 0, 0}; +const TForteByte cg_abLReal2_28743e6[9] = {0x4B, 0x41, 0x41, 0x73, 0xa3, 0x00, 0x00, 0x00, 0x00}; +const TForteByte cg_abLRealm6_2587em4[9] = {0x4B, 0xbf, 0x44, 0x82, 0x2d, 0x97, 0x3c, 0xf2, 0xfb}; +const TForteByte cg_abLReal1_0Em37[9] = {0x4B, 0x38, 0x41, 0x03, 0x9d, 0x42, 0x8a, 0x8b, 0x8f}; +const TForteByte cg_abLReal36_0[9] = {0x4B, 0x40, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +#endif +#endif + +//STRING +const unsigned int cg_unStringEmptySerSize = 3; +const TForteByte cg_abStringEmpty[3] = {0x50, 0, 0}; +const unsigned int cg_unStringHalloWorldSerSize = 13; +const TForteByte cg_abStringHalloWorld[13] = {0x50, 0, 0xA, 'H', 'a', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'}; + +//WSTRING +const unsigned int cg_unWStringEmptySerSize = 3; +const TForteByte cg_abWStringEmpty[3] = {0x55, 0, 0 }; +const unsigned int cg_unWStringHalloWorldSerSize = 23; +const TForteByte cg_abWStringHalloWorld[23] = {0x55, 0, 0xA, 0, 'H', 0, 'a', 0, 'l', 0, 'l', 0, 'o', 0, 'W', 0, 'o', 0, 'r', 0, 'l', 0, 'd'}; +const unsigned int cg_unWStringNihongoSerSize = 9; +const TForteByte cg_abWStringNihongo[9] = { 0x55, 0, 3, 0x65, 0xe5, 0x67, 0x2c, 0x8a, 0x9e }; +const TForteByte cg_abWStringNihongoUTF8[10] = { 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, 0 }; + +//TIME +const unsigned int cg_unTimeSerSize = 9; +const TForteByte cg_abTime0[9] = {0x4C, 0, 0, 0, 0, 0, 0, 0, 0}; +const TForteByte cg_abTime3000ms[9] = {0x4C, 0, 0, 0, 0, 0, 0x2D, 0xC6, 0xC0}; +const TForteByte cg_abTime3s22ms[9] = {0x4C, 0, 0, 0, 0, 0, 0x2e, 0x1c, 0xb0}; + + +//ARRAY tests +const unsigned int cg_unBOOL5SerSize = 8; +const TForteByte cg_abArrayBool10011[] = {0x76, 0x0, 0x5, 0x41, 0x40, 0x40, 0x41, 0x41}; +const TForteByte cg_abArrayBool01010[] = {0x76, 0x0, 0x5, 0x40, 0x41, 0x40, 0x41, 0x40}; + +const unsigned int cg_unSINT4SerSize = 8; +const TForteByte cg_abArraySINTm128_127_0_m90[] = {0x76, 0x0, 0x4, 0x42, 0x80, 127, 0, 0xA6}; +const TForteByte cg_abArraySINTm90_90_127_0[] = {0x76, 0x0, 0x4, 0x42, 0xA6, 0x5A, 127, 0x0}; + +const unsigned int cg_unString2SerSize = 18; +const TForteByte cg_abArrayStringEmptyHalloWorld[] = {0x76, 0x00, 0x02, 0x50, 0, 0, 0, 0xA, 'H', 'a', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd'}; + + diff --git a/tests/core/cominfra/fbdkasn1layerdeser_test.cpp b/tests/core/cominfra/fbdkasn1layerdeser_test.cpp new file mode 100644 index 000000000..216108953 --- /dev/null +++ b/tests/core/cominfra/fbdkasn1layerdeser_test.cpp @@ -0,0 +1,1549 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss, nxtControl and Profactor + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Michael Hofmann, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include + +#include "fbdkasn1layer_serdeserdata.h" + +#include "../../../src/core/cominfra/fbdkasn1layer.h" +#include "../../../src/core/cominfra/commfb.h" +#include "../../../src/stdfblib/ita/EMB_RES.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" + +#include "../../../src/core/datatypes/forte_time.h" + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_LREAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "fbdkasn1layerdeser_test_gen.cpp" +#endif + +class CDeserTestMockCommFB : public forte::com_infra::CCommFB{ + public: + CDeserTestMockCommFB(TForteUInt8 pa_nNumRD, const CStringDictionary::TStringId * const pa_aunDODataTypeNames) : + forte::com_infra::CCommFB(CStringDictionary::scm_nInvalidStringId, &m_oResource, forte::com_infra::e_Publisher), + m_oResource(CStringDictionary::scm_nInvalidStringId, 0), + m_oMockFBInterface(0U, 0, 0, 0, 0U, 0, 0, 0, 2U, 0, scm_anInputTypes, static_cast(pa_nNumRD + 2U), 0, pa_aunDODataTypeNames){ + + m_acFBConnData = new TForteByte[genFBConnDataSize(0, 2, pa_nNumRD + 2)]; + m_acFBVarsData = new TForteByte[genFBVarsDataSize(2, pa_nNumRD + 2)]; + + setupFBInterface(&m_oMockFBInterface, m_acFBConnData, m_acFBVarsData, false); + } + + virtual ~CDeserTestMockCommFB(){ + freeAllData(); + delete [] m_acFBConnData; + delete [] m_acFBVarsData; + m_pstInterfaceSpec = 0; + } + + private: + static const CStringDictionary::TStringId scm_anInputTypes[]; + + EMB_RES m_oResource; + SFBInterfaceSpecforGenerics m_oMockFBInterface; + TForteByte *m_acFBConnData; + TForteByte *m_acFBVarsData; + +}; + +const CStringDictionary::TStringId CDeserTestMockCommFB::scm_anInputTypes[] = {g_nStringIdBOOL, g_nStringIdBOOL}; + +BOOST_AUTO_TEST_SUITE(fbdkasn1layer_deserialize_test) + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_BOOL){ + + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_BOOL &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize)); + BOOST_CHECK_EQUAL(false, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(&cg_abBoolTrue, cg_unBoolSerSize)); + BOOST_CHECK_EQUAL(true, nVal); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_BOOL){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBOOL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_BYTE){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBYTE}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_BYTE &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abByte0, cg_unByteSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abByte12, cg_unByteSerSize)); + BOOST_CHECK_EQUAL(12, nVal); + BOOST_CHECK_EQUAL(12, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abByte128, cg_unByteSerSize)); + BOOST_CHECK_EQUAL(128, nVal); + BOOST_CHECK_EQUAL(128, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abByte255, cg_unByteSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + BOOST_CHECK_EQUAL(255, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_BYTE){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdBYTE}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_WORD){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdWORD}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_WORD &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWord0, cg_unWordSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWord255, cg_unWordSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + BOOST_CHECK_EQUAL(255, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWord256, cg_unWordSerSize)); + BOOST_CHECK_EQUAL(256, nVal); + BOOST_CHECK_EQUAL(256, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWord65535, cg_unWordSerSize)); + BOOST_CHECK_EQUAL(65535, nVal); + BOOST_CHECK_EQUAL(65535, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWord40396, cg_unWordSerSize)); + BOOST_CHECK_EQUAL(40396, nVal); + BOOST_CHECK_EQUAL(40396, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_WORD){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdWORD}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_DWORD){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDWORD}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_DWORD &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDWord0, cg_unDWordSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDWord255, cg_unDWordSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + BOOST_CHECK_EQUAL(255, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDWord256, cg_unDWordSerSize)); + BOOST_CHECK_EQUAL(256, nVal); + BOOST_CHECK_EQUAL(256, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDWord65535, cg_unDWordSerSize)); + BOOST_CHECK_EQUAL(65535, nVal); + BOOST_CHECK_EQUAL(65535, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDWord65536, cg_unDWordSerSize)); + BOOST_CHECK_EQUAL(65536, nVal); + BOOST_CHECK_EQUAL(65536, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDWord4294967295, cg_unDWordSerSize)); + BOOST_CHECK_EQUAL(4294967295UL, nVal); + BOOST_CHECK_EQUAL(4294967295UL, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize)); + BOOST_CHECK_EQUAL(690586453, nVal); + BOOST_CHECK_EQUAL(690586453, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_DWORD){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDWORD}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_LWORD){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLWORD}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_LWORD &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord0, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord255, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord256, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(256, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord65535, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(65535, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord65536, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(65536, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord4294967295, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(4294967295ULL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(4294967296ULL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord18446744073709551615, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(18446744073709551615ULL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLWord3544923647067170873, cg_unLWordSerSize)); + BOOST_CHECK_EQUAL(3544923647067170873ULL, nVal); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_LWORD){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLWORD}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} +#endif + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_USINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUSINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_USINT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUSInt0, cg_unUSIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUSInt12, cg_unUSIntSerSize)); + BOOST_CHECK_EQUAL(12, nVal); + BOOST_CHECK_EQUAL(12, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize)); + BOOST_CHECK_EQUAL(128, nVal); + BOOST_CHECK_EQUAL(128, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUSInt255, cg_unUSIntSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + BOOST_CHECK_EQUAL(255, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_USINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUSINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_UINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_UINT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUInt0, cg_unUIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUInt255, cg_unUIntSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + BOOST_CHECK_EQUAL(255, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUInt256, cg_unUIntSerSize)); + BOOST_CHECK_EQUAL(256, nVal); + BOOST_CHECK_EQUAL(256, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUInt65535, cg_unUIntSerSize)); + BOOST_CHECK_EQUAL(65535, nVal); + BOOST_CHECK_EQUAL(65535, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize)); + BOOST_CHECK_EQUAL(40396, nVal); + BOOST_CHECK_EQUAL(40396, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_UINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_UDINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUDINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_UDINT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUDInt0, cg_unUDIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUDInt255, cg_unUDIntSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + BOOST_CHECK_EQUAL(255, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUDInt256, cg_unUDIntSerSize)); + BOOST_CHECK_EQUAL(256, nVal); + BOOST_CHECK_EQUAL(256, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUDInt65535, cg_unUDIntSerSize)); + BOOST_CHECK_EQUAL(65535, nVal); + BOOST_CHECK_EQUAL(65535, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUDInt65536, cg_unUDIntSerSize)); + BOOST_CHECK_EQUAL(65536, nVal); + BOOST_CHECK_EQUAL(65536, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUDInt4294967295, cg_unUDIntSerSize)); + BOOST_CHECK_EQUAL(4294967295UL, nVal); + BOOST_CHECK_EQUAL(4294967295UL, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize)); + BOOST_CHECK_EQUAL(690586453, nVal); + BOOST_CHECK_EQUAL(690586453, *((CIEC_ANY::TLargestUIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_UDINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdUDINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_ULINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdULINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_ULINT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt0, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt255, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(255, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt256, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(256, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt65535, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(65535, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt65536, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(65536, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt4294967295, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(4294967295ULL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt4294967296, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(4294967296ULL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt18446744073709551615, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(18446744073709551615ULL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize)); + BOOST_CHECK_EQUAL(3544923647067170873ULL, nVal); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_ULINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdULINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} +#endif + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_SINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdSINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_SINT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abSInt0, cg_unSIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abSIntm128, cg_unSIntSerSize)); + BOOST_CHECK_EQUAL(-128, nVal); + BOOST_CHECK_EQUAL(-128, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abSInt127, cg_unSIntSerSize)); + BOOST_CHECK_EQUAL(127, nVal); + BOOST_CHECK_EQUAL(127, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize)); + BOOST_CHECK_EQUAL(-90, nVal); + BOOST_CHECK_EQUAL(-90, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abSInt90, cg_unSIntSerSize)); + BOOST_CHECK_EQUAL(90, nVal); + BOOST_CHECK_EQUAL(90, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_SINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdSINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_INT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_INT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abInt0, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abIntm128, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(-128, nVal); + BOOST_CHECK_EQUAL(-128, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abIntm129, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(-129, nVal); + BOOST_CHECK_EQUAL(-129, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abInt127, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(127, nVal); + BOOST_CHECK_EQUAL(127, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abInt128, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(128, nVal); + BOOST_CHECK_EQUAL(128, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abIntm32768, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(-32768, nVal); + BOOST_CHECK_EQUAL(-32768, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abInt32767, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(32767, nVal); + BOOST_CHECK_EQUAL(32767, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abIntm10934, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(-10934, nVal); + BOOST_CHECK_EQUAL(-10934, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abInt10934, cg_unIntSerSize)); + BOOST_CHECK_EQUAL(10934, nVal); + BOOST_CHECK_EQUAL(10934, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_INT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_DINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_DINT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDInt0, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + BOOST_CHECK_EQUAL(0, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDIntm128, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(static_cast(-128), nVal.operator TForteInt32()); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDIntm129, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(-129, nVal); + BOOST_CHECK_EQUAL(-129, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDInt127, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(127, nVal); + BOOST_CHECK_EQUAL(127, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDInt128, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(128, nVal); + BOOST_CHECK_EQUAL(128, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDIntm32768, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(-32768, nVal); + BOOST_CHECK_EQUAL(-32768, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDIntm32769, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(-32769, nVal); + BOOST_CHECK_EQUAL(-32769, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDInt32767, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(32767, nVal); + BOOST_CHECK_EQUAL(32767, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDInt32768, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(32768, nVal); + BOOST_CHECK_EQUAL(32768, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDIntm2147483648, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(-2147483648L, nVal); + + //the test didn't work correctly when not using this helper var + TForteInt32 buf = -2147483648L; + BOOST_CHECK_EQUAL(buf, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDInt2147483647, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(2147483647L, nVal); + BOOST_CHECK_EQUAL(2147483647L, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDIntm800058586, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(-800058586L, nVal); + BOOST_CHECK_EQUAL(-800058586L, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize)); + BOOST_CHECK_EQUAL(800058586L, nVal); + BOOST_CHECK_EQUAL(800058586L, *((CIEC_ANY::TLargestIntValueType *) nVal.getDataPtr())); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_DINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdDINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_LINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_LINT &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt0, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm128, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(-128, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm129, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(-129, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt127, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(127, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt128, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(128, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm32768, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(-32768, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm32769, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(-32769, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt32767, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(32767, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt32768, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(32768, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm2147483648, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(-2147483648LL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm2147483649, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(-2147483649LL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt2147483647, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(2147483647LL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt2147483648, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(2147483648LL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm9223372036854775808, cg_unLIntSerSize)); +#ifndef __INT64_C + BOOST_CHECK_EQUAL((-9223372036854775808LL), nVal); +#else + BOOST_CHECK_EQUAL(__INT64_C(-9223372036854775808), nVal); +#endif + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt9223372036854775807, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(9223372036854775807LL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(-800058586LL, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLInt800058586, cg_unLIntSerSize)); + BOOST_CHECK_EQUAL(800058586LL, nVal); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_LINT){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +#endif + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_REAL){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdREAL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_REAL &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abReal0, cg_unRealSerSize)); + BOOST_CHECK_EQUAL(0.0f, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abReal2_2874e6, cg_unRealSerSize)); + BOOST_CHECK_EQUAL(2.2874e6f, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abRealm6_2587em4, cg_unRealSerSize)); + BOOST_CHECK_EQUAL(-6.2587e-4f, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize)); + BOOST_CHECK_EQUAL(1.0E-37f, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abReal36_0, cg_unRealSerSize)); + BOOST_CHECK_EQUAL(36.0f, nVal); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_REAL){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdREAL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_LREAL){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLREAL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_LREAL &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLReal0, cg_unLRealSerSize)); + BOOST_CHECK_EQUAL(0.0, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLReal2_28743e6, cg_unLRealSerSize)); + BOOST_CHECK_EQUAL(2.28743e6, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize)); + BOOST_CHECK_EQUAL(-6.2587e-4, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLReal1_0Em37, cg_unLRealSerSize)); + BOOST_CHECK_EQUAL(1.0E-37, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abLReal36_0, cg_unLRealSerSize)); + BOOST_CHECK_EQUAL(36.0, nVal); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_LREAL){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdLREAL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} +#endif +#endif + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_STRING){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdSTRING}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_STRING &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abStringEmpty, cg_unStringEmptySerSize)); + BOOST_CHECK_EQUAL(nVal.length(), 0); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize)); + BOOST_CHECK_EQUAL(nVal.length(), 10); + BOOST_CHECK_EQUAL(strcmp(nVal.getValue(), "HalloWorld"), 0); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_STRING){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdSTRING}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_WSTRING){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdWSTRING}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_WSTRING &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWStringEmpty, cg_unWStringEmptySerSize)); + BOOST_CHECK_EQUAL(nVal.length(), 0); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize)); + BOOST_CHECK_EQUAL(nVal.length(), 10); + BOOST_CHECK_EQUAL(strcmp(nVal.getValue(), "HalloWorld"), 0); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abWStringNihongo, cg_unWStringNihongoSerSize)); + BOOST_CHECK_EQUAL(nVal.length(), 9); + BOOST_CHECK_EQUAL(strcmp(nVal.getValue(), (const char *) cg_abWStringNihongoUTF8), 0); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_WSTRING){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdWSTRING}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_TIME){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdTIME}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_TIME &nVal(*static_cast(nTestFB.getRDs())); + char acStrBuf[20]; + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abTime0, cg_unTimeSerSize)); + BOOST_CHECK_EQUAL(0, nVal); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abTime3000ms, cg_unTimeSerSize)); + nVal.toString(acStrBuf, 20); + BOOST_CHECK_EQUAL(strcmp(acStrBuf, "T#3000ms"), 0); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize)); + nVal.toString(acStrBuf, 20); + BOOST_CHECK_EQUAL(strcmp(acStrBuf, "T#3022ms"), 0); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_TIME){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdTIME}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_MultiDatas){ + + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdTIME, g_nStringIdWORD, g_nStringIdSTRING, g_nStringIdINT, g_nStringIdBOOL, g_nStringIdTIME}; + CDeserTestMockCommFB nTestFB(6, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + CIEC_TIME &oTimeVal1(*static_cast(nTestFB.getRDs())); + CIEC_WORD &oWordVal(*static_cast(nTestFB.getRDs() + 1)); + CIEC_STRING &oStringVal(*static_cast(nTestFB.getRDs() + 2)); + CIEC_INT &oIntVal(*static_cast(nTestFB.getRDs() + 3)); + CIEC_BOOL &oBoolVal(*static_cast(nTestFB.getRDs() + 4)); + CIEC_TIME &oTimeVal2(*static_cast(nTestFB.getRDs() + 5)); + + unsigned int nSerSize = cg_unTimeSerSize + cg_unWordSerSize + cg_unStringHalloWorldSerSize + cg_unIntSerSize + cg_unBoolSerSize + cg_unTimeSerSize; + TForteByte anGoodResult[] = {0x4C, 0, 0, 0, 0, 0, 0x2D, 0xC6, 0xC0, 0x52, 0x9D, 0xCC, 0x50, 0, 0xA, 'H', 'a', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd', 0x43, 0xD5, 0x4A, 0x41, 0x4C, 0, 0, 0, 0, 0, 0x2e, 0x1c, 0xb0}; + + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(anGoodResult, nSerSize)); + char acStrBuf[20]; + oTimeVal1.toString(acStrBuf, 20); + + BOOST_CHECK_EQUAL(strcmp(acStrBuf, "T#3000ms"), 0); + BOOST_CHECK_EQUAL(oWordVal, 40396); + BOOST_CHECK_EQUAL(strcmp(oStringVal.getValue(), "HalloWorld"), 0); + BOOST_CHECK_EQUAL(oIntVal, -10934); + BOOST_CHECK_EQUAL(oBoolVal, true); + oTimeVal2.toString(acStrBuf, 20); + BOOST_CHECK_EQUAL(strcmp(acStrBuf, "T#3022ms"), 0); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Test_ARRAY){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 5, g_nStringIdBOOL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + CIEC_ARRAY &nVal(*static_cast(nTestFB.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abArrayBool10011, cg_unBOOL5SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nVal[0]), true); + BOOST_CHECK_EQUAL(static_cast(*nVal[1]),false); + BOOST_CHECK_EQUAL(static_cast(*nVal[2]),false); + BOOST_CHECK_EQUAL(static_cast(*nVal[3]),true); + BOOST_CHECK_EQUAL(static_cast(*nVal[4]), true); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nVal[0]), false); + BOOST_CHECK_EQUAL(static_cast(*nVal[1]), true); + BOOST_CHECK_EQUAL(static_cast(*nVal[2]), false); + BOOST_CHECK_EQUAL(static_cast(*nVal[3]), true); + BOOST_CHECK_EQUAL(static_cast(*nVal[4]), false); + + + CStringDictionary::TStringId anType7[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 7, g_nStringIdBOOL}; + CDeserTestMockCommFB nTestFB7(1, anType7); + forte::com_infra::CFBDKASN1ComLayer nTestee7(0, &nTestFB7); + CIEC_ARRAY &nBoolArray7(*static_cast(nTestFB7.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee7.recvData(cg_abArrayBool10011, cg_unBOOL5SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray7[0]), true); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray7[1]),false); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray7[2]),false); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray7[3]),true); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray7[4]), true); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray7[5]), false); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray7[6]), false); + + + CStringDictionary::TStringId anType3[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 3, g_nStringIdBOOL}; + CDeserTestMockCommFB nTestFB3(1, anType3); + forte::com_infra::CFBDKASN1ComLayer nTestee3(0, &nTestFB3); + CIEC_ARRAY &nBoolArray3(*static_cast(nTestFB3.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee3.recvData(cg_abArrayBool10011, cg_unBOOL5SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray3[0]), true); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray3[1]),false); + BOOST_CHECK_EQUAL(static_cast(*nBoolArray3[2]),false); + + + CStringDictionary::TStringId anType4[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 4, g_nStringIdSINT}; + CDeserTestMockCommFB nTestFB4(1, anType4); + forte::com_infra::CFBDKASN1ComLayer nTesteeSInt(0, &nTestFB4); + CIEC_ARRAY &nSIntArray(*static_cast(nTestFB4.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTesteeSInt.recvData(cg_abArraySINTm128_127_0_m90, cg_unSINT4SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[0]), -128); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[1]), 127); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[2]), 0); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[3]), -90); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTesteeSInt.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[0]), -90); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[1]), 90); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[2]), 127); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray[3]), 0); + + CStringDictionary::TStringId anTypeSIntArray7[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 7, g_nStringIdSINT}; + CDeserTestMockCommFB nTestFBSIntArray7(1, anTypeSIntArray7); + forte::com_infra::CFBDKASN1ComLayer nTesteeSInt7(0, &nTestFBSIntArray7); + CIEC_ARRAY &nSIntArray7(*static_cast(nTestFBSIntArray7.getRDs())); + + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTesteeSInt7.recvData(cg_abArraySINTm128_127_0_m90, cg_unSINT4SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray7[0]), -128); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray7[1]), 127); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray7[2]), 0); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray7[3]), -90); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray7[4]), 0); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray7[5]), 0); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray7[6]), 0); + + CStringDictionary::TStringId anTypeSInt2[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 2, g_nStringIdSINT}; + CDeserTestMockCommFB nTestFBSInt2(1, anTypeSInt2); + forte::com_infra::CFBDKASN1ComLayer nTesteeSInt2(0, &nTestFBSInt2); + CIEC_ARRAY &nSIntArray2(*static_cast(nTestFBSInt2.getRDs())); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTesteeSInt2.recvData(cg_abArraySINTm128_127_0_m90, cg_unSINT4SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray2[0]), -128); + BOOST_CHECK_EQUAL(static_cast(*nSIntArray2[1]), 127); + + + CStringDictionary::TStringId anTypeString[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 2, g_nStringIdSTRING}; + CDeserTestMockCommFB nTestFBString(1, anTypeString); + forte::com_infra::CFBDKASN1ComLayer nTesteeString(0, &nTestFBString); + CIEC_ARRAY &nStringArray(*static_cast(nTestFBString.getRDs())); + + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTesteeString.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize)); + BOOST_CHECK_EQUAL(static_cast(*nStringArray[0]).length(), 0); + BOOST_CHECK_EQUAL(static_cast(*nStringArray[1]).length(), 10); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nStringArray[1]).getValue(), "HalloWorld"), 0); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_BOOLARRAY){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 5, g_nStringIdBOOL}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_SINTARRAY){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 4, g_nStringIdSINT}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayStringEmptyHalloWorld, cg_unString2SerSize))); +} + +BOOST_AUTO_TEST_CASE(Single_Deserialize_Negative_Test_STRINGARRAY){ + CStringDictionary::TStringId anType[] = {g_nStringIdBOOL, g_nStringIdBOOL, g_nStringIdARRAY, 2, g_nStringIdSTRING}; + CDeserTestMockCommFB nTestFB(1, anType); + forte::com_infra::CFBDKASN1ComLayer nTestee(0, &nTestFB); + + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(&cg_abBoolFalse, cg_unBoolSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abByte128, cg_unByteSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWord40396, cg_unWordSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDWord690586453, cg_unDWordSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLWord4294967296, cg_unLWordSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUSInt128, cg_unUSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUInt40396, cg_unUIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abUDInt690586453, cg_unUDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abULInt3544923647067170873, cg_unULIntSerSize))); +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abSIntm90, cg_unSIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abIntm10934, cg_unIntSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abDInt800058586, cg_unDIntSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLIntm800058586, cg_unLIntSerSize))); +#endif +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abReal1_0Em37, cg_unRealSerSize))); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abLRealm6_2587em4, cg_unLRealSerSize))); +#endif +#endif + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abStringHalloWorld, cg_unStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abWStringHalloWorld, cg_unWStringHalloWorldSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abTime3s22ms, cg_unTimeSerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArrayBool01010, cg_unBOOL5SerSize))); + BOOST_CHECK((forte::com_infra::e_ProcessDataOk != nTestee.recvData(cg_abArraySINTm90_90_127_0, cg_unSINT4SerSize))); +} + + +BOOST_AUTO_TEST_SUITE_END() + diff --git a/tests/core/cominfra/fbdkasn1layerser_test.cpp b/tests/core/cominfra/fbdkasn1layerser_test.cpp new file mode 100644 index 000000000..b142088a6 --- /dev/null +++ b/tests/core/cominfra/fbdkasn1layerser_test.cpp @@ -0,0 +1,1031 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss, nxtControl and Profactor + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Ingo Hegny, Michael Hofmann, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include + +#include "fbdkasn1layer_serdeserdata.h" + +#include "../../../src/core/cominfra/fbdkasn1layer.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" + +#include "../../../src/core/datatypes/forte_time.h" + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_LREAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "fbdkasn1layerser_test_gen.cpp" +#endif + + +class CFBDKASN1ComLayerTestMock: public forte::com_infra::CFBDKASN1ComLayer{ + public: + CFBDKASN1ComLayerTestMock() : forte::com_infra::CFBDKASN1ComLayer(0, 0){ + m_poBottomLayer = &m_oTestLayer; + } + + ~CFBDKASN1ComLayerTestMock(){ + m_poBottomLayer = 0; + } + + void *getSendDataPtr() { + return m_oTestLayer.m_poData; + } + unsigned int getSendDataSize(){ + return m_oTestLayer.m_unSize; + } + + private: + class TestMockBottomLayer : public forte::com_infra::CComLayer{ + public: + TestMockBottomLayer() : forte::com_infra::CComLayer(0,0){ + m_poData = 0; + m_poAllocData = 0; + m_unSize = 0; + } + + ~TestMockBottomLayer(){ + if (0 != m_poAllocData) { + delete[] m_poAllocData; + } + } + + forte::com_infra::EComResponse sendData(void *pa_pvData, unsigned int pa_unSize){ + if (0 != m_poAllocData) { + delete[] m_poAllocData; + } + m_poAllocData = new TForteByte[pa_unSize]; + if (0 != m_poAllocData) { + m_poData = m_poAllocData; + memcpy(m_poData,pa_pvData,pa_unSize); + //m_poData = pa_pvData; + m_unSize = pa_unSize; + return forte::com_infra::e_ProcessDataOk; + } else { + return forte::com_infra::e_ProcessDataSendFailed; + } + } + + virtual void closeConnection() {} + virtual forte::com_infra::EComResponse recvData(const void *, unsigned int ) { + return forte::com_infra::e_ProcessDataOk; + } + virtual forte::com_infra::EComResponse openConnection(char *){ + return forte::com_infra::e_ProcessDataOk; + } + + TForteByte *m_poData; + TForteByte *m_poAllocData; + unsigned int m_unSize; + }; + + TestMockBottomLayer m_oTestLayer; +}; + + + +BOOST_AUTO_TEST_SUITE(fbdkasn1layer_serialize_test) + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_BOOL){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_BOOL nBool; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nBool; + + nBool= false; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nBool, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unBoolSerSize); + BOOST_CHECK_EQUAL(cg_abBoolFalse, *((TForteByte *)nTestee.getSendDataPtr())); + + nBool = true; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nBool, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unBoolSerSize); + BOOST_CHECK_EQUAL(cg_abBoolTrue, *((TForteByte *)nTestee.getSendDataPtr())); + + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(static_cast(0), 0, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(static_cast(0), 0, nBool), -1); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_BYTE){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_BYTE nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[1]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 1, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 1, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unByteSerSize); + BOOST_CHECK(std::equal(cg_abByte0, cg_abByte0 + cg_unByteSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 12; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unByteSerSize); + BOOST_CHECK(std::equal(cg_abByte12, cg_abByte12 + cg_unByteSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unByteSerSize); + BOOST_CHECK(std::equal(cg_abByte128, cg_abByte128 + cg_unByteSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unByteSerSize); + BOOST_CHECK(std::equal(cg_abByte255, cg_abByte255 + cg_unByteSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_WORD){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_WORD nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[2]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 2, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 2, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWordSerSize); + BOOST_CHECK(std::equal(cg_abWord0, cg_abWord0 + cg_unWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWordSerSize); + BOOST_CHECK(std::equal(cg_abWord255, cg_abWord255 + cg_unWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 256; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWordSerSize); + BOOST_CHECK(std::equal(cg_abWord256, cg_abWord256 + cg_unWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 65535; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWordSerSize); + BOOST_CHECK(std::equal(cg_abWord65535, cg_abWord65535 + cg_unWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 40396; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWordSerSize); + BOOST_CHECK(std::equal(cg_abWord40396, cg_abWord40396 + cg_unWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_DWORD){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_DWORD nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[4]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 4, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 4, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDWordSerSize); + BOOST_CHECK(std::equal(cg_abDWord0, cg_abDWord0 + cg_unDWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDWordSerSize); + BOOST_CHECK(std::equal(cg_abDWord255, cg_abDWord255 + cg_unDWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 256; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDWordSerSize); + BOOST_CHECK(std::equal(cg_abDWord256, cg_abDWord256 + cg_unDWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 65535; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDWordSerSize); + BOOST_CHECK(std::equal(cg_abDWord65535, cg_abDWord65535 + cg_unDWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 65536; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDWordSerSize); + BOOST_CHECK(std::equal(cg_abDWord65536, cg_abDWord65536 + cg_unDWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 4294967295UL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDWordSerSize); + BOOST_CHECK(std::equal(cg_abDWord4294967295, cg_abDWord4294967295 + cg_unDWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 690586453; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDWordSerSize); + BOOST_CHECK(std::equal(cg_abDWord690586453, cg_abDWord690586453 + cg_unDWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + + +#ifdef FORTE_USE_64BIT_DATATYPES +//LWORD +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_LWORD){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_LWORD nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[8]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 8, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 8, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord0, cg_abLWord0 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord255, cg_abLWord255 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 256; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord256, cg_abLWord256 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 65535; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord65535, cg_abLWord65535 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 65536; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord65536, cg_abLWord65536 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 4294967295LL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord4294967295, cg_abLWord4294967295 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 4294967296LL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord4294967296, cg_abLWord4294967296 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 18446744073709551615ULL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord18446744073709551615, cg_abLWord18446744073709551615 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 18446744073709551615ULL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLWordSerSize); + BOOST_CHECK(std::equal(cg_abLWord18446744073709551615, cg_abLWord18446744073709551615 + cg_unLWordSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} +#endif + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_USINT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_USINT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[1]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 1, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 1, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUSIntSerSize); + BOOST_CHECK(std::equal(cg_abUSInt0, cg_abUSInt0 + cg_unUSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 12; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUSIntSerSize); + BOOST_CHECK(std::equal(cg_abUSInt12, cg_abUSInt12 + cg_unUSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUSIntSerSize); + BOOST_CHECK(std::equal(cg_abUSInt128, cg_abUSInt128 + cg_unUSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUSIntSerSize); + BOOST_CHECK(std::equal(cg_abUSInt255, cg_abUSInt255 + cg_unUSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_UINT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_UINT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[2]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 2, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 2, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUIntSerSize); + BOOST_CHECK(std::equal(cg_abUInt0, cg_abUInt0 + cg_unUIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUIntSerSize); + BOOST_CHECK(std::equal(cg_abUInt255, cg_abUInt255 + cg_unUIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 256; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUIntSerSize); + BOOST_CHECK(std::equal(cg_abUInt256, cg_abUInt256 + cg_unUIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + + nVal= 65535; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUIntSerSize); + BOOST_CHECK(std::equal(cg_abUInt65535, cg_abUInt65535 + cg_unUIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 40396; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUIntSerSize); + BOOST_CHECK(std::equal(cg_abUInt40396, cg_abUInt40396 + cg_unUIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_UDINT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_UDINT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[4]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 4, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 4, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUDIntSerSize); + BOOST_CHECK(std::equal(cg_abUDInt0, cg_abUDInt0 + cg_unUDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUDIntSerSize); + BOOST_CHECK(std::equal(cg_abUDInt255, cg_abUDInt255 + cg_unUDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + + nVal= 256; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUDIntSerSize); + BOOST_CHECK(std::equal(cg_abUDInt256, cg_abUDInt256 + cg_unUDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + + nVal= 65535; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUDIntSerSize); + BOOST_CHECK(std::equal(cg_abUDInt65535, cg_abUDInt65535 + cg_unUDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 65536; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUDIntSerSize); + BOOST_CHECK(std::equal(cg_abUDInt65536, cg_abUDInt65536 + cg_unUDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 4294967295UL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUDIntSerSize); + BOOST_CHECK(std::equal(cg_abUDInt4294967295, cg_abUDInt4294967295 + cg_unUDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 690586453; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unUDIntSerSize); + BOOST_CHECK(std::equal(cg_abUDInt690586453, cg_abUDInt690586453 + cg_unUDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + + +#ifdef FORTE_USE_64BIT_DATATYPES +//LWORD +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_ULINT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_ULINT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[8]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 8, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 8, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt0, cg_abULInt0 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 255; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt255, cg_abULInt255 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + + nVal= 256; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt256, cg_abULInt256 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + + nVal= 65535; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt65535, cg_abULInt65535 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 65536; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt65536, cg_abULInt65536 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 4294967295ULL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt4294967295, cg_abULInt4294967295 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 4294967296ULL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt4294967296, cg_abULInt4294967296 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 18446744073709551615ULL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt18446744073709551615, cg_abULInt18446744073709551615 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal= 18446744073709551615ULL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unULIntSerSize); + BOOST_CHECK(std::equal(cg_abULInt18446744073709551615, cg_abULInt18446744073709551615 + cg_unULIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} +#endif + + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_SINT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_SINT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[1]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 1, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 1, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unSIntSerSize); + BOOST_CHECK(std::equal(cg_abSInt0, cg_abSInt0 + cg_unSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unSIntSerSize); + BOOST_CHECK(std::equal(cg_abSIntm128, cg_abSIntm128 + cg_unSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 127; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unSIntSerSize); + BOOST_CHECK(std::equal(cg_abSInt127, cg_abSInt127 + cg_unSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -90; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unSIntSerSize); + BOOST_CHECK(std::equal(cg_abSIntm90, cg_abSIntm90 + cg_unSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 90; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unSIntSerSize); + BOOST_CHECK(std::equal(cg_abSInt90, cg_abSInt90 + cg_unSIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_INT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_INT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[2]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 2, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 2, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abInt0, cg_abInt0 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abIntm128, cg_abIntm128 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -129; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abIntm129, cg_abIntm129 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 127; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abInt127, cg_abInt127 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abInt128, cg_abInt128 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -32768; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abIntm32768, cg_abIntm32768 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 32767; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abInt32767, cg_abInt32767 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -10934; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abIntm10934, cg_abIntm10934 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 10934; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unIntSerSize); + BOOST_CHECK(std::equal(cg_abInt10934, cg_abInt10934 + cg_unIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_DINT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_DINT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[4]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 4, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 4, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDInt0, cg_abDInt0 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDIntm128, cg_abDIntm128 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -129; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDIntm129, cg_abDIntm129 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 127; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDInt127, cg_abDInt127 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDInt128, cg_abDInt128 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -32768; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDIntm32768, cg_abDIntm32768 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -32769; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDIntm32769, cg_abDIntm32769 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 32767; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDInt32767, cg_abDInt32767 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 32768; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDInt32768, cg_abDInt32768 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -2147483648L; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDIntm2147483648, cg_abDIntm2147483648 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 2147483647L; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDInt2147483647, cg_abDInt2147483647 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -800058586; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDIntm800058586, cg_abDIntm800058586 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 800058586; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unDIntSerSize); + BOOST_CHECK(std::equal(cg_abDInt800058586, cg_abDInt800058586 + cg_unDIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_LINT){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_LINT nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[8]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 8, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 8, nVal), -1); + + nVal= 0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt0, cg_abLInt0 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm128, cg_abLIntm128 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -129; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm129, cg_abLIntm129 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 127; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt127, cg_abLInt127 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 128; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt128, cg_abLInt128 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -32768; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm32768, cg_abLIntm32768 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -32769; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm32769, cg_abLIntm32769 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 32767; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt32767, cg_abLInt32767 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 32768; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt32768, cg_abLInt32768 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -2147483648LL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm2147483648, cg_abLIntm2147483648 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -2147483649LL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm2147483649, cg_abLIntm2147483649 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 2147483647; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt2147483647, cg_abLInt2147483647 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 2147483648LL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt2147483648, cg_abLInt2147483648 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -9223372036854775808LL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm9223372036854775808, cg_abLIntm9223372036854775808 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 9223372036854775807LL; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt9223372036854775807, cg_abLInt9223372036854775807 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -800058586; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLIntm800058586, cg_abLIntm800058586 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 800058586; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLIntSerSize); + BOOST_CHECK(std::equal(cg_abLInt800058586, cg_abLInt800058586 + cg_unLIntSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +#endif + +#ifdef FORTE_USE_REAL_DATATYPE + + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_REAL){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_REAL nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[4]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 4, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 4, nVal), -1); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unRealSerSize); + BOOST_CHECK(std::equal(cg_abReal0, cg_abReal0 + cg_unRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 2.2874e6f; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unRealSerSize); + BOOST_CHECK(std::equal(cg_abReal2_2874e6, cg_abReal2_2874e6 + cg_unRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -6.2587e-4f; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unRealSerSize); + BOOST_CHECK(std::equal(cg_abRealm6_2587em4, cg_abRealm6_2587em4 + cg_unRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 1.0E-37f; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unRealSerSize); + BOOST_CHECK(std::equal(cg_abReal1_0Em37, cg_abReal1_0Em37 + cg_unRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 36.0f; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unRealSerSize); + BOOST_CHECK(std::equal(cg_abReal36_0, cg_abReal36_0 + cg_unRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +#ifdef FORTE_USE_64BIT_DATATYPES +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_LREAL){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_LREAL nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[8]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 8, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 8, nVal), -1); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLRealSerSize); + BOOST_CHECK(std::equal(cg_abLReal0, cg_abLReal0 + cg_unLRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 2.28743e6; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLRealSerSize); + BOOST_CHECK(std::equal(cg_abLReal2_28743e6, cg_abLReal2_28743e6 + cg_unLRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = -6.2587e-4; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLRealSerSize); + BOOST_CHECK(std::equal(cg_abLRealm6_2587em4, cg_abLRealm6_2587em4 + cg_unLRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 1.0E-37; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLRealSerSize); + BOOST_CHECK(std::equal(cg_abLReal1_0Em37, cg_abLReal1_0Em37 + cg_unLRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = 36.0; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unLRealSerSize); + BOOST_CHECK(std::equal(cg_abLReal36_0, cg_abLReal36_0 + cg_unLRealSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +#endif +#endif + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_STRING){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_STRING nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[2]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 2, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 2, nVal), -1); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unStringEmptySerSize); + BOOST_CHECK(std::equal(cg_abStringEmpty, cg_abStringEmpty + cg_unStringEmptySerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = "HalloWorld"; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unStringHalloWorldSerSize); + BOOST_CHECK(std::equal(cg_abStringHalloWorld, cg_abStringHalloWorld + cg_unStringHalloWorldSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + TForteByte acSecondSmallBuf[12]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSecondSmallBuf, 12, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSecondSmallBuf, 12, nVal), -1); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_WSTRING){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_WSTRING nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[2]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 2, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 2, nVal), -1); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWStringEmptySerSize); + BOOST_CHECK(std::equal(cg_abWStringEmpty, cg_abWStringEmpty + cg_unWStringEmptySerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal = "HalloWorld"; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWStringHalloWorldSerSize); + BOOST_CHECK(std::equal(cg_abWStringHalloWorld, cg_abWStringHalloWorld + cg_unWStringHalloWorldSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + TForteByte acSecondSmallBuf[3]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSecondSmallBuf, cg_unWStringHalloWorldSerSize-1, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSecondSmallBuf, cg_unWStringHalloWorldSerSize-1, nVal), -1); + + nVal = (const char *) cg_abWStringNihongoUTF8; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unWStringNihongoSerSize); + BOOST_CHECK(std::equal(cg_abWStringNihongo, cg_abWStringNihongo + cg_unWStringNihongoSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_TIME){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_TIME nVal; + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + TForteByte acSmallBuf[8]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 8, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 8, nVal), -1); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unTimeSerSize); + BOOST_CHECK(std::equal(cg_abTime0, cg_abTime0 + cg_unStringEmptySerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal.fromString("T#3000ms"); + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unTimeSerSize); + BOOST_CHECK(std::equal(cg_abTime3000ms, cg_abTime3000ms + cg_unTimeSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + nVal.fromString("T#3s22ms"); + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unTimeSerSize); + BOOST_CHECK(std::equal(cg_abTime3s22ms, cg_abTime3s22ms + cg_unTimeSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_MultiDatas){ + CFBDKASN1ComLayerTestMock nTestee; + + CIEC_TIME *poTimeVal1; + CIEC_WORD *poWordVal; + CIEC_STRING *poStringVal; + CIEC_INT *poIntVal; + CIEC_BOOL *poBoolVal; + CIEC_TIME *poTimeVal2; + + TForteByte aoData[sizeof(CIEC_ANY) * 6]; + CIEC_ANY *aoArray = reinterpret_cast(aoData); + + TIEC_ANYPtr poArray[6]; + + poArray[0] = poTimeVal1 = new(reinterpret_cast(aoArray))CIEC_TIME(); + poArray[1] = poWordVal = new(reinterpret_cast(aoArray + 1))CIEC_WORD(); + poArray[2] = poStringVal = new(reinterpret_cast(aoArray + 2))CIEC_STRING(); + poArray[3] = poIntVal = new(reinterpret_cast(aoArray + 3))CIEC_INT(); + poArray[4] = poBoolVal = new(reinterpret_cast(aoArray + 4))CIEC_BOOL(); + poArray[5] = poTimeVal2 = new(reinterpret_cast(aoArray + 5))CIEC_TIME(); + + poTimeVal1->fromString("T#3000ms"); + *poWordVal = 40396; + *poStringVal = "HalloWorld"; + *poIntVal = -10934; + *poBoolVal = true; + poTimeVal2->fromString("T#3s22ms"); + + const unsigned int nSerSize = cg_unTimeSerSize + cg_unWordSerSize + cg_unStringHalloWorldSerSize + cg_unIntSerSize + cg_unBoolSerSize + cg_unTimeSerSize; + TForteByte anGoodResult[] = {0x4C, 0, 0, 0, 0, 0, 0x2D, 0xC6, 0xC0, 0x52, 0x9D, 0xCC, 0x50, 0, 0xA, 'H', 'a', 'l', 'l', 'o', 'W', 'o', 'r', 'l', 'd', 0x43, 0xD5, 0x4A, 0x41, 0x4C, 0, 0, 0, 0, 0, 0x2e, 0x1c, 0xb0}; + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(aoArray, 6)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), nSerSize); + BOOST_CHECK(std::equal(anGoodResult, anGoodResult + nSerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + TForteByte acSmallBuf[nSerSize - 1]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, nSerSize - 2, const_cast(poArray), 6), -1); + + //free memory + for(int i = 0; i < 6; ++i){ + poArray[i]->~CIEC_ANY(); + } +} + +BOOST_AUTO_TEST_CASE(Single_Serialize_Test_ARRAY){ + CFBDKASN1ComLayerTestMock nTestee; + CIEC_ARRAY nVal(5, g_nStringIdBOOL); + TIEC_ANYPtr poArray[1]; + poArray[0] = &nVal; + + + static_cast(*nVal[0]) = true; + static_cast(*nVal[1]) = false; + static_cast(*nVal[2]) = false; + static_cast(*nVal[3]) = true; + static_cast(*nVal[4]) = true; + + TForteByte acSmallBuf[7]; + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 1, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 3, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPointArray(acSmallBuf, 7, const_cast(poArray), 1), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 1, nVal), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 3, nVal), -1); + BOOST_CHECK_EQUAL(nTestee.serializeDataPoint(acSmallBuf, 7, nVal), -1); + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unBOOL5SerSize); + BOOST_CHECK(std::equal(cg_abArrayBool10011, cg_abArrayBool10011 + cg_unBOOL5SerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + static_cast(*nVal[0]) = false; + static_cast(*nVal[1]) = true; + static_cast(*nVal[2]) = false; + static_cast(*nVal[3]) = true; + static_cast(*nVal[4]) = false; + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nVal, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unBOOL5SerSize); + BOOST_CHECK(std::equal(cg_abArrayBool01010, cg_abArrayBool01010 + cg_unBOOL5SerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + + CIEC_ARRAY nSIntArray(4, g_nStringIdSINT); + + static_cast(*nSIntArray[0]) = -128; + static_cast(*nSIntArray[1]) = 127; + static_cast(*nSIntArray[2]) = 0; + static_cast(*nSIntArray[3]) = -90; + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nSIntArray, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unSINT4SerSize); + BOOST_CHECK(std::equal(cg_abArraySINTm128_127_0_m90, cg_abArraySINTm128_127_0_m90 + cg_unSINT4SerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + static_cast(*nSIntArray[0]) = -90; + static_cast(*nSIntArray[1]) = 90; + static_cast(*nSIntArray[2]) = 127; + static_cast(*nSIntArray[3]) = 0; + + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nSIntArray, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unSINT4SerSize); + BOOST_CHECK(std::equal(cg_abArraySINTm90_90_127_0, cg_abArraySINTm90_90_127_0 + cg_unSINT4SerSize, ((TForteByte *)nTestee.getSendDataPtr()))); + + CIEC_ARRAY nStringArray(2, g_nStringIdSTRING); + + static_cast(*nStringArray[1]) = "HalloWorld"; + BOOST_CHECK_EQUAL(forte::com_infra::e_ProcessDataOk, nTestee.sendData(&nStringArray, 1)); + BOOST_CHECK_EQUAL(nTestee.getSendDataSize(), cg_unString2SerSize); + BOOST_CHECK(std::equal(cg_abArrayStringEmptyHalloWorld, cg_abArrayStringEmptyHalloWorld + cg_unString2SerSize, ((TForteByte *)nTestee.getSendDataPtr()))); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_ANY_tests.cpp b/tests/core/datatypes/CIEC_ANY_tests.cpp new file mode 100644 index 000000000..7921a3bab --- /dev/null +++ b/tests/core/datatypes/CIEC_ANY_tests.cpp @@ -0,0 +1,219 @@ +/******************************************************************************* + * Copyright (c) 2013 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Monika Wenger - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "../../../src/core/datatypes/forte_any.h" + +BOOST_AUTO_TEST_SUITE(CIEC_ARRAY_function_test) + BOOST_AUTO_TEST_CASE(Type_test){ + CIEC_ANY *poTest = CIEC_ANY::createDataType(0); + BOOST_CHECK_EQUAL(poTest->getDataTypeID(), CIEC_ANY::e_ANY); + delete poTest; + } + + BOOST_AUTO_TEST_CASE(Conversion_test){ + CIEC_ANY *poTest = CIEC_ANY::createDataType(0); + char cBuffer[20]; + BOOST_CHECK_EQUAL(poTest->fromString("Any string is invalid in this case"), -1); + BOOST_CHECK_EQUAL(poTest->toString(cBuffer, 20), strlen("ND (ANY)")); + BOOST_CHECK_EQUAL(0, strcmp(cBuffer, "ND (ANY)")); + delete poTest; + } + + BOOST_AUTO_TEST_CASE(Any_Typisation_negativtest){ + CIEC_ANY *poTest = CIEC_ANY::createDataType(0); + + BOOST_CHECK_EQUAL(poTest->fromString("Hansi#Any string is invalid in this case"), -1); + BOOST_CHECK_EQUAL(poTest->getDataTypeID(), CIEC_ANY::e_ANY); + + BOOST_CHECK_EQUAL(poTest->fromString("E_RESTART#Any string is invalid in this case"), -1); + BOOST_CHECK_EQUAL(poTest->getDataTypeID(), CIEC_ANY::e_ANY); + delete poTest; + } + + void checkTypisation(CIEC_ANY &pa_roTestee, const char* pa_acString, CIEC_ANY::EDataTypeID pa_eTypeId){ + BOOST_CHECK_EQUAL(pa_roTestee.fromString(pa_acString), strlen(pa_acString)); + BOOST_CHECK_EQUAL(pa_roTestee.getDataTypeID(), pa_eTypeId); + } + + BOOST_AUTO_TEST_CASE(Any_Typisation_test){ + CIEC_ANY *poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "BOOL#TRUE", CIEC_ANY::e_BOOL); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "SINT#123", CIEC_ANY::e_SINT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "INT#5754", CIEC_ANY::e_INT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "DINT#112323", CIEC_ANY::e_DINT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "USINT#255", CIEC_ANY::e_USINT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "UINT#25754", CIEC_ANY::e_UINT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "UDINT#3112323", CIEC_ANY::e_UDINT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "BYTE#253", CIEC_ANY::e_BYTE); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "WORD#25754", CIEC_ANY::e_WORD); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "DWORD#3112323", CIEC_ANY::e_DWORD); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "DATE#2008-04-03", CIEC_ANY::e_DATE); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "TIME_OF_DAY#15:36:55.36", CIEC_ANY::e_TIME_OF_DAY); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "DATE_AND_TIME#1994-06-22-14:23:54.8", CIEC_ANY::e_DATE_AND_TIME); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "TIME#311ms", CIEC_ANY::e_TIME); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "REAL#3.125", CIEC_ANY::e_REAL); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "LREAL#3.1251234", CIEC_ANY::e_LREAL); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "STRING#Hallo FORTE user!", CIEC_ANY::e_STRING); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "WSTRING#Hallo FORTE user!", CIEC_ANY::e_WSTRING); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "LINT#123123123123", CIEC_ANY::e_LINT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "ULINT#123123123123123", CIEC_ANY::e_ULINT); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkTypisation(*poTestee, "LWORD#123123123123123", CIEC_ANY::e_LWORD); + delete poTestee; + + } + + void checkSaveWrongTypisation(CIEC_ANY &pa_roTestee, const char* pa_acString){ + BOOST_CHECK_EQUAL(pa_roTestee.fromString(pa_acString), -1); + BOOST_CHECK_EQUAL(pa_roTestee.getDataTypeID(), CIEC_ANY::e_ANY); + } + + BOOST_AUTO_TEST_CASE(Any_SaveWrongTypisation_test){ + CIEC_ANY *poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "BOOL#231"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "SINT#-130"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "INT#40000"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "DINT#411232312345"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "USINT#257"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "UINT#6257541235"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "UDINT#7311232312325346"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "BYTE#256"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "WORD#62575412345"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "DWORD#831123235938695"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "DATE#tes2008-04"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "TIME_OF_DAY#test15:36.36"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "DATE_AND_TIME#Test-06-22-54.8"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "TIME#Test"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "REAL#test"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "LREAL#hansi"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "LINT#1231231231239485692939293"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "ULINT#1231231231927598267926798546723123"); + delete poTestee; + + poTestee = CIEC_ANY::createDataType(0); + checkSaveWrongTypisation(*poTestee, "LWORD#823123123123123123468"); + delete poTestee; + } + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_ARRAY_test.cpp b/tests/core/datatypes/CIEC_ARRAY_test.cpp new file mode 100644 index 000000000..c0fa1de3d --- /dev/null +++ b/tests/core/datatypes/CIEC_ARRAY_test.cpp @@ -0,0 +1,333 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2015 ACIN, fortiss GmbH, Profactor, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl, Micheal Hofmann, Stanislav Meduna, Ingo Hegny - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_array.h" +#include "../../../src/core/datatypes/forte_bool.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +#include "../../../src/core/typelib.h" + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "CIEC_ARRAY_test_gen.cpp" +#endif + +BOOST_AUTO_TEST_SUITE(CIEC_ARRAY_function_test) +BOOST_AUTO_TEST_CASE(Array_assignment_test_BOOL) +{ + CIEC_ARRAY nTest(3, g_nStringIdBOOL); + + BOOST_CHECK_EQUAL(nTest.size(), 3); + BOOST_CHECK_EQUAL(nTest.getElementDataTypeID(), CIEC_ANY::e_BOOL); + BOOST_CHECK_EQUAL(nTest[0]->getDataTypeID(), CIEC_ANY::e_BOOL); + BOOST_CHECK_EQUAL(nTest[1]->getDataTypeID(), CIEC_ANY::e_BOOL); + BOOST_CHECK_EQUAL(nTest[2]->getDataTypeID(), CIEC_ANY::e_BOOL); + + static_cast(*nTest[0]) = true; + static_cast(*nTest[1]) = false; + static_cast(*nTest[2]) = true; + + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), true); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), false); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), true); + + static_cast(*nTest[0]) = false; + static_cast(*nTest[1]) = false; + static_cast(*nTest[2]) = true; + + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), false); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), false); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), true); + + static_cast(*nTest[0]) = true; + static_cast(*nTest[1]) = false; + static_cast(*nTest[2]) = false; + + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), true); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), false); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), false); +} + +BOOST_AUTO_TEST_CASE(Array_assignment_test_INT) +{ + CIEC_ARRAY nTest(5, g_nStringIdINT); + + BOOST_CHECK_EQUAL(nTest.size(), 5); + + BOOST_CHECK_EQUAL(nTest[0]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL(nTest[1]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL(nTest[2]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL(nTest[3]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL(nTest[4]->getDataTypeID(), CIEC_ANY::e_INT); + + static_cast(*nTest[0]) = 1; + static_cast(*nTest[1]) = -32259; + static_cast(*nTest[2]) = 256; + static_cast(*nTest[3]) = -32259; + static_cast(*nTest[4]) = 256; + + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), 1); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), -32259); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), 256); + BOOST_CHECK_EQUAL(static_cast(*nTest[3]), -32259); + BOOST_CHECK_EQUAL(static_cast(*nTest[4]), 256); + BOOST_CHECK((0 == nTest[5])); +} + +BOOST_AUTO_TEST_CASE(Array_assignment_test_array) +{ + CIEC_ARRAY nTest(5, g_nStringIdINT); + char acBuffer[30]; + + BOOST_CHECK_EQUAL(nTest.fromString("[1,2,3,4,5]"), 11); + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), 1); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), 2); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), 3); + BOOST_CHECK_EQUAL(static_cast(*nTest[3]), 4); + BOOST_CHECK_EQUAL(static_cast(*nTest[4]), 5); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 30), 11); + BOOST_CHECK_EQUAL(strcmp(acBuffer, "[1,2,3,4,5]"), 0); + + BOOST_CHECK_EQUAL(nTest.fromString("[3,1,2]"), 7); + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), 3); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), 1); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), 2); + BOOST_CHECK_EQUAL(static_cast(*nTest[3]), 0); + BOOST_CHECK_EQUAL(static_cast(*nTest[4]), 0); + + BOOST_CHECK_EQUAL(nTest.fromString("[3,1,2,4]"), 9); + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), 3); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), 1); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), 2); + BOOST_CHECK_EQUAL(static_cast(*nTest[3]), 4); + BOOST_CHECK_EQUAL(static_cast(*nTest[4]), 0); + + BOOST_CHECK_EQUAL(nTest.fromString("[3,1,2,4,7,8]"), 13); + BOOST_CHECK_EQUAL(static_cast(*nTest[0]), 3); + BOOST_CHECK_EQUAL(static_cast(*nTest[1]), 1); + BOOST_CHECK_EQUAL(static_cast(*nTest[2]), 2); + BOOST_CHECK_EQUAL(static_cast(*nTest[3]), 4); + BOOST_CHECK_EQUAL(static_cast(*nTest[4]), 7); + + BOOST_CHECK_EQUAL(nTest.fromString("[3,1,2"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10,20,30,40,50"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10.0,20,30,40,50"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10,20,test,40,50"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("wrong string"), -1); + +} + + +BOOST_AUTO_TEST_CASE(Array_copy_test){ + CIEC_ARRAY nTest1(5, g_nStringIdINT); + CIEC_ARRAY nTest2(5, g_nStringIdINT); + + //TODO think on implementing array assignment +// BOOST_CHECK_EQUAL(nTest1.fromString("[1,2,3,4,5]"), true); +// nTest2 = nTest1; +// BOOST_CHECK_EQUAL(static_cast(*nTest2[0]), 1); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[1]), 2); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[2]), 3); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[3]), 4); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[4]), 5); +// +// BOOST_CHECK_EQUAL(nTest1.fromString("[5,4,2,3,1]"), true); +// ntest2 = nTest1; +// BOOST_CHECK_EQUAL(static_cast(*nTest2[0]), 5); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[1]), 4); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[2]), 2); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[3]), 3); +// BOOST_CHECK_EQUAL(static_cast(*nTest2[4]), 1); + + BOOST_CHECK_EQUAL(nTest2.fromString("[1,2,3,4,5]"), 11); +// BOOST_CHECK_EQUAL(static_cast(*nTest1[0]), 5); +// BOOST_CHECK_EQUAL(static_cast(*nTest1[1]), 4); +// BOOST_CHECK_EQUAL(static_cast(*nTest1[2]), 2); +// BOOST_CHECK_EQUAL(static_cast(*nTest1[3]), 3); +// BOOST_CHECK_EQUAL(static_cast(*nTest1[4]), 1); + + nTest1.setValue(nTest2); + BOOST_CHECK_EQUAL(static_cast(*nTest1[0]), 1); + BOOST_CHECK_EQUAL(static_cast(*nTest1[1]), 2); + BOOST_CHECK_EQUAL(static_cast(*nTest1[2]), 3); + BOOST_CHECK_EQUAL(static_cast(*nTest1[3]), 4); + BOOST_CHECK_EQUAL(static_cast(*nTest1[4]), 5); + + BOOST_CHECK_EQUAL(nTest2.fromString("[5,4,2,3,1]"), 11); + BOOST_CHECK_EQUAL(static_cast(*nTest1[0]), 1); + BOOST_CHECK_EQUAL(static_cast(*nTest1[1]), 2); + BOOST_CHECK_EQUAL(static_cast(*nTest1[2]), 3); + BOOST_CHECK_EQUAL(static_cast(*nTest1[3]), 4); + BOOST_CHECK_EQUAL(static_cast(*nTest1[4]), 5); +} + + +BOOST_AUTO_TEST_CASE(Configure_test){ + CIEC_ARRAY *pTest = static_cast(CTypeLib::createDataTypeInstance(g_nStringIdARRAY, 0)); + + pTest->setup(8, g_nStringIdINT); + + BOOST_CHECK_EQUAL(pTest->size(), 8); + + BOOST_CHECK_EQUAL((*pTest)[0]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL((*pTest)[1]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL((*pTest)[2]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL((*pTest)[3]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL((*pTest)[4]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL((*pTest)[5]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL((*pTest)[6]->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL((*pTest)[7]->getDataTypeID(), CIEC_ANY::e_INT); + + static_cast(*(*pTest)[0]) = 1; + static_cast(*(*pTest)[1]) = -32259; + static_cast(*(*pTest)[2]) = 256; + static_cast(*(*pTest)[4]) = -32259; + static_cast(*(*pTest)[7]) = 256; + + BOOST_CHECK_EQUAL(static_cast(*(*pTest)[0]), 1); + BOOST_CHECK_EQUAL(static_cast(*(*pTest)[1]), -32259); + BOOST_CHECK_EQUAL(static_cast(*(*pTest)[2]), 256); + BOOST_CHECK_EQUAL(static_cast(*(*pTest)[4]), -32259); + BOOST_CHECK_EQUAL(static_cast(*(*pTest)[7]), 256); + + pTest->setup(15, g_nStringIdSTRING); + BOOST_CHECK_EQUAL(pTest->size(), 15); + + BOOST_CHECK_EQUAL((*pTest)[0]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[1]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[2]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[3]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[4]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[5]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[6]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[7]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[8]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[9]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[10]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[11]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[12]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[13]->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL((*pTest)[14]->getDataTypeID(), CIEC_ANY::e_STRING); + + static_cast(*(*pTest)[0]) = "Hansi"; + BOOST_CHECK_EQUAL(static_cast(*(*pTest)[0]).length(), 5); + BOOST_CHECK_EQUAL(strcmp("Hansi", static_cast(*(*pTest)[0]).getValue()), 0); + + delete pTest; +} + +BOOST_AUTO_TEST_CASE(Array_fromString_StringArrayTest) +{ + CIEC_ARRAY nTest(3, g_nStringIdSTRING); + const char cTestString1[] = {"[\'String 1\',\'String 2\',\'String 3\']"}; + const char cTestString2[] = {"[\'String 1\']"}; + const char cTestString2fromStringResult[] = {"[\'String 1\',\'\',\'\']"}; + const char cTestString3[] = {"[\'String 10\',\'String 20\',\'String 30\',\'String 4\',\'String 5\']"}; + const char cTestString3fromStringResult[] = {"[\'String 10\',\'String 20\',\'String 30\']"}; + const char cTestString4[] = {"[\'String 1\',\'String 2\',\'String 3]"}; + const char cTestString5[] = {"[\'String $$1\',\'String $\'2\',\'String $\"3\']"}; + + char acBuffer[50]; + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString1), strlen(cTestString1)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String 1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), "String 2"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), "String 3"), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString1)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString1), 0); + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString2), strlen(cTestString2)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String 1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), ""), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), ""), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString2fromStringResult)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString2fromStringResult), 0); + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString3), strlen(cTestString3)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String 10"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), "String 20"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), "String 30"), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString3fromStringResult)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString3fromStringResult), 0); + + CIEC_ARRAY nTest2(3, g_nStringIdSTRING); + BOOST_CHECK_EQUAL(nTest2.fromString(cTestString4), -1); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest2[0]).getValue(), "String 1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest2[1]).getValue(), "String 2"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest2[2]).getValue(), ""), 0); + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString5), strlen(cTestString5)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String $1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), "String \'2"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), "String \"3"), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString5)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString5), 0); +} + +BOOST_AUTO_TEST_CASE(Array_fromString_WStringArrayTest) +{ + CIEC_ARRAY nTest(3, g_nStringIdWSTRING); + const char cTestString1[] = {"[\"String 1\",\"String 2\",\"String 3\"]"}; + const char cTestString2[] = {"[\"String 1\"]"}; + const char cTestString2fromStringResult[] = {"[\"String 1\",\"\",\"\"]"}; + const char cTestString3[] = {"[\"String 10\",\"String 20\",\"String 30\",\"String 4\",\"String 5\"]"}; + const char cTestString3fromStringResult[] = {"[\"String 10\",\"String 20\",\"String 30\"]"}; + const char cTestString4[] = {"[\"String 1\",\"String 2\",\"String 3]"}; + const char cTestString5[] = {"[\"String $$1\",\"String $\'2\",\"String $\"3\"]"}; + + char acBuffer[50]; + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString1), strlen(cTestString1)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String 1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), "String 2"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), "String 3"), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString1)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString1), 0); + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString2), strlen(cTestString2)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String 1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), ""), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), ""), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString2fromStringResult)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString2fromStringResult), 0); + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString3), strlen(cTestString3)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String 10"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), "String 20"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), "String 30"), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString3fromStringResult)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString3fromStringResult), 0); + + CIEC_ARRAY nTest2(3, g_nStringIdWSTRING); + BOOST_CHECK_EQUAL(nTest2.fromString(cTestString4), -1); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest2[0]).getValue(), "String 1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest2[1]).getValue(), "String 2"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest2[2]).getValue(), ""), 0); + + BOOST_CHECK_EQUAL(nTest.fromString(cTestString5), strlen(cTestString5)); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[0]).getValue(), "String $1"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[1]).getValue(), "String \'2"), 0); + BOOST_CHECK_EQUAL(strcmp(static_cast(*nTest[2]).getValue(), "String \"3"), 0); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 2), -1); + BOOST_CHECK_EQUAL(nTest.toString(acBuffer, 50), strlen(cTestString5)); + BOOST_CHECK_EQUAL(strcmp(acBuffer, cTestString5), 0); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_BOOL_CASTS_test.cpp b/tests/core/datatypes/CIEC_BOOL_CASTS_test.cpp new file mode 100644 index 000000000..b1eae0617 --- /dev/null +++ b/tests/core/datatypes/CIEC_BOOL_CASTS_test.cpp @@ -0,0 +1,244 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_BOOL_casts_function_test) + +BOOST_AUTO_TEST_CASE(CASTS_BOOL_to_BITS) +{ + CIEC_BOOL bTestBool_true; + CIEC_BOOL bTestBool_false; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + + //initial value must be 0 = false + BOOST_CHECK_EQUAL(bTestBool_false, false); + BOOST_CHECK_EQUAL(bTestBool_true, false); + + bTestBool_false=false; + bTestBool_true=true; + + BOOST_CHECK_EQUAL(bTestBool_true, true); + +//toByte + nTestByte.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestByte, 1U); + +//toWord + nTestWord.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestWord, 1U); + +//toDWord + nTestDWord.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toDWord + nTestLWord.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_BOOL_to_INTS) +{ + CIEC_BOOL bTestBool_true; + CIEC_BOOL bTestBool_false; + + CIEC_SINT nTestSInt; + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //initial value must be 0 = false + BOOST_CHECK_EQUAL(bTestBool_false, false); + BOOST_CHECK_EQUAL(bTestBool_true, false); + + bTestBool_false=false; + bTestBool_true=true; + + BOOST_CHECK_EQUAL(bTestBool_true, true); + +//toSINT + nTestSInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestSInt, 1); + +//toUSINT + nTestUSInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + +//toINT + nTestInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestInt, 1); + +//toUINT + nTestUInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + +//toDINT + nTestDInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestDInt, 1); + +//toUINT + nTestUDInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + +//toULINT + nTestULInt.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_BOOL_to_REAL) +{ + CIEC_BOOL bTestBool_true; + CIEC_BOOL bTestBool_false; + CIEC_REAL nTestReal; + + //initial value must be 0 = false + BOOST_CHECK_EQUAL(bTestBool_false, false); + BOOST_CHECK_EQUAL(bTestBool_true, false); + + bTestBool_false=false; + bTestBool_true=true; + + BOOST_CHECK_EQUAL(bTestBool_true, true); + +//toREAL + nTestReal.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(bTestBool_false); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(bTestBool_true); + BOOST_CHECK_EQUAL(1.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(BOOL_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BOOL, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_BOOL_test.cpp b/tests/core/datatypes/CIEC_BOOL_test.cpp new file mode 100644 index 000000000..36b1ee0fd --- /dev/null +++ b/tests/core/datatypes/CIEC_BOOL_test.cpp @@ -0,0 +1,122 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_bool.h" + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_BOOL_function_test) + + BOOST_AUTO_TEST_CASE(Type_test){ + CIEC_BOOL bTest; + //check type information + BOOST_CHECK_EQUAL(bTest.getDataTypeID(), CIEC_ANY::e_BOOL); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(bTest.operator bool()), sizeof(bool)); + + } + + BOOST_AUTO_TEST_CASE(Assignment_test){ + CIEC_BOOL bTest1; + CIEC_BOOL bTest2; + + //initial value must be 0 = false + BOOST_CHECK_EQUAL(bTest1, false); + + bTest1 = true; + bTest2 = bTest1; + BOOST_CHECK_EQUAL(bTest1, true); + BOOST_CHECK_EQUAL(bTest2, true); + + bTest1 = false; + bTest2 = bTest1; + BOOST_CHECK_EQUAL(bTest1, false); + BOOST_CHECK_EQUAL(bTest2, false); + + //check that assignment operator does not intertwine objects + bTest2 = true; + BOOST_CHECK_EQUAL(bTest1, false); + BOOST_CHECK_EQUAL(bTest2, true); + + } + + BOOST_AUTO_TEST_CASE(Conversion_test){ + CIEC_BOOL bTest; + char cBuffer1[10]; + char cBuffer2[6]; + char cBuffer3[4]; + char cBuffer4[3]; + + strcpy(cBuffer1, ""); + strcpy(cBuffer2, ""); + strcpy(cBuffer3, ""); + strcpy(cBuffer4, ""); + + //check cast operator + bTest = true; + BOOST_CHECK_EQUAL(bTest.operator bool(), true); + + bTest = false; + BOOST_CHECK_EQUAL(bTest.operator bool(), false); + + //check toString and fromString + BOOST_CHECK_EQUAL(bTest.fromString("true"), 4); + BOOST_CHECK_EQUAL(bTest, true); + + BOOST_CHECK_EQUAL(bTest.fromString("1"), 1); + BOOST_CHECK_EQUAL(bTest, true); + + BOOST_CHECK_EQUAL(bTest.fromString("TRUE"), 4); + BOOST_CHECK_EQUAL(bTest, true); + + BOOST_CHECK_EQUAL(bTest.fromString("BOOL#FALSE"), strlen("BOOL#FALSE")); + BOOST_CHECK_EQUAL(bTest, false); + + BOOST_CHECK_EQUAL(bTest.fromString("BOOL#TRUE"), strlen("BOOL#TRUE")); + BOOST_CHECK_EQUAL(bTest, true); + + BOOST_CHECK_EQUAL(bTest.toString(cBuffer1,10), 4); + BOOST_CHECK_EQUAL(bTest.toString(cBuffer2,6), 4); + BOOST_CHECK_EQUAL(bTest.toString(cBuffer3,4), -1); + BOOST_CHECK_EQUAL(bTest.toString(cBuffer4,3), -1); + + BOOST_CHECK_EQUAL(strcmp(cBuffer1, "TRUE"), 0); + BOOST_CHECK_EQUAL(strcmp(cBuffer2, "TRUE"), 0); + + strcpy(cBuffer1, ""); + strcpy(cBuffer2, ""); + strcpy(cBuffer3, ""); + strcpy(cBuffer4, ""); + + BOOST_CHECK_EQUAL(bTest.fromString("FALSE"), 5); + BOOST_CHECK_EQUAL(bTest, false); + + BOOST_CHECK_EQUAL(bTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(bTest, false); + + BOOST_CHECK_EQUAL(bTest.fromString("false"), 5); + BOOST_CHECK_EQUAL(bTest, false); + + BOOST_CHECK_EQUAL(bTest.toString(cBuffer1,10), 5); + BOOST_CHECK_EQUAL(bTest.toString(cBuffer2,6), 5); + BOOST_CHECK_EQUAL(bTest.toString(cBuffer3,4), -1); + BOOST_CHECK_EQUAL(bTest.toString(cBuffer4,3), -1); + + BOOST_CHECK_EQUAL(strcmp(cBuffer1, "FALSE"), 0); + BOOST_CHECK_EQUAL(strcmp(cBuffer2, "FALSE"), 0); + + //check invalid fromString string + + BOOST_CHECK_EQUAL(bTest.fromString("NOT A VALID STRING"), -1); + + } + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_BYTE_CASTS_test.cpp b/tests/core/datatypes/CIEC_BYTE_CASTS_test.cpp new file mode 100644 index 000000000..bd1527d3c --- /dev/null +++ b/tests/core/datatypes/CIEC_BYTE_CASTS_test.cpp @@ -0,0 +1,398 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ + +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_BYTE_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_BYTE_to_BOOL) +{ + CIEC_BYTE nTestByte0; + CIEC_BYTE nTestByte1; + CIEC_BYTE nTestByte45; + CIEC_BYTE nTestByte255; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 0U); + BOOST_CHECK_EQUAL(nTestByte45, 0U); + BOOST_CHECK_EQUAL(nTestByte255, 0U); + + nTestByte0=0U; + nTestByte1=1U; + nTestByte45=45U; + nTestByte255=255U; + + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 1U); + BOOST_CHECK_EQUAL(nTestByte45, 45U); + BOOST_CHECK_EQUAL(nTestByte255, 255U); + +//checks + bTestBool.setValue(nTestByte0); + BOOST_CHECK_EQUAL(bTestBool, false); + bTestBool.setValue(nTestByte1); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestByte45); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestByte255); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_BYTE_to_BITDTs) +{ + CIEC_BYTE nTestByte0; + CIEC_BYTE nTestByte1; + CIEC_BYTE nTestByte45; + CIEC_BYTE nTestByte255; + + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 0U); + BOOST_CHECK_EQUAL(nTestByte45, 0U); + BOOST_CHECK_EQUAL(nTestByte255, 0U); + + nTestByte0=0U; + nTestByte1=1U; + nTestByte45=45U; + nTestByte255=255U; + + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 1U); + BOOST_CHECK_EQUAL(nTestByte45, 45U); + BOOST_CHECK_EQUAL(nTestByte255, 255U); + +//toWord + nTestWord.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestWord, 45U); + nTestWord.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestWord, 255U); + +//toDWord + nTestDWord.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestDWord, 45UL); + nTestDWord.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestDWord, 255UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestLWord, 45ULL); + nTestLWord.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestLWord, 255ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_BYTE_to_INTS) +{ + CIEC_BYTE nTestByte0; + CIEC_BYTE nTestByte1; + CIEC_BYTE nTestByte45; + CIEC_BYTE nTestByte255; + + CIEC_SINT nTestSInt; + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 0U); + BOOST_CHECK_EQUAL(nTestByte45, 0U); + BOOST_CHECK_EQUAL(nTestByte255, 0U); + + nTestByte0=0U; + nTestByte1=1U; + nTestByte45=45U; + nTestByte255=255U; + + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 1U); + BOOST_CHECK_EQUAL(nTestByte45, 45U); + BOOST_CHECK_EQUAL(nTestByte255, 255U); + +//toSINT + nTestSInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestSInt, 45); + nTestSInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUSINT + nTestUSInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestUSInt, 45U); + nTestUSInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + + +//toINT + nTestInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestInt, 45); + nTestInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestInt, 255); + +//toUINT + nTestUInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestUInt, 45U); + nTestUInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestUInt, 255U); + +//toDINT + nTestDInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestDInt, 0L); + nTestDInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestDInt, 1L); + nTestDInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestDInt, 45L); + nTestDInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestDInt, 255L); + +//toUDINT + nTestUDInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestUDInt, 45UL); + nTestUDInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestUDInt, 255UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestLInt, 45LL); + nTestLInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestLInt, 255LL); + +//toULINT + nTestULInt.setValue(nTestByte0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestByte1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestByte45); + BOOST_CHECK_EQUAL(nTestULInt, 45ULL); + nTestULInt.setValue(nTestByte255); + BOOST_CHECK_EQUAL(nTestULInt, 255ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_BYTE_to_REAL) +{ + CIEC_BYTE nTestByte0; + CIEC_BYTE nTestByte1; + CIEC_BYTE nTestByte45; + CIEC_BYTE nTestByte255; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 0U); + BOOST_CHECK_EQUAL(nTestByte45, 0U); + BOOST_CHECK_EQUAL(nTestByte255, 0U); + + nTestByte0=0U; + nTestByte1=1U; + nTestByte45=45U; + nTestByte255=255U; + + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 1U); + BOOST_CHECK_EQUAL(nTestByte45, 45U); + BOOST_CHECK_EQUAL(nTestByte255, 255U); + +//toREAL + nTestReal.setValue(nTestByte0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestByte1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestByte45); + BOOST_CHECK_EQUAL(45.0f, nTestReal); + nTestReal.setValue(nTestByte255); + BOOST_CHECK_EQUAL(255.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestByte0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestByte1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestByte45); + BOOST_CHECK_EQUAL(45.0, nTestLReal); + nTestLReal.setValue(nTestByte255); + BOOST_CHECK_EQUAL(255.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + + +BOOST_AUTO_TEST_CASE(CASTS_BYTE_to_TIME) +{ + CIEC_BYTE nTestByte0; + CIEC_BYTE nTestByte1; + CIEC_BYTE nTestByte45; + CIEC_BYTE nTestByte255; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 0U); + BOOST_CHECK_EQUAL(nTestByte45, 0U); + BOOST_CHECK_EQUAL(nTestByte255, 0U); + + nTestByte0=0U; + nTestByte1=1U; + nTestByte45=45U; + nTestByte255=255U; + + BOOST_CHECK_EQUAL(nTestByte0, 0U); + BOOST_CHECK_EQUAL(nTestByte1, 1U); + BOOST_CHECK_EQUAL(nTestByte45, 45U); + BOOST_CHECK_EQUAL(nTestByte255, 255U); + +//toTime + nTestTime.setValue(nTestByte0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestByte1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestByte45); + BOOST_CHECK_EQUAL(45, nTestTime); + nTestTime.setValue(nTestByte255); + BOOST_CHECK_EQUAL(255, nTestTime); +} + +BOOST_AUTO_TEST_CASE(BYTE_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_BYTE, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_BYTE_test.cpp b/tests/core/datatypes/CIEC_BYTE_test.cpp new file mode 100644 index 000000000..6e263aca2 --- /dev/null +++ b/tests/core/datatypes/CIEC_BYTE_test.cpp @@ -0,0 +1,205 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_byte.h" + +BOOST_AUTO_TEST_SUITE(CIEC_BYTE_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_BYTE nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_BYTE); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteByte()), sizeof(TForteByte)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_BYTE nTest1; + CIEC_BYTE nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0); + + nTest1 = 0; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0); + BOOST_CHECK_EQUAL(nTest2, 0); + + nTest1 = 12; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 12); + BOOST_CHECK_EQUAL(nTest2, 12); + + nTest1 = 255; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 255); + BOOST_CHECK_EQUAL(nTest2, 255); + + //check that assignment operator does not intertwine objects + nTest2 = 128; + BOOST_CHECK_EQUAL(nTest1, 255); + BOOST_CHECK_EQUAL(nTest2, 128); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_BYTE nTest; + + char cBuffer[4]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteByte(), 0); + + nTest = 64; + BOOST_CHECK_EQUAL(nTest.operator TForteByte(), 64); + + nTest = 255; + BOOST_CHECK_EQUAL(nTest.operator TForteByte(), 255); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("79"), 2); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1001111"), 9); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#117"), 5); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#4F"), 5); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("255"), 3); + BOOST_CHECK_EQUAL(nTest, 255); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#11111111"), 10); + BOOST_CHECK_EQUAL(nTest, 255); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#377"), 5); + BOOST_CHECK_EQUAL(nTest, 255); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FF"), 5); + BOOST_CHECK_EQUAL(nTest, 255); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("300"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#100101100"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#454"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#12C"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_DATE_AND_TIME_test.cpp b/tests/core/datatypes/CIEC_DATE_AND_TIME_test.cpp new file mode 100644 index 000000000..acdb1e755 --- /dev/null +++ b/tests/core/datatypes/CIEC_DATE_AND_TIME_test.cpp @@ -0,0 +1,206 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_date_and_time.h" + +BOOST_AUTO_TEST_SUITE(CIEC_DATE_AND_TIME_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_DATE_AND_TIME nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_DATE_AND_TIME); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteUInt64()), sizeof(TForteUInt64)); + +} + +BOOST_AUTO_TEST_CASE(Operator_test) +{ + CIEC_DATE_AND_TIME nTest1; + CIEC_DATE_AND_TIME nTest2; + + //check if data type is initialized with value of zero + BOOST_CHECK_EQUAL(nTest1,0ULL); + + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = 9657545ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 9657545ULL); + BOOST_CHECK_EQUAL(nTest2, 9657545ULL); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); + + nTest2 = 564874642ULL; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, 564874642ULL); + + ++nTest2; + BOOST_CHECK_EQUAL(nTest2, 564874643ULL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_DATE_AND_TIME nTest; + + char cBuffer[40]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 0ULL); + + nTest = std::numeric_limits::min(); + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), std::numeric_limits::min()); + + nTest = 4268743213844LL; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 4268743213844ULL); + + nTest = std::numeric_limits::max(); + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), std::numeric_limits::max()); + + //check toString and fromString + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54.8"), 21); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.800"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54"), 19); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.000"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54.1"), 21); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.100"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54.10"), 22); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.100"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54.100"), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.100"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54.12"), 22); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.120"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54.120"), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.120"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22-14:23:54.123"), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.123"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("DATE_AND_TIME#1994-06-22-14:23:54.8"), 35); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.800"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("date_and_time#1994-06-22-14:23:54.8"), 35); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.800"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("DT#1994-06-22-14:23:54.8"), 24); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.800"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("dt#1994-06-22-14:23:54.8"), 24); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22-14:23:54.800"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("2008-04-03-09:05:23.4"), 21); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03-09:05:23.400"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("DATE_AND_TIME#2008-04-03-09:05:23.4"), 35); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03-09:05:23.400"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("date_and_time#2008-04-03-09:05:23.4"), 35); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03-09:05:23.400"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("DT#2008-04-03-09:05:23.4"), 24); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03-09:05:23.400"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("dt#2008-04-03-09:05:23.4"), 24); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 40), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03-09:05:23.400"), 0); + strcpy(cBuffer, ""); + nTest = 0; + +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_DATE_test.cpp b/tests/core/datatypes/CIEC_DATE_test.cpp new file mode 100644 index 000000000..d1f41c530 --- /dev/null +++ b/tests/core/datatypes/CIEC_DATE_test.cpp @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_date.h" + +BOOST_AUTO_TEST_SUITE(CIEC_DATE_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_DATE nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_DATE); + //check operator book data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteUInt64()), sizeof(TForteUInt64)); + +} + +BOOST_AUTO_TEST_CASE(Operator_test) +{ + CIEC_DATE nTest1; + CIEC_DATE nTest2; + + //check if data type is initialized with value of zero + BOOST_CHECK_EQUAL(nTest1,0ULL); + + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = 9657545ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 9657545ULL); + BOOST_CHECK_EQUAL(nTest2, 9657545ULL); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); + + nTest2 = 564874642ULL; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, 564874642ULL); + + ++nTest2; + BOOST_CHECK_EQUAL(nTest2, 564874643ULL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_DATE nTest; + TForteInt32 nTZOffset; + + char cBuffer[11]; + char cBufferFail[2]; + + nTZOffset = CIEC_ANY_DATE::getTimeZoneOffset(); + BOOST_CHECK_EQUAL(nTZOffset, 60); // Western Europe, adjust if somewhere else + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 0ULL); + + nTest = std::numeric_limits::min(); + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), std::numeric_limits::min()); + + nTest = 4268743213844LL; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 4268743213844ULL); + + nTest = std::numeric_limits::max(); + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), std::numeric_limits::max()); + + //check toString and fromString + strcpy(cBuffer, ""); + + //TODO: Check if this is really a legal literal + BOOST_CHECK_EQUAL(nTest.fromString("1994-06-22"), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("DATE#1994-06-22"), 15); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("date#1994-06-22"), 15); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("D#1994-06-22"), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("d#1994-06-22"), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1994-06-22"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + //TODO: Check if this is really a legal literal + BOOST_CHECK_EQUAL(nTest.fromString("2008-04-03"), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("DATE#2008-04-03"), 15); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("date#2008-04-03"), 15); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("D#2008-04-03"), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("d#2008-04-03"), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2008-04-03"), 0); + strcpy(cBuffer, ""); + + // Check timezone handling + BOOST_CHECK_EQUAL(nTest.fromString("1970-01-01"), 10); + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 0ULL); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_DINT_CASTS_test.cpp b/tests/core/datatypes/CIEC_DINT_CASTS_test.cpp new file mode 100644 index 000000000..325b8d1c9 --- /dev/null +++ b/tests/core/datatypes/CIEC_DINT_CASTS_test.cpp @@ -0,0 +1,411 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_DINT_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_DINT_to_BOOL) +{ + CIEC_DINT nTestDInt0; + CIEC_DINT nTestDInt1; + CIEC_DINT nTestDInt32768; + CIEC_DINT nTestDInt2147483647; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 0); + BOOST_CHECK_EQUAL(nTestDInt32768, 0); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 0); + + nTestDInt0=0; + nTestDInt1=1; + nTestDInt32768=32768; + nTestDInt2147483647=2147483647; + + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 1); + BOOST_CHECK_EQUAL(nTestDInt32768, 32768); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 2147483647); + +//checks + bTestBool.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(false, bTestBool); + bTestBool.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_DINT_to_BITDTs) +{ + CIEC_DINT nTestDInt0; + CIEC_DINT nTestDInt1; + CIEC_DINT nTestDInt32768; + CIEC_DINT nTestDInt2147483647; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 0); + BOOST_CHECK_EQUAL(nTestDInt32768, 0); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 0); + + nTestDInt0=0; + nTestDInt1=1; + nTestDInt32768=32768; + nTestDInt2147483647=2147483647; + + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 1); + BOOST_CHECK_EQUAL(nTestDInt32768, 32768); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 2147483647); + +//toByte + nTestByte.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toWord + nTestWord.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestWord, 32768U); + nTestWord.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestWord, 65535U); + +//toDWord + nTestDWord.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestDWord, 32768UL); + nTestDWord.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestDWord, 2147483647UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestLWord, 32768ULL); + nTestLWord.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestLWord, 2147483647ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_DINT_to_INTS) +{ + CIEC_DINT nTestDInt0; + CIEC_DINT nTestDInt1; + CIEC_DINT nTestDInt32768; + CIEC_DINT nTestDInt2147483647; + CIEC_DINT nTestDInt_1; + + CIEC_USINT nTestUSInt; + CIEC_SINT nTestSInt; + CIEC_UINT nTestUInt; + CIEC_INT nTestInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 0); + BOOST_CHECK_EQUAL(nTestDInt32768, 0); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 0); + BOOST_CHECK_EQUAL(nTestDInt_1, 0); + + nTestDInt0=0; + nTestDInt1=1; + nTestDInt32768=32768; + nTestDInt2147483647=2147483647; + nTestDInt_1=-1; + + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 1); + BOOST_CHECK_EQUAL(nTestDInt32768, 32768); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 2147483647); + BOOST_CHECK_EQUAL(nTestDInt_1, -1); + +//toUSINT + nTestUSInt.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + nTestUSInt.setValue(nTestDInt_1); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + + +//toSINT + nTestSInt.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestSInt, -1); + nTestSInt.setValue(nTestDInt_1); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUINT + nTestUInt.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestUInt, 32768U); + nTestUInt.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + nTestUInt.setValue(nTestDInt_1); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + +//toINT + nTestInt.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestInt, -32768); + nTestInt.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestInt, -1); + nTestInt.setValue(nTestDInt_1); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toUDINT + nTestUDInt.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestUDInt, 0U); + nTestUDInt.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestUDInt, 1U); + nTestUDInt.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestUDInt, 32768U); + nTestUDInt.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestUDInt, 2147483647U); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestLInt, 32768LL); + nTestLInt.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestLInt, 2147483647LL); + nTestLInt.setValue(nTestDInt_1); + BOOST_CHECK_EQUAL(nTestLInt, -1LL); + +//toULINT + nTestULInt.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(nTestULInt, 32768ULL); + nTestULInt.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(nTestULInt, 2147483647ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_DINT_to_REAL) +{ + CIEC_DINT nTestDInt0; + CIEC_DINT nTestDInt1; + CIEC_DINT nTestDInt32768; + CIEC_DINT nTestDInt2147483647; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 0); + BOOST_CHECK_EQUAL(nTestDInt32768, 0); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 0); + + nTestDInt0=0; + nTestDInt1=1; + nTestDInt32768=32768; + nTestDInt2147483647=2147483647; + + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 1); + BOOST_CHECK_EQUAL(nTestDInt32768, 32768); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 2147483647); + +//toREAL + nTestReal.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(32768.0f, nTestReal); + nTestReal.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(2147483647.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(32768.0, nTestLReal); + nTestLReal.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(2147483647.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(CASTS_DINT_to_TIME) +{ + CIEC_DINT nTestDInt0; + CIEC_DINT nTestDInt1; + CIEC_DINT nTestDInt32768; + CIEC_DINT nTestDInt2147483647; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 0); + BOOST_CHECK_EQUAL(nTestDInt32768, 0); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 0); + + nTestDInt0=0; + nTestDInt1=1; + nTestDInt32768=32768; + nTestDInt2147483647=2147483647; + + BOOST_CHECK_EQUAL(nTestDInt0, 0); + BOOST_CHECK_EQUAL(nTestDInt1, 1); + BOOST_CHECK_EQUAL(nTestDInt32768, 32768); + BOOST_CHECK_EQUAL(nTestDInt2147483647, 2147483647); + +//toTIME + nTestTime.setValue(nTestDInt0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestDInt1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestDInt32768); + BOOST_CHECK_EQUAL(32768, nTestTime); + nTestTime.setValue(nTestDInt2147483647); + BOOST_CHECK_EQUAL(2147483647, nTestTime); + +} + +BOOST_AUTO_TEST_CASE(DINT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DINT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_DINT_test.cpp b/tests/core/datatypes/CIEC_DINT_test.cpp new file mode 100644 index 000000000..4b961a76e --- /dev/null +++ b/tests/core/datatypes/CIEC_DINT_test.cpp @@ -0,0 +1,235 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_dint.h" + +BOOST_AUTO_TEST_SUITE(CIEC_DINT_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_DINT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_DINT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteInt32()), sizeof(TForteInt32)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_DINT nTest1; + CIEC_DINT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0); + + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = -896475124; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -896475124); + BOOST_CHECK_EQUAL(nTest2, -896475124); + + nTest1 = 36548; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 36548); + BOOST_CHECK_EQUAL(nTest2, 36548); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); + + //check that assignment operator does not intertwine objects + nTest2 = 6874; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, 6874); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_DINT nTest; + + char cBuffer[12]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), 0); + + nTest = std::numeric_limits::min(); + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), std::numeric_limits::min()); + + nTest = 9853268; + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), 9853268); + + nTest = std::numeric_limits::max(); + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), std::numeric_limits::max()); + + //check toString and fromString + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("-2147483648"), 11); + BOOST_CHECK_EQUAL(-2147483648L, nTest); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-2147483648"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#10000000000000000000000000000000"), 34); + BOOST_CHECK_EQUAL(nTest, -2147483648L); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-2147483648"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#20000000000"), 13); + BOOST_CHECK_EQUAL(nTest, -2147483648L); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-2147483648"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#80000000"), 11); + BOOST_CHECK_EQUAL(nTest, -2147483648L); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-2147483648"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + + + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + strcpy(cBuffer, ""); + + + BOOST_CHECK_EQUAL(nTest.fromString("368745"), 6); + BOOST_CHECK_EQUAL(nTest, 368745); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "368745"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1011010000001101001"), 21); + BOOST_CHECK_EQUAL(nTest, 368745); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "368745"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("8#1320151"), 9); + BOOST_CHECK_EQUAL(nTest, 368745); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "368745"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#5a069"), 8); + BOOST_CHECK_EQUAL(nTest, 368745); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "368745"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("2147483647"), 10); + BOOST_CHECK_EQUAL(nTest, 2147483647); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2147483647"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#01111111111111111111111111111111"), 34); + BOOST_CHECK_EQUAL(nTest, 2147483647); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2147483647"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#17777777777"), 13); + BOOST_CHECK_EQUAL(nTest, 2147483647); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2147483647"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#7FFFFfFF"), 11); + BOOST_CHECK_EQUAL(nTest, 2147483647); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "2147483647"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), 6); + BOOST_CHECK_EQUAL(nTest, 300); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "300"), 0); + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("21474836473"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#1011111111111111111111111111111110"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#177777777770"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#7FFFFFFF0"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-21474836473"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_DWORD_CASTS_test.cpp b/tests/core/datatypes/CIEC_DWORD_CASTS_test.cpp new file mode 100644 index 000000000..ae9b54e7e --- /dev/null +++ b/tests/core/datatypes/CIEC_DWORD_CASTS_test.cpp @@ -0,0 +1,407 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_DWORD_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_DWORD_to_BOOL) +{ + CIEC_DWORD nTestDWord0; + CIEC_DWORD nTestDWord1; + CIEC_DWORD nTestDWord65536; + CIEC_DWORD nTestDWord4294967295; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 0UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 0UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 0UL); + + nTestDWord0=0x00; + nTestDWord1=0x01; + nTestDWord65536=0x010000; + nTestDWord4294967295=0xffffffff; + + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 1UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 65536UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 4294967295UL); + +//checks + bTestBool.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(bTestBool, false); + bTestBool.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(bTestBool, true); + +} + +BOOST_AUTO_TEST_CASE(CASTS_DWORD_to_BITDTs) +{ + CIEC_DWORD nTestDWord0; + CIEC_DWORD nTestDWord1; + CIEC_DWORD nTestDWord65536; + CIEC_DWORD nTestDWord4294967295; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 0UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 0UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 0UL); + + nTestDWord0=0UL; + nTestDWord1=1UL; + nTestDWord65536=65536UL; + nTestDWord4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 1UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 65536UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 4294967295UL); + +//toByte + nTestByte.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toWord + nTestWord.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestWord, 65535U); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestLWord, 65536ULL); + nTestLWord.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestLWord, 4294967295ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_DWORD_to_INTS) +{ + CIEC_DWORD nTestDWord0; + CIEC_DWORD nTestDWord1; + CIEC_DWORD nTestDWord65536; + CIEC_DWORD nTestDWord4294967295; + + CIEC_SINT nTestSInt; + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 0UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 0UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 0UL); + + nTestDWord0=0UL; + nTestDWord1=1UL; + nTestDWord65536=65536UL; + nTestDWord4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 1UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 65536UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 4294967295UL); + +//toSINT + nTestSInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUSINT + nTestUSInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + + +//toINT + nTestInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toUINT + nTestUInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + +//toDINT + nTestDInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestDInt, 0L); + nTestDInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestDInt, 1L); + nTestDInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestDInt, 65536L); + nTestDInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestDInt, -1); + +//toUDINT + nTestUDInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestUDInt, 65536UL); + nTestUDInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestUDInt, 4294967295UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestLInt, 65536LL); + nTestLInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestLInt, 4294967295LL); + +//toULINT + nTestULInt.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(nTestULInt, 65536ULL); + nTestULInt.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(nTestULInt, 4294967295ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_DWORD_to_REAL) +{ + CIEC_DWORD nTestDWord0; + CIEC_DWORD nTestDWord1; + CIEC_DWORD nTestDWord65536; + CIEC_DWORD nTestDWord4294967295; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 0UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 0UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 0UL); + + nTestDWord0=0UL; + nTestDWord1=1UL; + nTestDWord65536=65536UL; + nTestDWord4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 1UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 65536UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 4294967295UL); + +//toREAL + nTestReal.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(65536.0f, nTestReal); + nTestReal.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(4294967295.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(65536.0, nTestLReal); + nTestLReal.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(4294967295.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(CASTS_DWORD_to_Time) +{ + CIEC_DWORD nTestDWord0; + CIEC_DWORD nTestDWord1; + CIEC_DWORD nTestDWord65536; + CIEC_DWORD nTestDWord4294967295; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 0UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 0UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 0UL); + + nTestDWord0=0UL; + nTestDWord1=1UL; + nTestDWord65536=65536UL; + nTestDWord4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestDWord0, 0UL); + BOOST_CHECK_EQUAL(nTestDWord1, 1UL); + BOOST_CHECK_EQUAL(nTestDWord65536, 65536UL); + BOOST_CHECK_EQUAL(nTestDWord4294967295, 4294967295UL); + +//toTime +#ifdef FORTE_USE_64BIT_DATATYPES + nTestTime.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(0LL, nTestTime); + nTestTime.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(1LL, nTestTime); + nTestTime.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(65536LL, nTestTime); + nTestTime.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(4294967295LL, nTestTime); +#else + nTestTime.setValue(nTestDWord0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestDWord1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestDWord65536); + BOOST_CHECK_EQUAL(65536, nTestTime); + nTestTime.setValue(nTestDWord4294967295); + BOOST_CHECK_EQUAL(-1, nTestTime); +#endif +} + +BOOST_AUTO_TEST_CASE(DWORD_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_DWORD, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_DWORD_test.cpp b/tests/core/datatypes/CIEC_DWORD_test.cpp new file mode 100644 index 000000000..0f690d555 --- /dev/null +++ b/tests/core/datatypes/CIEC_DWORD_test.cpp @@ -0,0 +1,204 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_dword.h" + +BOOST_AUTO_TEST_SUITE(CIEC_DWORD_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_DWORD nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_DWORD); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteDWord()), sizeof(TForteDWord)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_DWORD nTest1; + CIEC_DWORD nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0UL); + + nTest1 = 0; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0UL); + BOOST_CHECK_EQUAL(nTest2, 0UL); + + nTest1 = 87456813UL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 87456813UL); + BOOST_CHECK_EQUAL(nTest2, 87456813UL); + + nTest1 = 4294967295UL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 4294967295UL); + BOOST_CHECK_EQUAL(nTest2, 4294967295UL); + + //check that assignment operator does not intertwine objects + nTest2 = 25432341UL; + BOOST_CHECK_EQUAL(nTest1, 4294967295UL); + BOOST_CHECK_EQUAL(nTest2, 25432341UL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_DWORD nTest; + + char cBuffer[11]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteDWord(), 0UL); + + nTest = 294967295UL; + BOOST_CHECK_EQUAL(nTest.operator TForteDWord(), 294967295UL); + + nTest = 4294967295UL; + BOOST_CHECK_EQUAL(nTest.operator TForteDWord(), 4294967295UL); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("56397517"), 8); + BOOST_CHECK_EQUAL(nTest, 56397517UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 8); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "56397517"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#11010111001000111011001101"), 28); + BOOST_CHECK_EQUAL(nTest, 56397517UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 8); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "56397517"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#327107315"), 11); + BOOST_CHECK_EQUAL(nTest, 56397517UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 8); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "56397517"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#35C8ECD"), 10); + BOOST_CHECK_EQUAL(nTest, 56397517UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 8); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "56397517"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("4294967295"), 10); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#11111111111111111111111111111111"), 34); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#37777777777"), 13); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFFFFFF"), 11); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("5000000000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#100101010000001011111001000000000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#45201371000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#5000000000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#12A05F200"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_INT_CASTS_test.cpp b/tests/core/datatypes/CIEC_INT_CASTS_test.cpp new file mode 100644 index 000000000..4d7a21af6 --- /dev/null +++ b/tests/core/datatypes/CIEC_INT_CASTS_test.cpp @@ -0,0 +1,413 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_INT_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_INT_to_BOOL) +{ + CIEC_INT nTestInt0; + CIEC_INT nTestInt1; + CIEC_INT nTestInt256; + CIEC_INT nTestInt32767; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 0); + BOOST_CHECK_EQUAL(nTestInt256, 0); + BOOST_CHECK_EQUAL(nTestInt32767, 0); + + nTestInt0=0; + nTestInt1=1; + nTestInt256=256; + nTestInt32767=32767; + + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 1); + BOOST_CHECK_EQUAL(nTestInt256, 256); + BOOST_CHECK_EQUAL(nTestInt32767, 32767); + +//checks + bTestBool.setValue(nTestInt0); + BOOST_CHECK_EQUAL(false, bTestBool); + bTestBool.setValue(nTestInt1); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestInt256); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_INT_to_BITDTs) +{ + CIEC_INT nTestInt0; + CIEC_INT nTestInt1; + CIEC_INT nTestInt256; + CIEC_INT nTestInt32767; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 0); + BOOST_CHECK_EQUAL(nTestInt256, 0); + BOOST_CHECK_EQUAL(nTestInt32767, 0); + + nTestInt0=0; + nTestInt1=1; + nTestInt256=256; + nTestInt32767=32767; + + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 1); + BOOST_CHECK_EQUAL(nTestInt256, 256); + BOOST_CHECK_EQUAL(nTestInt32767, 32767); + +//toByte + nTestByte.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toWord + nTestWord.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestWord, 256U); + nTestWord.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestWord, 32767U); + +//toDWord + nTestDWord.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestDWord, 256UL); + nTestDWord.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestDWord, 32767UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestLWord, 256ULL); + nTestLWord.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestLWord, 32767ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_INT_to_INTS) +{ + CIEC_INT nTestInt0; + CIEC_INT nTestInt1; + CIEC_INT nTestInt256; + CIEC_INT nTestInt32767; + CIEC_INT nTestInt_1; + + CIEC_USINT nTestUSInt; + CIEC_SINT nTestSInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 0); + BOOST_CHECK_EQUAL(nTestInt256, 0); + BOOST_CHECK_EQUAL(nTestInt32767, 0); + BOOST_CHECK_EQUAL(nTestInt_1, 0); + + nTestInt0=0; + nTestInt1=1; + nTestInt256=256; + nTestInt32767=32767; + nTestInt_1=-1; + + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 1); + BOOST_CHECK_EQUAL(nTestInt256, 256); + BOOST_CHECK_EQUAL(nTestInt32767, 32767); + BOOST_CHECK_EQUAL(nTestInt_1, -1); + +//toUSINT + nTestUSInt.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + nTestUSInt.setValue(nTestInt_1); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + + +//toSINT + nTestSInt.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUINT + nTestUInt.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestUInt, 256U); + nTestUInt.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestUInt, 32767U); + nTestUInt.setValue(nTestInt_1); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + +//toDINT + nTestDInt.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestDInt, 1); + nTestDInt.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestDInt, 256); + nTestDInt.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestDInt, 32767); + nTestDInt.setValue(nTestInt_1); + BOOST_CHECK_EQUAL(nTestDInt, -1); + +//toUDINT + nTestUDInt.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestUDInt, 256UL); + nTestUDInt.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestUDInt, 32767UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestLInt, 256LL); + nTestLInt.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestLInt, 32767LL); + nTestLInt.setValue(nTestInt_1); + BOOST_CHECK_EQUAL(nTestLInt, -1LL); + +//toULINT + nTestULInt.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestULInt, 256ULL); + nTestULInt.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestULInt, 32767ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_INT_to_REAL) +{ + CIEC_INT nTestInt0; + CIEC_INT nTestInt1; + CIEC_INT nTestInt256; + CIEC_INT nTestInt32767; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 0); + BOOST_CHECK_EQUAL(nTestInt256, 0); + BOOST_CHECK_EQUAL(nTestInt32767, 0); + + nTestInt0=0; + nTestInt1=1; + nTestInt256=256; + nTestInt32767=32767; + + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 1); + BOOST_CHECK_EQUAL(nTestInt256, 256); + BOOST_CHECK_EQUAL(nTestInt32767, 32767); + +//toREAL + nTestReal.setValue(nTestInt0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestInt1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestInt256); + BOOST_CHECK_EQUAL(256.0f, nTestReal); + nTestReal.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(32767.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestInt0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestInt1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestInt256); + BOOST_CHECK_EQUAL(256.0, nTestLReal); + nTestLReal.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(32767.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(CASTS_INT_to_TIME) +{ + CIEC_INT nTestInt0; + CIEC_INT nTestInt1; + CIEC_INT nTestInt256; + CIEC_INT nTestInt32767; + CIEC_INT nTestInt_1; + + CIEC_TIME nTestTime; + + //check initial values + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 0); + BOOST_CHECK_EQUAL(nTestInt256, 0); + BOOST_CHECK_EQUAL(nTestInt32767, 0); + BOOST_CHECK_EQUAL(nTestInt_1, 0); + + nTestInt0=0; + nTestInt1=1; + nTestInt256=256; + nTestInt32767=32767; + nTestInt_1=-1; + + BOOST_CHECK_EQUAL(nTestInt0, 0); + BOOST_CHECK_EQUAL(nTestInt1, 1); + BOOST_CHECK_EQUAL(nTestInt256, 256); + BOOST_CHECK_EQUAL(nTestInt32767, 32767); + BOOST_CHECK_EQUAL(nTestInt_1, -1); + +//toTIME + nTestTime.setValue(nTestInt0); + BOOST_CHECK_EQUAL(nTestTime, 0); + nTestTime.setValue(nTestInt1); + BOOST_CHECK_EQUAL(nTestTime, 1); + nTestTime.setValue(nTestInt256); + BOOST_CHECK_EQUAL(nTestTime, 256); + nTestTime.setValue(nTestInt32767); + BOOST_CHECK_EQUAL(nTestTime, 32767); + nTestTime.setValue(nTestInt_1); + BOOST_CHECK_EQUAL(nTestTime, -1); +} + +BOOST_AUTO_TEST_CASE(INT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_INT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_INT_test.cpp b/tests/core/datatypes/CIEC_INT_test.cpp new file mode 100644 index 000000000..955d11abd --- /dev/null +++ b/tests/core/datatypes/CIEC_INT_test.cpp @@ -0,0 +1,275 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_int.h" + +BOOST_AUTO_TEST_SUITE(CIEC_INT_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_INT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_INT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteInt16()), sizeof(TForteInt16)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_INT nTest1; + CIEC_INT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0); + + nTest1 = -32768; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -32768); + BOOST_CHECK_EQUAL(nTest2, -32768); + + nTest1 = -25789; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -25789); + BOOST_CHECK_EQUAL(nTest2, -25789); + + nTest1 = 15748; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 15748); + BOOST_CHECK_EQUAL(nTest2, 15748); + + nTest1 = 32767; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 32767); + BOOST_CHECK_EQUAL(nTest2, 32767); + + //check that assignment operator does not intertwine objects + nTest2 = -36; + BOOST_CHECK_EQUAL(nTest1, 32767); + BOOST_CHECK_EQUAL(nTest2, -36); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_INT nTest; + + char cBuffer[7]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteInt16(), 0); + + nTest = -32768; + BOOST_CHECK_EQUAL(nTest.operator TForteInt16(), -32768); + + nTest = 6984; + BOOST_CHECK_EQUAL(nTest.operator TForteInt16(), 6984); + + nTest = 32767; + BOOST_CHECK_EQUAL(nTest.operator TForteInt16(), 32767); + + //check toString and fromString + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("-32768"), 6); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.fromString("INT#-32768"), 10); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-32768"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1000000000000000"), 18); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.fromString("INT#2#1000000000000000"), 22); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-32768"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#100000"), 8); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.fromString("INT#8#100000"), 12); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-32768"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#8000"), 7); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.fromString("INT#16#8000"), 11); + BOOST_CHECK_EQUAL(nTest, -32768); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-32768"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + BOOST_CHECK_EQUAL(nTest.fromString("16#ffff"), 7); + BOOST_CHECK_EQUAL(nTest, -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.fromString("INT#2#0"), 7); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.fromString("INT#8#0"), 7); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + + BOOST_CHECK_EQUAL(nTest.fromString("99"), 2); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.fromString("INT#99"), 6); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1100011"), 9); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("8#143"), 5); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#63"), 5); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("32767"), 5); + BOOST_CHECK_EQUAL(nTest, 32767); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "32767"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#0111111111111111"), 18); + BOOST_CHECK_EQUAL(nTest, 32767); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "32767"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#77777"), 7); + BOOST_CHECK_EQUAL(nTest, 32767); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "32767"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#7FFF"), 7); + BOOST_CHECK_EQUAL(nTest, 32767); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "32767"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), 6); + BOOST_CHECK_EQUAL(nTest, 300); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "300"), 0); + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("40000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#100101100100101101"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#1161007"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFF0"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-40000"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_LINT_CASTS_test.cpp b/tests/core/datatypes/CIEC_LINT_CASTS_test.cpp new file mode 100644 index 000000000..8ad8b5cbb --- /dev/null +++ b/tests/core/datatypes/CIEC_LINT_CASTS_test.cpp @@ -0,0 +1,419 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, nxtControl, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifdef FORTE_USE_64BIT_DATATYPES +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + + + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE + + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_LINT_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_LINT_to_BOOL) +{ + CIEC_LINT nTestLInt0; + CIEC_LINT nTestLInt1; + CIEC_LINT nTestLInt2147483648; + CIEC_LINT nTestLInt9223372036854775807; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 0); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 0); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 0); + + nTestLInt0=0; + nTestLInt1=1; + nTestLInt2147483648=2147483648LL; + nTestLInt9223372036854775807=9223372036854775807LL; + + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 1); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 2147483648LL); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 9223372036854775807LL); + +//checks + bTestBool.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(false, bTestBool); + bTestBool.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_LINT_to_BITDTs) +{ + CIEC_LINT nTestLInt0; + CIEC_LINT nTestLInt1; + CIEC_LINT nTestLInt2147483648; + CIEC_LINT nTestLInt9223372036854775807; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; + CIEC_LWORD nTestLWord; + +//check initial values + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 0); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 0); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 0); + + nTestLInt0=0; + nTestLInt1=1; + nTestLInt2147483648=2147483648LL; + nTestLInt9223372036854775807=9223372036854775807LL; + + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 1); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 2147483648LL); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 9223372036854775807LL); + +//toByte + nTestByte.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toWord + nTestWord.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestWord, 65535U); + +//toDWord + nTestDWord.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestDWord, 2147483648UL); + nTestDWord.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestDWord, 4294967295UL); + + +//toLWord + nTestLWord.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestLWord, 2147483648ULL); + nTestLWord.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestLWord, 9223372036854775807ULL); + +} + +BOOST_AUTO_TEST_CASE(CASTS_LINT_to_INTS) +{ + CIEC_LINT nTestLInt0; + CIEC_LINT nTestLInt1; + CIEC_LINT nTestLInt2147483648; + CIEC_LINT nTestLInt9223372036854775807; + CIEC_LINT nTestLInt_1; + + CIEC_USINT nTestUSInt; + CIEC_SINT nTestSInt; + CIEC_UINT nTestUInt; + CIEC_INT nTestInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; + CIEC_ULINT nTestULInt; + + //check initial values + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 0); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 0); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 0); + BOOST_CHECK_EQUAL(nTestLInt_1, 0); + + nTestLInt0=0; + nTestLInt1=1; + nTestLInt2147483648=2147483648LL; + nTestLInt9223372036854775807=9223372036854775807LL; + nTestLInt_1=-1LL; + + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 1); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 2147483648LL); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 9223372036854775807LL); + BOOST_CHECK_EQUAL(nTestLInt_1, -1); + +//toUSINT + nTestUSInt.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + nTestUSInt.setValue(nTestLInt_1); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + + +//toSINT + nTestSInt.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestSInt, -1); + nTestSInt.setValue(nTestLInt_1); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUINT + nTestUInt.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + nTestUInt.setValue(nTestLInt_1); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + +//toINT + nTestInt.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestInt, -1); + nTestInt.setValue(nTestLInt_1); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toDINT + nTestDInt.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestDInt, 1); + nTestDInt.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestDInt, -2147483648LL); + nTestDInt.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestDInt, -1); + nTestDInt.setValue(nTestLInt_1); + BOOST_CHECK_EQUAL(nTestDInt, -1); + + //toUDINT + nTestUDInt.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestUDInt, 2147483648UL); + nTestUDInt.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestUDInt, 4294967295UL); + + +//toULINT + nTestULInt.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(nTestULInt, 2147483648ULL); + nTestULInt.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(nTestULInt, 9223372036854775807ULL); + nTestULInt.setValue(nTestLInt_1); + BOOST_CHECK_EQUAL(nTestULInt, 18446744073709551615ULL); + +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_LINT_to_REAL) +{ + CIEC_LINT nTestLInt0; + CIEC_LINT nTestLInt1; + CIEC_LINT nTestLInt2147483648; + CIEC_LINT nTestLInt9223372036854775807; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 0); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 0); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 0); + + nTestLInt0=0LL; + nTestLInt1=1LL; + nTestLInt2147483648=2147483648LL; + nTestLInt9223372036854775807=9223372036854775807LL; + + BOOST_CHECK_EQUAL(nTestLInt0, 0LL); + BOOST_CHECK_EQUAL(nTestLInt1, 1LL); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 2147483648LL); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 9223372036854775807LL); + +//toREAL + nTestReal.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(2147483648.0f, nTestReal); + nTestReal.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(9223372036854775807.0f, nTestReal); + + + + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(2147483648.0, nTestLReal); + nTestLReal.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(9223372036854775807.0, nTestLReal); + + +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(CASTS_LINT_to_TIME) +{ + CIEC_LINT nTestLInt0; + CIEC_LINT nTestLInt1; + CIEC_LINT nTestLInt2147483648; + CIEC_LINT nTestLInt9223372036854775807; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestLInt0, 0); + BOOST_CHECK_EQUAL(nTestLInt1, 0); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 0); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 0); + + nTestLInt0=0LL; + nTestLInt1=1LL; + nTestLInt2147483648=2147483648LL; + nTestLInt9223372036854775807=9223372036854775807LL; + + BOOST_CHECK_EQUAL(nTestLInt0, 0LL); + BOOST_CHECK_EQUAL(nTestLInt1, 1LL); + BOOST_CHECK_EQUAL(nTestLInt2147483648, 2147483648LL); + BOOST_CHECK_EQUAL(nTestLInt9223372036854775807, 9223372036854775807LL); + +//toTIME +#ifdef FORTE_USE_64BIT_DATATYPES + nTestTime.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(0L, nTestTime); + nTestTime.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(1L, nTestTime); + nTestTime.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(2147483648LL, nTestTime); + nTestTime.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(9223372036854775807LL, nTestTime); +#else + nTestTime.setValue(nTestLInt0); + BOOST_CHECK_EQUAL(0L, nTestTime); + nTestTime.setValue(nTestLInt1); + BOOST_CHECK_EQUAL(1L, nTestTime); + nTestTime.setValue(nTestLInt2147483648); + BOOST_CHECK_EQUAL(-2147483648L, nTestTime); + nTestTime.setValue(nTestLInt9223372036854775807); + BOOST_CHECK_EQUAL(-1L, nTestTime); +#endif +} + +BOOST_AUTO_TEST_CASE(LINT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LINT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() +#endif //FORTE_USE_64BIT_DATATYPES diff --git a/tests/core/datatypes/CIEC_LINT_test.cpp b/tests/core/datatypes/CIEC_LINT_test.cpp new file mode 100644 index 000000000..826f371dd --- /dev/null +++ b/tests/core/datatypes/CIEC_LINT_test.cpp @@ -0,0 +1,253 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_lint.h" + +BOOST_AUTO_TEST_SUITE(CIEC_LINT_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_LINT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_LINT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteInt64()), sizeof(TForteInt64)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_LINT nTest1; + CIEC_LINT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0); + + nTest1 = CIEC_LINT::scm_nMinVal; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, CIEC_LINT::scm_nMinVal); + BOOST_CHECK_EQUAL(nTest2, CIEC_LINT::scm_nMinVal); + + nTest1 = -56921482365875466LL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -56921482365875466LL); + BOOST_CHECK_EQUAL(nTest2, -56921482365875466LL); + + nTest1 = 4723658749321LL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 4723658749321LL); + BOOST_CHECK_EQUAL(nTest2, 4723658749321LL); + + nTest1 = 9223372036854775807LL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 9223372036854775807LL); + BOOST_CHECK_EQUAL(nTest2, 9223372036854775807LL); + + nTest2 = -6548432101LL; + BOOST_CHECK_EQUAL(nTest1, 9223372036854775807LL); + BOOST_CHECK_EQUAL(nTest2, -6548432101LL); +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_LINT nTest; + + char cBuffer[21]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), 0); + + nTest = -68734876324LL; + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), -68734876324LL); + + nTest = CIEC_LINT::scm_nMinVal; + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), CIEC_LINT::scm_nMinVal); + + nTest = 8462382567LL; + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), 8462382567LL); + + nTest = 9223372036854775807LL; + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), 9223372036854775807LL); + + //check toString and fromString + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("-9223372036854775808"), 20); + BOOST_CHECK_EQUAL(nTest, CIEC_LINT::scm_nMinVal); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-9223372036854775808"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1000000000000000000000000000000000000000000000000000000000000000"), 66); + BOOST_CHECK_EQUAL(nTest, CIEC_LINT::scm_nMinVal); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-9223372036854775808"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#1000000000000000000000"), 24); + BOOST_CHECK_EQUAL(nTest, CIEC_LINT::scm_nMinVal); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-9223372036854775808"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#8000000000000000"), 19); + BOOST_CHECK_EQUAL(nTest, CIEC_LINT::scm_nMinVal); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-9223372036854775808"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("36891234593"), 11); + BOOST_CHECK_EQUAL(nTest, 36891234593LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "36891234593"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#100010010110111000111001000100100001"), 38); + BOOST_CHECK_EQUAL(nTest, 36891234593LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "36891234593"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("8#422670710441"), 14); + BOOST_CHECK_EQUAL(nTest, 36891234593LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "36891234593"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#896E39121"), 12); + BOOST_CHECK_EQUAL(nTest, 36891234593LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "36891234593"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("9223372036854775807"), 19); + BOOST_CHECK_EQUAL(nTest, 9223372036854775807LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 19); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "9223372036854775807"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#0111111111111111111111111111111111111111111111111111111111111111"), 66); + BOOST_CHECK_EQUAL(nTest, 9223372036854775807LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 19); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "9223372036854775807"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#777777777777777777777"), 23); + BOOST_CHECK_EQUAL(nTest, 9223372036854775807LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 19); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "9223372036854775807"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#7FFFFFFFFFFFFFFF"), 19); + BOOST_CHECK_EQUAL(nTest, 9223372036854775807LL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 19); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "9223372036854775807"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), 6); + BOOST_CHECK_EQUAL(nTest, 300); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "300"), 0); + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("92233720368547758070"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#101111111111111111111111111111111111111111111111111111111111111110"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#7777777777777777777770"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#7FFFFFFFFFFFFFFF0"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-9223372036854775810"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-9223372036854775809"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-9223372036854775808"), 20); + BOOST_CHECK_EQUAL(nTest, -9223372036854775808LL); + BOOST_CHECK_EQUAL(nTest.fromString("-9223372036854775807"), 20); + BOOST_CHECK_EQUAL(nTest, -9223372036854775807LL); + BOOST_CHECK_EQUAL(nTest.fromString("-9223372036854775806"), 20); + BOOST_CHECK_EQUAL(nTest, -9223372036854775806LL); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_LREAL_CASTS_test.cpp b/tests/core/datatypes/CIEC_LREAL_CASTS_test.cpp new file mode 100644 index 000000000..0f9ff69e1 --- /dev/null +++ b/tests/core/datatypes/CIEC_LREAL_CASTS_test.cpp @@ -0,0 +1,408 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifdef FORTE_USE_64BIT_DATATYPES +#ifdef FORTE_USE_REAL_DATATYPE + +#include +#include + +#include "../../../src/core/datatypes/forte_real.h" + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + +//64bit Datatypes +#include "../../../src/core/datatypes/forte_lword.h" +#include "../../../src/core/datatypes/forte_lint.h" +#include "../../../src/core/datatypes/forte_ulint.h" +#include "../../../src/core/datatypes/forte_lreal.h" + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_LREAL_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_LREAL_to_BOOL) +{ + CIEC_LREAL nTestLReal0; + CIEC_LREAL nTestLReal1; + CIEC_LREAL nTestLReal2_2874e6; + CIEC_LREAL nTestLRealm6_2587em4; + CIEC_LREAL nTestLReal1_0em37; + CIEC_LREAL nTestLReal36; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestLReal0, 0); + BOOST_CHECK_EQUAL(nTestLReal1, 0); + BOOST_CHECK_EQUAL(nTestLReal2_2874e6, 0); + BOOST_CHECK_EQUAL(nTestLRealm6_2587em4, 0); + BOOST_CHECK_EQUAL(nTestLReal1_0em37, 0); + BOOST_CHECK_EQUAL(nTestLReal36, 0); + + nTestLReal0=0.0; + nTestLReal1=1.0; + nTestLReal2_2874e6=2.2874e6; + nTestLRealm6_2587em4=-6.2587e-4; + nTestLReal1_0em37=1.0e-37; + nTestLReal36=36.0; + + + BOOST_CHECK_EQUAL(0.0, nTestLReal0); + BOOST_CHECK_EQUAL(1.0, nTestLReal1); + BOOST_CHECK_EQUAL(2.2874e6, nTestLReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4, nTestLRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37, nTestLReal1_0em37); + BOOST_CHECK_EQUAL(36.0, nTestLReal36); + +//checks + CIEC_ANY::specialCast(nTestLReal0, bTestBool); + BOOST_CHECK_EQUAL(false, bTestBool); + CIEC_ANY::specialCast(nTestLReal1, bTestBool); + BOOST_CHECK_EQUAL(true, bTestBool); + CIEC_ANY::specialCast(nTestLReal2_2874e6, bTestBool); + BOOST_CHECK_EQUAL(true, bTestBool); + CIEC_ANY::specialCast(nTestLReal36, bTestBool); + BOOST_CHECK_EQUAL(true, bTestBool); + CIEC_ANY::specialCast(nTestLRealm6_2587em4, bTestBool); + BOOST_CHECK_EQUAL(false, bTestBool); +} + +BOOST_AUTO_TEST_CASE(CASTS_LREAL_to_BITDTs) +{ + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; + CIEC_LWORD nTestLWord; + + CIEC_LREAL nTestLReal0; + CIEC_LREAL nTestLReal1; + CIEC_LREAL nTestLReal2_2874e6; + CIEC_LREAL nTestLRealm6_2587em4; + CIEC_LREAL nTestLReal1_0em37; + CIEC_LREAL nTestLReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestLReal0, 0.0); + BOOST_CHECK_EQUAL(nTestLReal1, 0.0); + BOOST_CHECK_EQUAL(nTestLReal2_2874e6, 0.0); + BOOST_CHECK_EQUAL(nTestLRealm6_2587em4, 0.0); + BOOST_CHECK_EQUAL(nTestLReal1_0em37, 0.0); + BOOST_CHECK_EQUAL(nTestLReal36, 0); + + nTestLReal0=0.0; + nTestLReal1=1.0; + nTestLReal2_2874e6=2.2874e6; + nTestLRealm6_2587em4=-6.2587e-4; + nTestLReal1_0em37=1.0e-37; + nTestLReal36=36.0; + + //the 4byte hex value for 36.0: 0x4042000000000000 + //the 4byte hex value for -6.2587e-4f: 0xbf44822d973cf2fb + //the 4byte hex value for 1: 0x3ff0000000000000 + + BOOST_CHECK_EQUAL(0.0, nTestLReal0); + BOOST_CHECK_EQUAL(1.0, nTestLReal1); + BOOST_CHECK_EQUAL(2.2874e6, nTestLReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4, nTestLRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37, nTestLReal1_0em37); + BOOST_CHECK_EQUAL(36.0, nTestLReal36); + +//toByte + nTestByte.setValue(nTestLReal0); + CIEC_ANY::specialCast(nTestLReal0, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0U); + CIEC_ANY::specialCast(nTestLReal1, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0); + CIEC_ANY::specialCast(nTestLReal36, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0); + CIEC_ANY::specialCast(nTestLRealm6_2587em4, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0xfb); + +//toWord + CIEC_ANY::specialCast(nTestLReal0, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0U); + CIEC_ANY::specialCast(nTestLReal1, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0x0); + CIEC_ANY::specialCast(nTestLReal36, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0x0); + CIEC_ANY::specialCast(nTestLRealm6_2587em4, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0xf2fb); + +//toDWord + CIEC_ANY::specialCast(nTestLReal0, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + CIEC_ANY::specialCast(nTestLReal1, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0x0); + CIEC_ANY::specialCast(nTestLReal36, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0x0); + CIEC_ANY::specialCast(nTestLRealm6_2587em4, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0x973cf2fb); + +//toLWord + CIEC_ANY::specialCast(nTestLReal0, nTestLWord); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + CIEC_ANY::specialCast(nTestLReal1, nTestLWord); + BOOST_CHECK_EQUAL(0x3ff0000000000000ULL, nTestLWord); + CIEC_ANY::specialCast(nTestLReal36, nTestLWord); + BOOST_CHECK_EQUAL(0x4042000000000000ULL, nTestLWord); + CIEC_ANY::specialCast(nTestLRealm6_2587em4, nTestLWord); + BOOST_CHECK_EQUAL(nTestLWord, 0xbf44822d973cf2fbULL); +} + +BOOST_AUTO_TEST_CASE(CASTS_LREAL_to_INTS) +{ + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; + + CIEC_LREAL nTestLReal0; + CIEC_LREAL nTestLReal1; + CIEC_LREAL nTestLReal2_2874e6; + CIEC_LREAL nTestLRealm6_2587em4; + CIEC_LREAL nTestLReal1_0em37; + CIEC_LREAL nTestLReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestLReal0, 0); + BOOST_CHECK_EQUAL(nTestLReal1, 0); + BOOST_CHECK_EQUAL(nTestLReal2_2874e6, 0); + BOOST_CHECK_EQUAL(nTestLRealm6_2587em4, 0); + BOOST_CHECK_EQUAL(nTestLReal1_0em37, 0); + BOOST_CHECK_EQUAL(nTestLReal36, 0); + + nTestLReal0=0.0; + nTestLReal1=1.0; + nTestLReal2_2874e6=2.2874e6; + nTestLRealm6_2587em4=-6.2587e-4; + nTestLReal1_0em37=1.0e-37; + nTestLReal36=36.0; + + BOOST_CHECK_EQUAL(0.0, nTestLReal0); + BOOST_CHECK_EQUAL(1.0, nTestLReal1); + BOOST_CHECK_EQUAL(2.2874e6, nTestLReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4, nTestLRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37, nTestLReal1_0em37); + BOOST_CHECK_EQUAL(36.0, nTestLReal36); + +//toUSINT + CIEC_ANY::specialCast(nTestLReal0, nTestUSInt); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + CIEC_ANY::specialCast(nTestLReal1, nTestUSInt); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + CIEC_ANY::specialCast(nTestLReal36, nTestUSInt); + BOOST_CHECK_EQUAL(nTestUSInt, 36U); + +//toINT + CIEC_ANY::specialCast(nTestLReal0, nTestInt); + BOOST_CHECK_EQUAL(nTestInt, 0); + CIEC_ANY::specialCast(nTestLReal1, nTestInt); + BOOST_CHECK_EQUAL(nTestInt, 1); + CIEC_ANY::specialCast(nTestLReal36, nTestInt); + BOOST_CHECK_EQUAL(nTestInt, 36); + +//toUINT + CIEC_ANY::specialCast(nTestLReal0, nTestUInt); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + CIEC_ANY::specialCast(nTestLReal1, nTestUInt); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + CIEC_ANY::specialCast(nTestLReal36, nTestUInt); + BOOST_CHECK_EQUAL(nTestUInt, 36U); + +//toDINT + CIEC_ANY::specialCast(nTestLReal0, nTestDInt); + BOOST_CHECK_EQUAL(nTestDInt, 0L); + CIEC_ANY::specialCast(nTestLReal1, nTestDInt); + BOOST_CHECK_EQUAL(nTestDInt, 1L); + CIEC_ANY::specialCast(nTestLReal36, nTestDInt); + BOOST_CHECK_EQUAL(nTestDInt, 36L); + +//toUDINT + CIEC_ANY::specialCast(nTestLReal0, nTestUDInt); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + CIEC_ANY::specialCast(nTestLReal1, nTestUDInt); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + CIEC_ANY::specialCast(nTestLReal36, nTestUDInt); + BOOST_CHECK_EQUAL(nTestUDInt, 36UL); + +//toLINT + CIEC_ANY::specialCast(nTestLReal0, nTestLInt); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + CIEC_ANY::specialCast(nTestLReal1, nTestLInt); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + CIEC_ANY::specialCast(nTestLReal36, nTestLInt); + BOOST_CHECK_EQUAL(nTestLInt, 36LL); + +//toULINT + CIEC_ANY::specialCast(nTestLReal0, nTestULInt); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + CIEC_ANY::specialCast(nTestLReal1, nTestULInt); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + CIEC_ANY::specialCast(nTestLReal36, nTestULInt); + BOOST_CHECK_EQUAL(nTestULInt, 36ULL); +} + +BOOST_AUTO_TEST_CASE(CASTS_LREAL_to_REAL) +{ + CIEC_LREAL nTestLReal0; + CIEC_LREAL nTestLReal1; + CIEC_LREAL nTestLReal2_2874e6; + CIEC_LREAL nTestLRealm6_2587em4; + CIEC_LREAL nTestLReal1_0em37; + CIEC_LREAL nTestLReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestLReal0, 0); + BOOST_CHECK_EQUAL(nTestLReal1, 0); + BOOST_CHECK_EQUAL(nTestLReal2_2874e6, 0); + BOOST_CHECK_EQUAL(nTestLRealm6_2587em4, 0); + BOOST_CHECK_EQUAL(nTestLReal1_0em37, 0); + BOOST_CHECK_EQUAL(nTestLReal36, 0); + + nTestLReal0=0.0; + nTestLReal1=1.0; + nTestLReal2_2874e6=2.2874e6; + nTestLRealm6_2587em4=-6.2587e-4; + nTestLReal1_0em37=1.0e-37; + nTestLReal36=36.0; + + BOOST_CHECK_EQUAL(0.0, nTestLReal0); + BOOST_CHECK_EQUAL(1.0, nTestLReal1); + BOOST_CHECK_EQUAL(2.2874e6, nTestLReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4, nTestLRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37, nTestLReal1_0em37); + BOOST_CHECK_EQUAL(36.0, nTestLReal36); + + + + CIEC_REAL nTestReal; + +//toLREAL + BOOST_CHECK_EQUAL(1.0, nTestLReal1); + BOOST_CHECK_EQUAL(2.2874e6, nTestLReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4, nTestLRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37, nTestLReal1_0em37); + BOOST_CHECK_EQUAL(36.0, nTestLReal36); + + CIEC_ANY::specialCast(nTestLReal0, nTestReal); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + CIEC_ANY::specialCast(nTestLReal1, nTestReal); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + CIEC_ANY::specialCast(nTestLReal2_2874e6, nTestReal); + BOOST_CHECK_EQUAL(2.2874e6f, nTestReal); + CIEC_ANY::specialCast(nTestLRealm6_2587em4, nTestReal); + BOOST_CHECK_EQUAL(-6.2587e-4f, nTestReal); + CIEC_ANY::specialCast(nTestLReal1_0em37, nTestReal); + BOOST_CHECK_EQUAL(1.0e-37f, nTestReal); + CIEC_ANY::specialCast(nTestLReal36, nTestReal); + BOOST_CHECK_EQUAL(36.0f, nTestReal); +} + +BOOST_AUTO_TEST_CASE(CASTS_LREAL_to_TIME) +{ + CIEC_TIME nTestTime; + + CIEC_LREAL nTestLReal0; + CIEC_LREAL nTestLReal1; + CIEC_LREAL nTestLReal2_2874e6; + CIEC_LREAL nTestLRealm6_2587em4; + CIEC_LREAL nTestLReal1_0em37; + CIEC_LREAL nTestLReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestLReal0, 0); + BOOST_CHECK_EQUAL(nTestLReal1, 0); + BOOST_CHECK_EQUAL(nTestLReal2_2874e6, 0); + BOOST_CHECK_EQUAL(nTestLRealm6_2587em4, 0); + BOOST_CHECK_EQUAL(nTestLReal1_0em37, 0); + BOOST_CHECK_EQUAL(nTestLReal36, 0); + + nTestLReal0=0.0; + nTestLReal1=1.0; + nTestLReal2_2874e6=2.2874e6; + nTestLRealm6_2587em4=-6.2587e-4; + nTestLReal1_0em37=1.0e-37; + nTestLReal36=36.0; + + BOOST_CHECK_EQUAL(0.0, nTestLReal0); + BOOST_CHECK_EQUAL(1.0, nTestLReal1); + BOOST_CHECK_EQUAL(2.2874e6, nTestLReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4, nTestLRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37, nTestLReal1_0em37); + BOOST_CHECK_EQUAL(36.0, nTestLReal36); + +//toTime + CIEC_ANY::specialCast(nTestLReal0, nTestTime); + BOOST_CHECK_EQUAL(nTestTime, 0); + CIEC_ANY::specialCast(nTestLReal1, nTestTime); + BOOST_CHECK_EQUAL(nTestTime, 1); + CIEC_ANY::specialCast(nTestLReal36, nTestTime); + BOOST_CHECK_EQUAL(nTestTime, 36); + +} + +BOOST_AUTO_TEST_CASE(LREAL_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LREAL, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES diff --git a/tests/core/datatypes/CIEC_LREAL_test.cpp b/tests/core/datatypes/CIEC_LREAL_test.cpp new file mode 100644 index 000000000..4de1db83e --- /dev/null +++ b/tests/core/datatypes/CIEC_LREAL_test.cpp @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, nxtControl, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include + +#include "../../../src/core/datatypes/forte_lreal.h" + + +BOOST_AUTO_TEST_SUITE(CIEC_LREAL_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_LREAL nTest; + //check type information + BOOST_REQUIRE_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_LREAL); + //check operator bool data type size + BOOST_REQUIRE_EQUAL(sizeof(nTest.operator TForteDFloat()), sizeof(TForteDFloat)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_LREAL nTest1; + CIEC_LREAL nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0.0f); + + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = 2.28743e6; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 2.28743e6); + BOOST_CHECK_EQUAL(nTest2, 2.28743e6); + + nTest1 = -6.2587e-4f; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -6.2587e-4f); + BOOST_CHECK_EQUAL(nTest2, -6.2587e-4f); + + nTest1 = 1.0E-37f; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 1.0E-37f); + BOOST_CHECK_EQUAL(nTest2, 1.0E-37f); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); + + //check that assignment operator does not intertwine objects + nTest2 = -36.0; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, -36.0); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_LREAL nTest; + + char cBuffer[12]; + char cBufferFail[2]; + + //check cast operator + nTest = 0.0; + BOOST_CHECK_EQUAL(nTest.operator TForteDFloat(), 0.0); + + nTest = std::numeric_limits::min(); + BOOST_CHECK_EQUAL(nTest.operator TForteDFloat(), std::numeric_limits::min()); + + nTest = -4.2345e4; + BOOST_CHECK_EQUAL(nTest.operator TForteDFloat(), -4.2345e4); + + nTest = 23.7813e2; + BOOST_CHECK_EQUAL(nTest.operator TForteDFloat(), 23.7813e2); + + nTest = std::numeric_limits::max(); + BOOST_CHECK_EQUAL(nTest.operator TForteDFloat(), std::numeric_limits::max()); + + //check toString and fromString + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("-1E-37"), 6); + BOOST_CHECK_EQUAL(static_cast(nTest), -1.0E-37); + +#ifdef WIN32 + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 10), 7); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-1e-037"), 0); +#else + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 10), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-1e-37"), 0); +#endif + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(static_cast(nTest), 0.0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("3.2523E15"), 9); + BOOST_CHECK_EQUAL(static_cast(nTest), 3.2523e15); +#ifdef WIN32 + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "3.2523e+015"), 0); +#else + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "3.2523e+15"), 0); +#endif + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("1E37"), 4); + BOOST_CHECK_EQUAL(static_cast(nTest), 1e37); +#ifdef WIN32 + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1e+037"), 0); +#else + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1e+37"), 0); +#endif + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("4e401"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#100101100"), 1); + BOOST_CHECK_EQUAL(nTest.fromString("8#116100"), 1); + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), 2); + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFF0"), 2); + BOOST_CHECK_EQUAL(nTest.fromString("-4e-401"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} + +void lRealTypedFromString(const char *pa_acTestString, double pa_fResult){ + CIEC_LREAL nTest; + BOOST_CHECK_EQUAL(nTest.fromString(pa_acTestString), strlen(pa_acTestString)); + BOOST_CHECK_EQUAL(pa_fResult, nTest); +} + +void faultingLRealTypedFromString(const char *pa_acTestString){ + CIEC_LREAL nTest; + BOOST_CHECK_EQUAL(nTest.fromString(pa_acTestString), -1); +} + + +BOOST_AUTO_TEST_CASE(REAL_typed_fromString_tests){ + lRealTypedFromString("LREAL#1E37", 1e37); + lRealTypedFromString("LREAL#-4.2345e4",-4.2345e4); + lRealTypedFromString("LREAL#0",0.0); + lRealTypedFromString("LREAL#3.2523E15",3.2523E15); + + faultingLRealTypedFromString("LREAL#4e401"); + faultingLRealTypedFromString("LREAL#-4e-401"); + faultingLRealTypedFromString("LREAL#NOT A VALID STRING"); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_LWORD_CASTS_test.cpp b/tests/core/datatypes/CIEC_LWORD_CASTS_test.cpp new file mode 100644 index 000000000..0594f8e8f --- /dev/null +++ b/tests/core/datatypes/CIEC_LWORD_CASTS_test.cpp @@ -0,0 +1,400 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifdef FORTE_USE_64BIT_DATATYPES +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//Time +#include "../../../src/core/datatypes/forte_time.h" + + + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_LWORD_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_LWORD_to_BOOL) +{ + CIEC_LWORD nTestLWord0; + CIEC_LWORD nTestLWord1; + CIEC_LWORD nTestLWord4294967296; + CIEC_LWORD nTestLWord18446744073709551615; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 0ULL); + + nTestLWord0=0x00; + nTestLWord1=0x01; + nTestLWord4294967296=4294967296ULL; + nTestLWord18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestLWord0, 0U); + BOOST_CHECK_EQUAL(nTestLWord1, 1U); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 4294967296ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 18446744073709551615ULL); + +//checks + bTestBool.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(bTestBool, false); + bTestBool.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(bTestBool, true); + +} + +BOOST_AUTO_TEST_CASE(CASTS_LWORD_to_BITDTs) +{ + CIEC_LWORD nTestLWord0; + CIEC_LWORD nTestLWord1; + CIEC_LWORD nTestLWord4294967296; + CIEC_LWORD nTestLWord18446744073709551615; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; + +//check initial values + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 0ULL); + + nTestLWord0=0; + nTestLWord1=1; + nTestLWord4294967296=4294967296LL; + nTestLWord18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 1ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 4294967296ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 18446744073709551615ULL); + +//toByte + nTestByte.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestByte, 0); + nTestByte.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestByte, 1); + nTestByte.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestByte, 0); + nTestByte.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestByte, 255); + +//toWord + nTestWord.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestWord, 0); + nTestWord.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestWord, 1); + nTestWord.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestWord, 0); + nTestWord.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestWord, 65535); + +//toDWord + nTestDWord.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestDWord, 4294967295UL); + +} + +BOOST_AUTO_TEST_CASE(CASTS_LWORD_to_INTS) +{ + CIEC_LWORD nTestLWord0; + CIEC_LWORD nTestLWord1; + CIEC_LWORD nTestLWord4294967296; + CIEC_LWORD nTestLWord18446744073709551615; + + CIEC_SINT nTestSInt; + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; + + + //check initial values + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 0ULL); + + nTestLWord0=0ULL; + nTestLWord1=1ULL; + nTestLWord4294967296=4294967296ULL; + nTestLWord18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 1ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 4294967296ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 18446744073709551615ULL); + +//toSINT + nTestSInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUSINT + nTestUSInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestUSInt, 0); + nTestUSInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestUSInt, 1); + nTestUSInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestUSInt, 0); + nTestUSInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestUSInt, 255); + + +//toINT + nTestInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toUINT + nTestUInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestUInt, 0); + nTestUInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestUInt, 1); + nTestUInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestUInt, 0); + nTestUInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestUInt, 65535); + +//toDINT + nTestDInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestDInt, 1); + nTestDInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestDInt, -1); + +//toUDINT + nTestUDInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestUDInt, 0U); + nTestUDInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestUDInt, 1U); + nTestUDInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestUDInt, 0U); + nTestUDInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestUDInt, 4294967295UL); + +//toLINT + nTestLInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestLInt, 0); + nTestLInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestLInt, 1); + nTestLInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestLInt, 4294967296LL); + nTestLInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestLInt, -1LL); + +//toULINT + nTestULInt.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestULInt, 4294967296ULL); + nTestULInt.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestULInt, 18446744073709551615ULL); +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_LWORD_to_REAL) +{ + CIEC_LWORD nTestLWord0; + CIEC_LWORD nTestLWord1; + CIEC_LWORD nTestLWord4294967296; + CIEC_LWORD nTestLWord18446744073709551615; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 0ULL); + + nTestLWord0=0ULL; + nTestLWord1=1ULL; + nTestLWord4294967296=4294967296ULL; + nTestLWord18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 1ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 4294967296ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 18446744073709551615ULL); + +//toREAL + nTestReal.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(4294967296.0f, nTestReal); + nTestReal.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(18446744073709551615.0f, nTestReal); + + + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(nTestLReal, 0.0); + nTestLReal.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(nTestLReal, 1.0); + nTestLReal.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(nTestLReal, 4294967296.0); + nTestLReal.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(nTestLReal, 18446744073709551615.0); + +} +#endif //FORTE_USE_REAL_DATATYPE + + +BOOST_AUTO_TEST_CASE(CASTS_LWORD_to_Time) +{ + CIEC_LWORD nTestLWord0; + CIEC_LWORD nTestLWord1; + CIEC_LWORD nTestLWord4294967296; + CIEC_LWORD nTestLWord18446744073709551615; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 0ULL); + + nTestLWord0=0ULL; + nTestLWord1=1ULL; + nTestLWord4294967296=4294967296ULL; + nTestLWord18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestLWord0, 0ULL); + BOOST_CHECK_EQUAL(nTestLWord1, 1ULL); + BOOST_CHECK_EQUAL(nTestLWord4294967296, 4294967296ULL); + BOOST_CHECK_EQUAL(nTestLWord18446744073709551615, 18446744073709551615ULL); + +//toTime +#ifdef FORTE_USE_64BIT_DATATYPES + nTestTime.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(4294967296LL, nTestTime); + nTestTime.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(-1LL, nTestTime); +#else + nTestTime.setValue(nTestLWord0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestLWord1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestLWord4294967296); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestLWord18446744073709551615); + BOOST_CHECK_EQUAL(-1, nTestTime); +#endif +} + + +BOOST_AUTO_TEST_SUITE_END() + +BOOST_AUTO_TEST_CASE(LWORD_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_LWORD, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +#endif //FORTE_USE_64BIT_DATATYPES diff --git a/tests/core/datatypes/CIEC_LWORD_test.cpp b/tests/core/datatypes/CIEC_LWORD_test.cpp new file mode 100644 index 000000000..f185a234b --- /dev/null +++ b/tests/core/datatypes/CIEC_LWORD_test.cpp @@ -0,0 +1,203 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_lword.h" + +BOOST_AUTO_TEST_SUITE(CIEC_LWORD_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_LWORD nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_LWORD); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteLWord()), sizeof(TForteLWord)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_LWORD nTest1; + CIEC_LWORD nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0ULL); + + nTest1 = 0ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0ULL); + BOOST_CHECK_EQUAL(nTest2, 0ULL); + + nTest1 = 87456813ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 87456813ULL); + BOOST_CHECK_EQUAL(nTest2, 87456813ULL); + + nTest1 = 18446744073709551615ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest2, 18446744073709551615ULL); + + //check that assignment operator does not intertwine objects + nTest2 = 25432341ULL; + BOOST_CHECK_EQUAL(nTest1, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest2, 25432341ULL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_LWORD nTest; + + char cBuffer[21]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteLWord(), 0ULL); + + nTest = 14524526231894545ULL; + BOOST_CHECK_EQUAL(nTest.operator TForteLWord(), 14524526231894545ULL); + + nTest = 9223372036854775807ULL; + BOOST_CHECK_EQUAL(nTest.operator TForteLWord(), 9223372036854775807ULL); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("45387346543765474"), 17); + BOOST_CHECK_EQUAL(nTest, 45387346543765474ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 17); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "45387346543765474"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#10100001001111111000110100011100000010011110011111100010"), 58); + BOOST_CHECK_EQUAL(nTest, 45387346543765474ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 17); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "45387346543765474"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#2411770643402363742"), 21); + BOOST_CHECK_EQUAL(nTest, 45387346543765474ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 17); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "45387346543765474"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#A13F8D1C09E7E2"), 17); + BOOST_CHECK_EQUAL(nTest, 45387346543765474ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 17); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "45387346543765474"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("18446744073709551615"), 20); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1111111111111111111111111111111111111111111111111111111111111111"), 66); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#1777777777777777777777"), 24); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFFFFFFFFFFFFFF"), 19); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("184467440737095516150"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#11111111111111111111111111111111111111111111111111111111111111110"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#17777777777777777777770"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#922337203685477580754"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFFFFFFFFFFFFFF0"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_REAL_CASTS_test.cpp b/tests/core/datatypes/CIEC_REAL_CASTS_test.cpp new file mode 100644 index 000000000..90e31ac80 --- /dev/null +++ b/tests/core/datatypes/CIEC_REAL_CASTS_test.cpp @@ -0,0 +1,421 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifdef FORTE_USE_REAL_DATATYPE + +#include +#include + +#include "../../../src/core/datatypes/forte_real.h" + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_REAL_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_REAL_to_BOOL) +{ + CIEC_REAL nTestReal0; + CIEC_REAL nTestReal1; + CIEC_REAL nTestReal2_2874e6; + CIEC_REAL nTestRealm6_2587em4; + CIEC_REAL nTestReal1_0em37; + CIEC_REAL nTestReal36; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestReal0, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1, 0.0f); + BOOST_CHECK_EQUAL(nTestReal2_2874e6, 0.0f); + BOOST_CHECK_EQUAL(nTestRealm6_2587em4, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1_0em37, 0.0f); + BOOST_CHECK_EQUAL(nTestReal36, 0.0f); + + nTestReal0=0.0f; + nTestReal1=1.0f; + nTestReal2_2874e6=2.2874e6f; + nTestRealm6_2587em4=-6.2587e-4f; + nTestReal1_0em37=1.0e-37f; + nTestReal36=36.0f; + + + BOOST_CHECK_EQUAL(0.0f, nTestReal0); + BOOST_CHECK_EQUAL(1.0f, nTestReal1); + BOOST_CHECK_EQUAL(2.2874e6f, nTestReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4f, nTestRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37f, nTestReal1_0em37); + BOOST_CHECK_EQUAL(36.0f, nTestReal36); + + +//checks + CIEC_ANY::specialCast(nTestReal0, bTestBool); + BOOST_CHECK_EQUAL(false, bTestBool); + CIEC_ANY::specialCast(nTestReal1, bTestBool); + BOOST_CHECK_EQUAL(true, bTestBool); + CIEC_ANY::specialCast(nTestReal2_2874e6, bTestBool); + BOOST_CHECK_EQUAL(true, bTestBool); + CIEC_ANY::specialCast(nTestRealm6_2587em4, bTestBool); + BOOST_CHECK_EQUAL(false, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_REAL_to_BITDTs) +{ + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + + CIEC_REAL nTestReal0; + CIEC_REAL nTestReal1; + CIEC_REAL nTestReal2_2874e6; + CIEC_REAL nTestRealm6_2587em4; + CIEC_REAL nTestReal1_0em37; + CIEC_REAL nTestReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestReal0, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1, 0.0f); + BOOST_CHECK_EQUAL(nTestReal2_2874e6, 0.0f); + BOOST_CHECK_EQUAL(nTestRealm6_2587em4, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1_0em37, 0.0f); + BOOST_CHECK_EQUAL(nTestReal36, 0.0f); + + nTestReal0=0.0f; + nTestReal1=1.0f; + nTestReal2_2874e6=2.2874e6f; + nTestRealm6_2587em4=-6.2587e-4f; + nTestReal1_0em37=1.0e-37f; + nTestReal36=36.0f; + + BOOST_CHECK_EQUAL(0.0f, nTestReal0); + BOOST_CHECK_EQUAL(1.0f, nTestReal1); + BOOST_CHECK_EQUAL(2.2874e6f, nTestReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4f, nTestRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37f, nTestReal1_0em37); + BOOST_CHECK_EQUAL(36.0f, nTestReal36); + + //the 4byte hex value for 36.0: 0x42100000 + //the 4byte hex value for -6.2587e-4f: 0xba24116d + //the 4byte hex value for 1: 0x3f800000 + +//toByte + CIEC_ANY::specialCast(nTestReal0, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0U); + CIEC_ANY::specialCast(nTestReal1, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0x00); + CIEC_ANY::specialCast(nTestReal36, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0x00); + CIEC_ANY::specialCast(nTestRealm6_2587em4, nTestByte); + BOOST_CHECK_EQUAL(nTestByte, 0x6d); + +//toWord + CIEC_ANY::specialCast(nTestReal0, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0U); + CIEC_ANY::specialCast(nTestReal1, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0x00); + CIEC_ANY::specialCast(nTestReal36, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0x0000); + CIEC_ANY::specialCast(nTestRealm6_2587em4, nTestWord); + BOOST_CHECK_EQUAL(nTestWord, 0x116d); + +//toDWord + CIEC_ANY::specialCast(nTestReal0, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + CIEC_ANY::specialCast(nTestReal1, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0x3f800000); + CIEC_ANY::specialCast(nTestReal36, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0x42100000); + CIEC_ANY::specialCast(nTestRealm6_2587em4, nTestDWord); + BOOST_CHECK_EQUAL(nTestDWord, 0xba24116d); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + CIEC_ANY::specialCast(nTestReal0, nTestLWord); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + CIEC_ANY::specialCast(nTestReal1, nTestLWord); + BOOST_CHECK_EQUAL(nTestLWord, 0x3f800000); + CIEC_ANY::specialCast(nTestReal36, nTestLWord); + BOOST_CHECK_EQUAL(nTestLWord, 0x42100000); + CIEC_ANY::specialCast(nTestRealm6_2587em4, nTestLWord); + BOOST_CHECK_EQUAL(nTestLWord, 0xba24116d); +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_REAL_to_INTS) +{ + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + CIEC_REAL nTestReal0; + CIEC_REAL nTestReal1; + CIEC_REAL nTestReal2_2874e6; + CIEC_REAL nTestRealm6_2587em4; + CIEC_REAL nTestReal1_0em37; + CIEC_REAL nTestReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestReal0, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1, 0.0f); + BOOST_CHECK_EQUAL(nTestReal2_2874e6, 0.0f); + BOOST_CHECK_EQUAL(nTestRealm6_2587em4, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1_0em37, 0.0f); + BOOST_CHECK_EQUAL(nTestReal36, 0.0f); + + nTestReal0=0.0f; + nTestReal1=1.0f; + nTestReal2_2874e6=2.2874e6f; + nTestRealm6_2587em4=-6.2587e-4f; + nTestReal1_0em37=1.0e-37f; + nTestReal36=36.0f; + + BOOST_CHECK_EQUAL(0.0f, nTestReal0); + BOOST_CHECK_EQUAL(1.0f, nTestReal1); + BOOST_CHECK_EQUAL(2.2874e6f, nTestReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4f, nTestRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37f, nTestReal1_0em37); + BOOST_CHECK_EQUAL(36.0f, nTestReal36); + +//toUSINT + CIEC_ANY::specialCast(nTestReal0, nTestUSInt); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + CIEC_ANY::specialCast(nTestReal1, nTestUSInt); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + CIEC_ANY::specialCast(nTestReal36, nTestUSInt); + BOOST_CHECK_EQUAL(nTestUSInt, 36U); + +//toINT + CIEC_ANY::specialCast(nTestReal0, nTestInt); + BOOST_CHECK_EQUAL(nTestInt, 0); + CIEC_ANY::specialCast(nTestReal1, nTestInt); + BOOST_CHECK_EQUAL(nTestInt, 1); + CIEC_ANY::specialCast(nTestReal36, nTestInt); + BOOST_CHECK_EQUAL(nTestInt, 36); + +//toUINT + CIEC_ANY::specialCast(nTestReal0, nTestUInt); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + CIEC_ANY::specialCast(nTestReal1, nTestUInt); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + CIEC_ANY::specialCast(nTestReal36, nTestUInt); + BOOST_CHECK_EQUAL(nTestUInt, 36U); + +//toDINT + CIEC_ANY::specialCast(nTestReal0, nTestDInt); + BOOST_CHECK_EQUAL(nTestDInt, 0L); + CIEC_ANY::specialCast(nTestReal1, nTestDInt); + BOOST_CHECK_EQUAL(nTestDInt, 1L); + CIEC_ANY::specialCast(nTestReal36, nTestDInt); + BOOST_CHECK_EQUAL(nTestDInt, 36L); + +//toUDINT + CIEC_ANY::specialCast(nTestReal0, nTestUDInt); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + CIEC_ANY::specialCast(nTestReal1, nTestUDInt); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + CIEC_ANY::specialCast(nTestReal36, nTestUDInt); + BOOST_CHECK_EQUAL(nTestUDInt, 36UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + CIEC_ANY::specialCast(nTestReal0, nTestLInt); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + CIEC_ANY::specialCast(nTestReal1, nTestLInt); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + CIEC_ANY::specialCast(nTestReal36, nTestLInt); + BOOST_CHECK_EQUAL(nTestLInt, 36LL); + +//toULINT + CIEC_ANY::specialCast(nTestReal0, nTestULInt); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + CIEC_ANY::specialCast(nTestReal1, nTestULInt); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + CIEC_ANY::specialCast(nTestReal36, nTestULInt); + BOOST_CHECK_EQUAL(nTestULInt, 36ULL); +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_REAL_to_LREAL) +{ + CIEC_REAL nTestReal0; + CIEC_REAL nTestReal1; + CIEC_REAL nTestReal2_2874e6; + CIEC_REAL nTestRealm6_2587em4; + CIEC_REAL nTestReal1_0em37; + CIEC_REAL nTestReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestReal0, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1, 0.0f); + BOOST_CHECK_EQUAL(nTestReal2_2874e6, 0.0f); + BOOST_CHECK_EQUAL(nTestRealm6_2587em4, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1_0em37, 0.0f); + BOOST_CHECK_EQUAL(nTestReal36, 0.0f); + + nTestReal0=0.0f; + nTestReal1=1.0f; + nTestReal2_2874e6=2.2874e6f; + nTestRealm6_2587em4=-6.2587e-4f; + nTestReal1_0em37=1.0e-37f; + nTestReal36=36.0f; + + BOOST_CHECK_EQUAL(0.0f, nTestReal0); + BOOST_CHECK_EQUAL(1.0f, nTestReal1); + BOOST_CHECK_EQUAL(2.2874e6f, nTestReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4f, nTestRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37f, nTestReal1_0em37); + BOOST_CHECK_EQUAL(36.0f, nTestReal36); + + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + BOOST_CHECK_EQUAL(1.0f, nTestReal1); + BOOST_CHECK_EQUAL(2.2874e6f, nTestReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4f, nTestRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37f, nTestReal1_0em37); + BOOST_CHECK_EQUAL(36.0f, nTestReal36); + + CIEC_ANY::specialCast(nTestReal0, nTestLReal); + BOOST_CHECK_EQUAL((double)0.0f, nTestLReal); + CIEC_ANY::specialCast(nTestReal1, nTestLReal); + BOOST_CHECK_EQUAL((double)1.0f, nTestLReal); + nTestLReal.setValue(nTestReal2_2874e6); + CIEC_ANY::specialCast(nTestReal2_2874e6, nTestLReal); + BOOST_CHECK_EQUAL(((double)2.2874e6f), nTestLReal); + CIEC_ANY::specialCast(nTestRealm6_2587em4, nTestLReal); + BOOST_CHECK_EQUAL(((double)-6.2587e-4f), nTestLReal); + nTestLReal.setValue(nTestReal1_0em37); + CIEC_ANY::specialCast(nTestReal1_0em37, nTestLReal); + BOOST_CHECK_EQUAL(((double)1.0e-37f), nTestLReal); + CIEC_ANY::specialCast(nTestReal36, nTestLReal); + BOOST_CHECK_EQUAL(((double)36.0f), nTestLReal); + +#endif //FORTE_USE_64BIT_DATATYPES + +} + +BOOST_AUTO_TEST_CASE(CASTS_REAL_to_TIME) +{ + CIEC_TIME nTestTime; + + CIEC_REAL nTestReal0; + CIEC_REAL nTestReal1; + CIEC_REAL nTestReal2_2874e6; + CIEC_REAL nTestRealm6_2587em4; + CIEC_REAL nTestReal1_0em37; + CIEC_REAL nTestReal36; + +//check initial values + BOOST_CHECK_EQUAL(nTestReal0, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1, 0.0f); + BOOST_CHECK_EQUAL(nTestReal2_2874e6, 0.0f); + BOOST_CHECK_EQUAL(nTestRealm6_2587em4, 0.0f); + BOOST_CHECK_EQUAL(nTestReal1_0em37, 0.0f); + BOOST_CHECK_EQUAL(nTestReal36, 0.0f); + + nTestReal0=0.0f; + nTestReal1=1.0f; + nTestReal2_2874e6=2.2874e6f; + nTestRealm6_2587em4=-6.2587e-4f; + nTestReal1_0em37=1.0e-37f; + nTestReal36=36.0f; + + BOOST_CHECK_EQUAL(0.0f, nTestReal0); + BOOST_CHECK_EQUAL(1.0f, nTestReal1); + BOOST_CHECK_EQUAL(2.2874e6f, nTestReal2_2874e6); + BOOST_CHECK_EQUAL(-6.2587e-4f, nTestRealm6_2587em4); + BOOST_CHECK_EQUAL(1.0e-37f, nTestReal1_0em37); + BOOST_CHECK_EQUAL(36.0f, nTestReal36); + +//toTime + CIEC_ANY::specialCast(nTestReal0, nTestTime); + BOOST_CHECK_EQUAL(nTestTime, 0); + CIEC_ANY::specialCast(nTestReal1, nTestTime); + BOOST_CHECK_EQUAL(nTestTime, 1); + CIEC_ANY::specialCast(nTestReal36, nTestTime); + BOOST_CHECK_EQUAL(nTestTime, 36); + +} + +BOOST_AUTO_TEST_CASE(REAL_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_REAL, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() +#endif //FORTE_USE_REAL_DATATYPE diff --git a/tests/core/datatypes/CIEC_REAL_test.cpp b/tests/core/datatypes/CIEC_REAL_test.cpp new file mode 100644 index 000000000..0dbeeefc8 --- /dev/null +++ b/tests/core/datatypes/CIEC_REAL_test.cpp @@ -0,0 +1,178 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, nxtControl, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include + +#include "../../../src/core/datatypes/forte_real.h" +#include + + +BOOST_AUTO_TEST_SUITE(CIEC_REAL_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_REAL nTest; + //check type information + BOOST_REQUIRE_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_REAL); + //check operator bool data type size + BOOST_REQUIRE_EQUAL(sizeof(nTest.operator TForteFloat()), sizeof(TForteFloat)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_REAL nTest1; + CIEC_REAL nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0.0f); + + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = 2.28743e6; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 2.28743e6); + BOOST_CHECK_EQUAL(nTest2, 2.28743e6); + + nTest1 = -6.2587e-4f; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -6.2587e-4f); + BOOST_CHECK_EQUAL(nTest2, -6.2587e-4f); + + nTest1 = 1.0E-37f; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 1.0E-37f); + BOOST_CHECK_EQUAL(nTest2, 1.0E-37f); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); + + //check that assignment operator does not intertwine objects + nTest2 = -36.0; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, -36.0); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_REAL nTest; + + char cBuffer[12]; + char cBufferFail[2]; + + //check cast operator + nTest = 0.0f; + BOOST_CHECK_EQUAL(nTest.operator TForteFloat(), 0.0f); + + nTest = std::numeric_limits::min(); + BOOST_CHECK_EQUAL(nTest.operator TForteFloat(), std::numeric_limits::min()); + + nTest = -4.2345e4f; + BOOST_CHECK_EQUAL(nTest.operator TForteFloat(), -4.2345e4f); + + nTest = 23.7813e2f; + BOOST_CHECK_EQUAL(nTest.operator TForteFloat(), 23.7813e2f); + + nTest = std::numeric_limits::max(); + BOOST_CHECK_EQUAL(nTest.operator TForteFloat(), std::numeric_limits::max()); + + //check toString and fromString + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("-1E-37"), 6); + BOOST_CHECK_EQUAL(static_cast(nTest), -1.0E-37f); + +#ifdef WIN32 + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 8), 7); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-1e-037"), 0); +#else + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-1e-37"), 0); +#endif + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(static_cast(nTest), 0.0f); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("3.2523E15"), 9); + BOOST_CHECK_EQUAL(static_cast(nTest), 3.2523e15f); +#ifdef WIN32 + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 12), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "3.2523e+015"), 0); +#else + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "3.2523e+15"), 0); +#endif + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("1E37"), 4); + BOOST_CHECK_EQUAL(static_cast(nTest), 1e37f); +#ifdef WIN32 + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 6); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1e+037"), 0); +#else + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 7), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "1e+37"), 0); +#endif + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("4e40"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#100101100"), 1); + BOOST_CHECK_EQUAL(nTest.fromString("8#116100"), 1); + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), 2); + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFF0"), 2); + BOOST_CHECK_EQUAL(nTest.fromString("-4e-40"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} + +void realTypedFromString(const char *pa_acTestString, float pa_fResult){ + CIEC_REAL nTest; + BOOST_CHECK_EQUAL(nTest.fromString(pa_acTestString), strlen(pa_acTestString)); + BOOST_CHECK_EQUAL(pa_fResult, nTest); +} + +void faultingRealTypedFromString(const char *pa_acTestString){ + CIEC_REAL nTest; + BOOST_CHECK_EQUAL(nTest.fromString(pa_acTestString), -1); +} + + +BOOST_AUTO_TEST_CASE(REAL_typed_fromString_tests){ + realTypedFromString("REAL#1E37", 1e37f); + realTypedFromString("REAL#-4.2345e4",-4.2345e4f); + realTypedFromString("REAL#0",0.0f); + + faultingRealTypedFromString("REAL#4e40"); + faultingRealTypedFromString("REAL#NOT A VALID STRING"); +} + + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_SINT_CASTS_test.cpp b/tests/core/datatypes/CIEC_SINT_CASTS_test.cpp new file mode 100644 index 000000000..3445c8077 --- /dev/null +++ b/tests/core/datatypes/CIEC_SINT_CASTS_test.cpp @@ -0,0 +1,400 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE +#include + +#include "../../../src/core/datatypes/forte_real.h" +#endif + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//Time +#include "../../../src/core/datatypes/forte_time.h" + +#ifdef FORTE_USE_64BIT_DATATYPES +#include "../../../src/core/datatypes/forte_lword.h" +#include "../../../src/core/datatypes/forte_lint.h" +#include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_LREAL_DATATYPE +#include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_LREAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_SINT_casts_function_test) + +BOOST_AUTO_TEST_CASE(CASTS_SINT_to_BOOL) +{ + CIEC_SINT nTestSInt0; + CIEC_SINT nTestSInt1; + CIEC_SINT nTestSInt45; + CIEC_SINT nTestSInt127; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 0); + BOOST_CHECK_EQUAL(nTestSInt45, 0); + BOOST_CHECK_EQUAL(nTestSInt127, 0); + + nTestSInt0=0; + nTestSInt1=1; + nTestSInt45=45; + nTestSInt127=127; + + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 1); + BOOST_CHECK_EQUAL(nTestSInt45, 45); + BOOST_CHECK_EQUAL(nTestSInt127, 127); + +//checks + bTestBool.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(bTestBool, false); + bTestBool.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(bTestBool, true); + +} + +BOOST_AUTO_TEST_CASE(CASTS_SINT_to_BITDTs) +{ + CIEC_SINT nTestSInt0; + CIEC_SINT nTestSInt1; + CIEC_SINT nTestSInt45; + CIEC_SINT nTestSInt127; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES +//check initial values + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 0); + BOOST_CHECK_EQUAL(nTestSInt45, 0); + BOOST_CHECK_EQUAL(nTestSInt127, 0); + + nTestSInt0=0; + nTestSInt1=1; + nTestSInt45=45; + nTestSInt127=127; + + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 1); + BOOST_CHECK_EQUAL(nTestSInt45, 45); + BOOST_CHECK_EQUAL(nTestSInt127, 127); + +//toByte + nTestByte.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestByte, 45U); + nTestByte.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestByte, 127U); + +//toWord + nTestWord.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestWord, 45U); + nTestWord.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestWord, 127U); + +//toDWord + nTestDWord.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestDWord, 45UL); + nTestDWord.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestDWord, 127UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestLWord, 45ULL); + nTestLWord.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestLWord, 127ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_SINT_to_INTS) +{ + CIEC_SINT nTestSInt0; + CIEC_SINT nTestSInt1; + CIEC_SINT nTestSInt45; + CIEC_SINT nTestSInt127; + CIEC_SINT nTestSInt_1; + + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + //check initial values + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 0); + BOOST_CHECK_EQUAL(nTestSInt45, 0); + BOOST_CHECK_EQUAL(nTestSInt127, 0); + BOOST_CHECK_EQUAL(nTestSInt_1, 0); + + nTestSInt0=0; + nTestSInt1=1; + nTestSInt45=45; + nTestSInt127=127; + nTestSInt_1=-1; + + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 1); + BOOST_CHECK_EQUAL(nTestSInt45, 45); + BOOST_CHECK_EQUAL(nTestSInt127, 127); + BOOST_CHECK_EQUAL(nTestSInt_1, -1); + +//toUSINT + nTestUSInt.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestUSInt, 45U); + nTestUSInt.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestUSInt, 127U); + nTestUSInt.setValue(nTestSInt_1); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + +//toINT + nTestInt.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestInt, 45); + nTestInt.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestInt, 127); + nTestInt.setValue(nTestSInt_1); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toUINT + nTestUInt.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestUInt, 45U); + nTestUInt.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestUInt, 127U); + +//toDINT + nTestDInt.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestDInt, 0L); + nTestDInt.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestDInt, 1L); + nTestDInt.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestDInt, 45L); + nTestDInt.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestDInt, 127L); + nTestDInt.setValue(nTestSInt_1); + BOOST_CHECK_EQUAL(nTestDInt, -1L); + +//toUDINT + nTestUDInt.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestUDInt, 45UL); + nTestUDInt.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestUDInt, 127UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestLInt, 45LL); + nTestLInt.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestLInt, 127LL); + nTestLInt.setValue(nTestSInt_1); + BOOST_CHECK_EQUAL(nTestLInt, -1LL); + +//toULINT + nTestULInt.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestULInt, 45ULL); + nTestULInt.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestULInt, 127ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_SINT_to_REAL) +{ + CIEC_SINT nTestSInt0; + CIEC_SINT nTestSInt1; + CIEC_SINT nTestSInt45; + CIEC_SINT nTestSInt127; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 0); + BOOST_CHECK_EQUAL(nTestSInt45, 0); + BOOST_CHECK_EQUAL(nTestSInt127, 0); + + nTestSInt0=0; + nTestSInt1=1; + nTestSInt45=45; + nTestSInt127=127; + + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 1); + BOOST_CHECK_EQUAL(nTestSInt45, 45); + BOOST_CHECK_EQUAL(nTestSInt127, 127); + +//toREAL + nTestReal.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestReal, 0.0f); + nTestReal.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestReal, 1.0f); + nTestReal.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestReal, 45.0f); + nTestReal.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestReal, 127.0f); + +#ifdef FORTE_USE_64BIT_DATATYPES +#ifdef FORTE_USE_LREAL_DATATYPE + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(nTestLReal, 0.0f); + nTestLReal.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(nTestLReal, 1.0f); + nTestLReal.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(nTestLReal, 45.0f); + nTestLReal.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(nTestLReal, 127.0f); +#endif //FORTE_USE_LREAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES +} +#endif //FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_SINT_to_TIME) +{ + CIEC_SINT nTestSInt0; + CIEC_SINT nTestSInt1; + CIEC_SINT nTestSInt45; + CIEC_SINT nTestSInt127; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 0); + BOOST_CHECK_EQUAL(nTestSInt45, 0); + BOOST_CHECK_EQUAL(nTestSInt127, 0); + + nTestSInt0=0; + nTestSInt1=1; + nTestSInt45=45; + nTestSInt127=127; + + BOOST_CHECK_EQUAL(nTestSInt0, 0); + BOOST_CHECK_EQUAL(nTestSInt1, 1); + BOOST_CHECK_EQUAL(nTestSInt45, 45); + BOOST_CHECK_EQUAL(nTestSInt127, 127); + +//toTime + nTestTime.setValue(nTestSInt0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestSInt1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestSInt45); + BOOST_CHECK_EQUAL(45, nTestTime); + nTestTime.setValue(nTestSInt127); + BOOST_CHECK_EQUAL(127, nTestTime); +} + +BOOST_AUTO_TEST_CASE(SINT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_SINT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_SINT_test.cpp b/tests/core/datatypes/CIEC_SINT_test.cpp new file mode 100644 index 000000000..ff8c7dee4 --- /dev/null +++ b/tests/core/datatypes/CIEC_SINT_test.cpp @@ -0,0 +1,224 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_sint.h" + +BOOST_AUTO_TEST_SUITE(CIEC_SINT_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_SINT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_SINT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteInt8()), sizeof(TForteInt8)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_SINT nTest1; + CIEC_SINT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0); + + nTest1 = -128; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -128); + BOOST_CHECK_EQUAL(nTest2, -128); + + nTest1 = -65; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, -65); + BOOST_CHECK_EQUAL(nTest2, -65); + + nTest1 = 98; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 98); + BOOST_CHECK_EQUAL(nTest2, 98); + + nTest1 = 127; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 127); + BOOST_CHECK_EQUAL(nTest2, 127); + + //check that assignment operator does not intertwine objects + nTest2 = -74; + BOOST_CHECK_EQUAL(nTest1, 127); + BOOST_CHECK_EQUAL(nTest2, -74); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_SINT nTest; + + char cBuffer[5]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteInt8(), 0); + + nTest = -128; + BOOST_CHECK_EQUAL(nTest.operator TForteInt8(), -128); + + nTest = 53; + BOOST_CHECK_EQUAL(nTest.operator TForteInt8(), 53); + + nTest = 127; + BOOST_CHECK_EQUAL(nTest.operator TForteInt8(), 127); + + //check toString and fromString + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("-128"), 4); + BOOST_CHECK_EQUAL(nTest, -128); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 4); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-128"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#10000000"), 10); + BOOST_CHECK_EQUAL(nTest, -128); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 4); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-128"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#200"), 5); + BOOST_CHECK_EQUAL(nTest, -128); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 4); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-128"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#80"), 5); + BOOST_CHECK_EQUAL(nTest, -128); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 4); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "-128"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + strcpy(cBuffer, ""); + + + BOOST_CHECK_EQUAL(nTest.fromString("99"), 2); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1100011"), 9); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#143"), 5); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#63"), 5); + BOOST_CHECK_EQUAL(nTest, 99); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "99"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("127"), 3); + BOOST_CHECK_EQUAL(nTest, 127); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "127"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#01111111"), 10); + BOOST_CHECK_EQUAL(nTest, 127); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "127"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#177"), 5); + BOOST_CHECK_EQUAL(nTest, 127); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "127"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#7F"), 5); + BOOST_CHECK_EQUAL(nTest, 127); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 5), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "127"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("300"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#100101100"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#454"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#12C"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_STRING_test.cpp b/tests/core/datatypes/CIEC_STRING_test.cpp new file mode 100644 index 000000000..60330972f --- /dev/null +++ b/tests/core/datatypes/CIEC_STRING_test.cpp @@ -0,0 +1,403 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2013 ACIN, nxtControl, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna, Matthias Plasch - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_string.h" + +BOOST_AUTO_TEST_SUITE(CIEC_STRING_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_STRING sTest; + //check type information + BOOST_CHECK_EQUAL(sTest.getDataTypeID(), CIEC_ANY::e_STRING); + //check operator const char* data type size + BOOST_CHECK_EQUAL(sizeof(sTest.getValue()), sizeof(char*)); + +} + +BOOST_AUTO_TEST_CASE(String_manipulation_interface) +{ + CIEC_STRING sTest; + char cTest[] = "This is a test string!"; //length 22 without trailing \0 + BOOST_CHECK_EQUAL(sTest.length(), 0); + BOOST_CHECK(sTest.empty()); + + sTest = cTest; + BOOST_CHECK(! sTest.empty()); + BOOST_CHECK_EQUAL(sTest.length(), 22); + BOOST_CHECK_EQUAL(strcmp(sTest.getValue(), cTest), 0); + + CIEC_STRING* psTest = new CIEC_STRING(cTest); + BOOST_CHECK_EQUAL(psTest->length(), 22); + BOOST_CHECK_EQUAL(strcmp(psTest->getValue(), cTest), 0); + delete psTest; + +} + +BOOST_AUTO_TEST_CASE(String_assignment) +{ + CIEC_STRING sTest1; + CIEC_STRING sTest2; + char cTest1[] = "This is another test string!"; + char cTest2[] = "Check string!"; + + sTest1 = cTest1; + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + + sTest2 = sTest1; + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), sTest2.getValue()), 0); + BOOST_CHECK_EQUAL(sTest1.length(), 28); + BOOST_CHECK_EQUAL(sTest2.length(), 28); + sTest2 = cTest2; + BOOST_CHECK((0 != strcmp(sTest1.getValue(), sTest2.getValue()))); +} + +BOOST_AUTO_TEST_CASE(String_compare) +{ + CIEC_STRING sTest1; + CIEC_STRING sTest2; + CIEC_STRING sTest3; + + char cTest1[] = "Check string!"; + char cTest2[] = "Check string!"; + char cTest3[] = "checkstring!"; + + sTest1 = cTest1; + sTest2 = cTest2; + sTest3 = cTest3; + BOOST_CHECK(sTest1 == sTest2); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cTest2), 0); + + BOOST_CHECK(!(sTest1 == sTest3)); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + BOOST_CHECK_EQUAL(strcmp(sTest3.getValue(), cTest3), 0); + + BOOST_CHECK(sTest2 != sTest3); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cTest2), 0); + BOOST_CHECK_EQUAL(strcmp(sTest3.getValue(), cTest3), 0); + + BOOST_CHECK(!(sTest2 != sTest1)); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cTest2), 0); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + + + BOOST_CHECK(sTest1 == cTest2); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + + BOOST_CHECK(cTest2 == sTest1); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + + BOOST_CHECK(!(sTest1 == cTest3)); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + + BOOST_CHECK(!(cTest3 == sTest1)); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cTest1), 0); + + BOOST_CHECK(sTest2 != cTest3); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cTest2), 0); + + BOOST_CHECK(cTest3 != sTest2); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cTest2), 0); + + BOOST_CHECK(!(sTest2 != cTest1)); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cTest2), 0); + + BOOST_CHECK(!(cTest1 != sTest2)); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cTest2), 0); +} + +BOOST_AUTO_TEST_CASE(String_binary_interface) +{ + CIEC_STRING sTest1, sTest2; + char cTest[] = "This is a test\0string!"; //embedded \0, length 22 without trailing \0 + BOOST_CHECK_EQUAL(sTest1.length(), 0); + sTest1.assign(cTest, sizeof(cTest)-1); + BOOST_CHECK_EQUAL(sTest1.length(), 22); + BOOST_CHECK_EQUAL(memcmp(sTest1.getValue(), cTest, 22), 0); + + sTest2 = sTest1; + BOOST_CHECK_EQUAL(sTest2.length(), 22); + BOOST_CHECK_EQUAL(memcmp(sTest2.getValue(), cTest, 22), 0); + + CIEC_STRING* psTest = new CIEC_STRING(sTest1); + BOOST_CHECK_EQUAL(psTest->length(), 22); + BOOST_CHECK_EQUAL(memcmp(psTest->getValue(), cTest, 22), 0); + delete psTest; +} + +BOOST_AUTO_TEST_CASE(Memory_Allocation) +{ + CIEC_STRING sTest; + + BOOST_CHECK_EQUAL(sTest.length(), 0); + BOOST_CHECK_EQUAL(strlen(sTest.getValue()),0); + BOOST_CHECK_EQUAL(sTest.getValue()[0],'\0'); + sTest.reserve(10); + BOOST_CHECK_EQUAL(sTest.length(), 0); + BOOST_CHECK_EQUAL(strlen(sTest.getValue()),0); + BOOST_CHECK_EQUAL(sTest.getValue()[0],'\0'); + sTest = "Test"; + BOOST_CHECK_EQUAL(sTest.length(), 4); + sTest = "Test with more than ten characters"; + BOOST_CHECK_EQUAL(sTest.length(), 34); + + sTest = "Test Test"; + BOOST_CHECK_EQUAL(sTest.length(), 9); + + sTest = ""; + BOOST_CHECK_EQUAL(sTest.length(), 0); +} + +BOOST_AUTO_TEST_CASE(String_fromUTF8) +{ + const TForteByte cASCII1[] = { 0 }; + const TForteByte cASCII2[] = { 'A', 0 }; + const TForteByte cASCII3[] = { 0x7f, 0 }; + const TForteByte cUpper1[] = { 'A', 0xc2, 0xa2, 'A', 0 }; + const TForteByte cUpper2[] = { 'A', 0xe2, 0x82, 0xac, 'B', 0 }; + const TForteByte cUpper3[] = { 0xf0, 0xa4, 0xad, 0xa2, 0 }; + const TForteByte cInvalid1[] = { 0x80, 0 }; + const TForteByte cInvalid2[] = { 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0 }; + + int nRes; + CIEC_STRING sTest; + + nRes = sTest.fromUTF8((const char *) cASCII1, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cASCII1), nRes); + BOOST_CHECK_EQUAL(sTest.length(), 0); + + nRes = sTest.fromUTF8((const char *) cASCII2, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cASCII2), nRes); + BOOST_CHECK(! strcmp("A", sTest.getValue())); + + nRes = sTest.fromUTF8((const char *) cASCII3, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cASCII3), nRes); + BOOST_CHECK(! strcmp("\x7f", sTest.getValue())); + + nRes = sTest.fromUTF8((const char *) cUpper1, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cUpper1), nRes); + BOOST_CHECK(! strcmp("A\xa2""A", sTest.getValue())); + + nRes = sTest.fromUTF8((const char *) cUpper2, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cUpper2), nRes); + BOOST_CHECK(! strcmp("A?B", sTest.getValue())); + + nRes = sTest.fromUTF8((const char *) cUpper2, 4, false); + BOOST_CHECK_EQUAL(4, nRes); + BOOST_CHECK(! strcmp("A?", sTest.getValue())); + + nRes = sTest.fromUTF8((const char *) cUpper3, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cUpper3), nRes); + BOOST_CHECK(! strcmp("?", sTest.getValue())); + + nRes = sTest.fromUTF8((const char *) cInvalid1, -1, false); + BOOST_CHECK_EQUAL(-1, nRes); + + nRes = sTest.fromUTF8((const char *) cInvalid2, -1, false); + BOOST_CHECK_EQUAL(-1, nRes); +} + +BOOST_AUTO_TEST_CASE(String_toUTF8) +{ + const TForteByte cASCII1[] = { 0 }; + const TForteByte cASCII2[] = { 'A', 0 }; + const TForteByte cASCII3[] = { 0x7f, 0 }; + const TForteByte cUpper1[] = { 'A', 0xc2, 0xa2, 'A', 0 }; + + int nRes; + CIEC_STRING sTest; + char sResult[32]; + + sTest = ""; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 0); + BOOST_CHECK(! memcmp(sResult, cASCII1, sizeof(cASCII1))); + + sTest = "A"; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 1); + BOOST_CHECK(! memcmp(sResult, cASCII2, sizeof(cASCII2))); + nRes = sTest.toUTF8(sResult, 1, false); + BOOST_CHECK_EQUAL(nRes, -1); + + sTest = "\x7f"; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 1); + BOOST_CHECK(! memcmp(sResult, cASCII3, sizeof(cASCII3))); + nRes = sTest.toUTF8(sResult, 1, false); + BOOST_CHECK_EQUAL(nRes, -1); + nRes = sTest.toUTF8(sResult, 2, false); + BOOST_CHECK_EQUAL(nRes, 1); + + sTest = "A\xa2""A"; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 4); + BOOST_CHECK(! memcmp(sResult, cUpper1, sizeof(cUpper1))); + nRes = sTest.toUTF8(sResult, 4, false); + BOOST_CHECK_EQUAL(nRes, -1); + nRes = sTest.toUTF8(sResult, 5, false); + BOOST_CHECK_EQUAL(nRes, 4); +} + +char cTestLiteral1[] = "Test String"; +char cTestResult1[] = "Test String"; +char cTestToStringResult1[] = "\'Test String\'"; +char cTestLiteral2[] = "\'This is another test string!\'"; +char cTestResult2[] = "This is another test string!"; +char cTestDollarLiteral[] ="\'$$\'"; +char cTestDollarResult[] = "$"; +char cTestDollarToStringResult[] = "\'$$\'"; +char cTestLineFeedLiteral[] = "\'$L$l\'"; +char cTestLineFeedResult[] = {0x10, 0x10, '\0'}; +char cTestLineFeedToStringResult[] = "\'$l$l\'"; +char cTestNewLineLiteral[] = "\'$N$n\'"; +char cTestNewLineResult[] = "\n\n"; +char cTestNewLineToStringResult[] = "\'$n$n\'"; +char cTestFormFeedLiteral[] = "\'$P$p\'"; +char cTestFormFeedResult[] = "\f\f"; +char cTestFormFeedToStringResult[] = "\'$p$p\'"; +char cTestCarriageReturnLiteral[] = "\'$R$r\'"; +char cTestCarriageReturnResult[] = "\r\r"; +char cTestCarriageReturnToStringResult[] = "\'$r$r\'"; +char cTestTabLiteral[] = "\'$T$t\'"; +char cTestTabResult[] = "\t\t"; +char cTestTabToStringResult[] = "\'$t$t\'"; +char cTestSingleQuoteLiteral[] = "\'$\'\'"; +char cTestSingleQuoteResult[] = "\'"; +char cTestSingleQuoteToStringResult[] = "\'$\'\'"; +char cTestDoubleQuoteLiteral[] = "\'$\"\'"; +char cTestDoubleQuoteResult[] = "\""; +char cTestDoubleQuoteToStringResult[] = "\'$\"\'"; +char cTestEscapedCharacterLiteral[] = "\'$30\'"; +char cTestEscapedCharacterResult[] = "0"; +char cTestEscapedCharacterToStringResult[] = "\'0\'"; + +BOOST_AUTO_TEST_CASE(String_fromString) +{ + CIEC_STRING sTestee; + + BOOST_CHECK_EQUAL(strlen(cTestLiteral1), sTestee.fromString(cTestLiteral1)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestResult1)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestResult1)); + + BOOST_CHECK_EQUAL(strlen(cTestLiteral2), sTestee.fromString(cTestLiteral2)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestResult2)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestResult2)); + + BOOST_CHECK_EQUAL(strlen(cTestDollarLiteral), sTestee.fromString(cTestDollarLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestDollarResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestDollarResult)); + + BOOST_CHECK_EQUAL(strlen(cTestLineFeedLiteral), sTestee.fromString(cTestLineFeedLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestLineFeedResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestLineFeedResult)); + + BOOST_CHECK_EQUAL(strlen(cTestDollarLiteral), sTestee.fromString(cTestDollarLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestDollarResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestDollarResult)); + + BOOST_CHECK_EQUAL(strlen(cTestFormFeedLiteral), sTestee.fromString(cTestFormFeedLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestFormFeedResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestFormFeedResult)); + + BOOST_CHECK_EQUAL(strlen(cTestCarriageReturnLiteral), sTestee.fromString(cTestCarriageReturnLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestCarriageReturnResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestCarriageReturnResult)); + + BOOST_CHECK_EQUAL(strlen(cTestTabLiteral), sTestee.fromString(cTestTabLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestTabResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestTabResult)); + + BOOST_CHECK_EQUAL(strlen(cTestSingleQuoteLiteral), sTestee.fromString(cTestSingleQuoteLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestSingleQuoteResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestSingleQuoteResult)); + + BOOST_CHECK_EQUAL(strlen(cTestDoubleQuoteLiteral), sTestee.fromString(cTestDoubleQuoteLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestDoubleQuoteResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestDoubleQuoteResult)); + + BOOST_CHECK_EQUAL(strlen(cTestEscapedCharacterLiteral), sTestee.fromString(cTestEscapedCharacterLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cTestEscapedCharacterResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cTestEscapedCharacterResult)); +} + +void stringTypedFromString(const std::string &pa_sSrc, const char* pa_acResult){ + CIEC_STRING sTestee; + BOOST_CHECK_EQUAL(pa_sSrc.length(), sTestee.fromString(pa_sSrc.c_str())); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(pa_acResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), pa_acResult)); +} + +BOOST_AUTO_TEST_CASE(String_fromString_typed) +{ + stringTypedFromString(std::string("STRING#") + cTestLiteral1, cTestResult1); + stringTypedFromString(std::string("STRING#") + cTestLiteral2, cTestResult2); + stringTypedFromString(std::string("STRING#") + cTestDollarLiteral, cTestDollarResult); +} + +BOOST_AUTO_TEST_CASE(String_toString) +{ + CIEC_STRING sTestee; + char acBuffer[200]; + + sTestee = cTestResult1; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestToStringResult1)); + BOOST_CHECK_EQUAL(0, strncmp(cTestToStringResult1, acBuffer, strlen(cTestToStringResult1))); + + sTestee = cTestResult2; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestLiteral2)); + BOOST_CHECK_EQUAL(0, strncmp(cTestLiteral2, acBuffer, strlen(cTestLiteral2))); + + sTestee = cTestDollarResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestDollarToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestDollarToStringResult, acBuffer, strlen(cTestDollarToStringResult))); + + sTestee = cTestLineFeedResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestLineFeedToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestLineFeedToStringResult, acBuffer, strlen(cTestLineFeedToStringResult))); + + sTestee = cTestNewLineResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestNewLineToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestNewLineToStringResult, acBuffer, strlen(cTestNewLineToStringResult))); + + sTestee = cTestFormFeedResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestFormFeedToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestFormFeedToStringResult, acBuffer, strlen(cTestFormFeedToStringResult))); + + sTestee = cTestCarriageReturnResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestCarriageReturnToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestCarriageReturnToStringResult, acBuffer, strlen(cTestCarriageReturnToStringResult))); + + sTestee = cTestTabResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestTabToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestTabToStringResult, acBuffer, strlen(cTestTabToStringResult))); + + sTestee = cTestSingleQuoteResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestSingleQuoteToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestSingleQuoteToStringResult, acBuffer, strlen(cTestSingleQuoteToStringResult))); + + sTestee = cTestDoubleQuoteResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestDoubleQuoteToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestDoubleQuoteToStringResult, acBuffer, strlen(cTestDoubleQuoteToStringResult))); + + sTestee = cTestEscapedCharacterResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cTestEscapedCharacterToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cTestEscapedCharacterToStringResult, acBuffer, strlen(cTestEscapedCharacterToStringResult))); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_STRUCT_test.cpp b/tests/core/datatypes/CIEC_STRUCT_test.cpp new file mode 100755 index 000000000..bfea51382 --- /dev/null +++ b/tests/core/datatypes/CIEC_STRUCT_test.cpp @@ -0,0 +1,411 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_struct.h" +#include "../../../src/core/datatypes/forte_bool.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_real.h" +#include "../../../src/core/datatypes/forte_string.h" + +#include "../../../src/core/typelib.h" + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "CIEC_STRUCT_test_gen.cpp" +#endif + +BOOST_AUTO_TEST_SUITE(CIEC_STRUCT_function_test) + +/***********************************************************/ + class CIEC_TestStruct1 : public CIEC_STRUCT{ + DECLARE_FIRMWARE_DATATYPE(TestStruct1) + ; + public: + CIEC_TestStruct1() : + + CIEC_STRUCT(g_nStringIdTestStruct1, 3, scm_unElementTypes, scm_unElementNames, e_APPLICATION + e_CONSTRUCTED + 1){ + } + + virtual ~CIEC_TestStruct1(){ + } + + private: + static const CStringDictionary::TStringId scm_unElementTypes[]; + static const CStringDictionary::TStringId scm_unElementNames[]; + }; + + const CStringDictionary::TStringId CIEC_TestStruct1::scm_unElementTypes[] = { g_nStringIdSTRING, g_nStringIdBOOL, g_nStringIdINT }; + const CStringDictionary::TStringId CIEC_TestStruct1::scm_unElementNames[] = { g_nStringIdVal1, g_nStringIdVal2, g_nStringIdVal3 }; + + /***********************************************************/ + class CIEC_TestStruct2 : public CIEC_STRUCT{ + DECLARE_FIRMWARE_DATATYPE(TestStruct2) + ; + public: + CIEC_TestStruct2() : + CIEC_STRUCT(g_nStringIdTestStruct2, 4, scm_unElementTypes, scm_unElementNames, e_APPLICATION + e_CONSTRUCTED + 1){ + } + + virtual ~CIEC_TestStruct2(){ + } + + private: + static const CStringDictionary::TStringId scm_unElementTypes[]; + static const CStringDictionary::TStringId scm_unElementNames[]; + }; + + const CStringDictionary::TStringId CIEC_TestStruct2::scm_unElementTypes[] = { g_nStringIdREAL, g_nStringIdINT, g_nStringIdBOOL, g_nStringIdINT }; + const CStringDictionary::TStringId CIEC_TestStruct2::scm_unElementNames[] = { g_nStringIdVal1, g_nStringIdVal2, g_nStringIdVal3, g_nStringIdVal4 }; + +//*********************** TESTS *************************************************************************************************/ + void setDataTestStruct1(CIEC_TestStruct1 &pa_roStruct, const char* pa_acVal1, bool pa_nVal2, int pa_nVal3){ + (*(CIEC_STRING *) pa_roStruct.getMemberNamed(g_nStringIdVal1)) = pa_acVal1; + (*(CIEC_BOOL *) pa_roStruct.getMemberNamed(g_nStringIdVal2)) = pa_nVal2; + (*(CIEC_INT *) pa_roStruct.getMemberNamed(g_nStringIdVal3)) = pa_nVal3; + } + + const char cTestStringData[] = "Check string!"; + + void setupTestStruct1_TestDataSet1(CIEC_TestStruct1 &pa_stStruct){ + setDataTestStruct1(pa_stStruct, cTestStringData, true, 24534); + } + + void checkTestStruct1_InitialValues(CIEC_TestStruct1 &pa_stStruct){ + BOOST_CHECK_EQUAL((*(CIEC_STRING *)pa_stStruct.getMemberNamed(g_nStringIdVal1)).length(), 0); + BOOST_CHECK_EQUAL(false, (*(CIEC_BOOL *)pa_stStruct.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal3))); + } + + void checkTestStruct1_TestDataSet1(CIEC_TestStruct1 &pa_stStruct){ + BOOST_CHECK_EQUAL(strcmp((*(CIEC_STRING *)pa_stStruct.getMemberNamed(g_nStringIdVal1)).getValue(), cTestStringData), 0); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)pa_stStruct.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(24534, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal3))); + } + + void setDataTestStruct2(CIEC_TestStruct2&pa_roStruct, float pa_fVal1, int pa_nVal2, bool pa_bVal3, int pa_bVal4){ + (*(CIEC_REAL *) pa_roStruct.getMemberNamed(g_nStringIdVal1)) = pa_fVal1; + (*(CIEC_INT *) pa_roStruct.getMemberNamed(g_nStringIdVal2)) = pa_nVal2; + (*(CIEC_BOOL *) pa_roStruct.getMemberNamed(g_nStringIdVal3)) = pa_bVal3; + (*(CIEC_INT *) pa_roStruct.getMemberNamed(g_nStringIdVal4)) = pa_bVal4; + } + + void setupTestStruct2_TestDataSet1(CIEC_TestStruct2 &pa_stStruct){ + setDataTestStruct2(pa_stStruct, 3.1415f, 256, true, 31234); + } + + void checkTestStruct2_InitialValues(CIEC_TestStruct2 &pa_stStruct){ + BOOST_CHECK_EQUAL(0.0f, (*(CIEC_REAL *)pa_stStruct.getMemberNamed(g_nStringIdVal1))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(false, (*(CIEC_BOOL *)pa_stStruct.getMemberNamed(g_nStringIdVal3))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal4))); + } + + void checkTestStruct2_TestDataSet1(CIEC_TestStruct2 &pa_stStruct){ + BOOST_CHECK_EQUAL(3.1415f, (*(CIEC_REAL *)pa_stStruct.getMemberNamed(g_nStringIdVal1))); + BOOST_CHECK_EQUAL(256, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)pa_stStruct.getMemberNamed(g_nStringIdVal3))); + BOOST_CHECK_EQUAL(31234, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal4))); + } + + BOOST_AUTO_TEST_CASE(Struct_element_access_test){ + CIEC_TestStruct1 stStruct1; + CIEC_TestStruct2 stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.getMemberNamed(g_nStringIdVal1)->getDataTypeID(), CIEC_ANY::e_STRING); + BOOST_CHECK_EQUAL(stStruct1.getMemberNamed(g_nStringIdVal2)->getDataTypeID(), CIEC_ANY::e_BOOL); + BOOST_CHECK_EQUAL(stStruct1.getMemberNamed(g_nStringIdVal3)->getDataTypeID(), CIEC_ANY::e_INT); + + checkTestStruct1_InitialValues(stStruct1); + + char cTest[] = "Check string!"; + (*(CIEC_STRING *) stStruct1.getMemberNamed(g_nStringIdVal1)) = cTest; + BOOST_CHECK_EQUAL(strcmp((*(CIEC_STRING *)stStruct1.getMemberNamed(g_nStringIdVal1)).getValue(), cTest), 0); + BOOST_CHECK_EQUAL(false, (*(CIEC_BOOL *)stStruct1.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)stStruct1.getMemberNamed(g_nStringIdVal3))); + + (*(CIEC_BOOL *) stStruct1.getMemberNamed(g_nStringIdVal2)) = true; + BOOST_CHECK_EQUAL(strcmp((*(CIEC_STRING *)stStruct1.getMemberNamed(g_nStringIdVal1)).getValue(), cTest), 0); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)stStruct1.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)stStruct1.getMemberNamed(g_nStringIdVal3))); + + (*(CIEC_INT *) stStruct1.getMemberNamed(g_nStringIdVal3)) = 24534; + BOOST_CHECK_EQUAL(strcmp((*(CIEC_STRING *)stStruct1.getMemberNamed(g_nStringIdVal1)).getValue(), cTest), 0); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)stStruct1.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(24534, (*(CIEC_INT *)stStruct1.getMemberNamed(g_nStringIdVal3))); + + //***************** Test struct 2 ******************************************************** + BOOST_CHECK_EQUAL(stStruct2.getMemberNamed(g_nStringIdVal1)->getDataTypeID(), CIEC_ANY::e_REAL); + BOOST_CHECK_EQUAL(stStruct2.getMemberNamed(g_nStringIdVal2)->getDataTypeID(), CIEC_ANY::e_INT); + BOOST_CHECK_EQUAL(stStruct2.getMemberNamed(g_nStringIdVal3)->getDataTypeID(), CIEC_ANY::e_BOOL); + BOOST_CHECK_EQUAL(stStruct2.getMemberNamed(g_nStringIdVal4)->getDataTypeID(), CIEC_ANY::e_INT); + + checkTestStruct2_InitialValues(stStruct2); + + (*(CIEC_REAL *) stStruct2.getMemberNamed(g_nStringIdVal1)) = 3.1415f; + BOOST_CHECK_EQUAL(3.1415f, (*(CIEC_REAL *)stStruct2.getMemberNamed(g_nStringIdVal1))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(false, (*(CIEC_BOOL *)stStruct2.getMemberNamed(g_nStringIdVal3))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal4))); + + (*(CIEC_INT *) stStruct2.getMemberNamed(g_nStringIdVal2)) = 256; + BOOST_CHECK_EQUAL(3.1415f, (*(CIEC_REAL *)stStruct2.getMemberNamed(g_nStringIdVal1))); + BOOST_CHECK_EQUAL(256, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(false, (*(CIEC_BOOL *)stStruct2.getMemberNamed(g_nStringIdVal3))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal4))); + + (*(CIEC_BOOL *) stStruct2.getMemberNamed(g_nStringIdVal3)) = true; + BOOST_CHECK_EQUAL(3.1415f, (*(CIEC_REAL *)stStruct2.getMemberNamed(g_nStringIdVal1))); + BOOST_CHECK_EQUAL(256, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)stStruct2.getMemberNamed(g_nStringIdVal3))); + BOOST_CHECK_EQUAL(0, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal4))); + + (*(CIEC_INT *) stStruct2.getMemberNamed(g_nStringIdVal4)) = 31234; + BOOST_CHECK_EQUAL(3.1415f, (*(CIEC_REAL *)stStruct2.getMemberNamed(g_nStringIdVal1))); + BOOST_CHECK_EQUAL(256, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)stStruct2.getMemberNamed(g_nStringIdVal3))); + BOOST_CHECK_EQUAL(31234, (*(CIEC_INT *)stStruct2.getMemberNamed(g_nStringIdVal4))); + } + + BOOST_AUTO_TEST_CASE(Struct_copy_test_teststruct1){ + CIEC_TestStruct1 stStruct1; + CIEC_TestStruct1 stStruct2; + + setupTestStruct1_TestDataSet1(stStruct1); + checkTestStruct1_TestDataSet1(stStruct1); + checkTestStruct1_InitialValues(stStruct2); + + //self assign + stStruct1 = stStruct1; + checkTestStruct1_TestDataSet1(stStruct1); + + //default initialized self assign + stStruct2 = stStruct2; + checkTestStruct1_InitialValues(stStruct2); + + //copy struct via assignment operator + stStruct2 = stStruct1; + checkTestStruct1_TestDataSet1(stStruct2); + } + + BOOST_AUTO_TEST_CASE(Struct_copy_test_teststruct2){ + CIEC_TestStruct2 stStruct1; + CIEC_TestStruct2 stStruct2; + + setupTestStruct2_TestDataSet1(stStruct1); + checkTestStruct2_InitialValues(stStruct2); + + //self assign + stStruct1 = stStruct1; + checkTestStruct2_TestDataSet1(stStruct1); + + //default initialized self assign + stStruct2 = stStruct2; + checkTestStruct2_InitialValues(stStruct2); + + //copy struct via assignment operator + stStruct2 = stStruct1; + checkTestStruct2_TestDataSet1(stStruct2); + } + + const char cTestFromString_String1[] = "String1"; + + void checkTestStruct1_fromStringTestData(CIEC_TestStruct1 &pa_stStruct){ + BOOST_CHECK_EQUAL(strcmp((*(CIEC_STRING *)pa_stStruct.getMemberNamed(g_nStringIdVal1)).getValue(), cTestFromString_String1), 0); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)pa_stStruct.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(23451, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal3))); + } + + BOOST_AUTO_TEST_CASE(Struct_fromString_TestStruct1){ + CIEC_TestStruct1 stStruct1; + CIEC_TestStruct1 stStruct2; //emtpy struct for resting the values after each parse + + const char cTestString1[] = { "(Val1:='String1',Val2:=true,Val3:=23451)" }; + const char cTestString2[] = { "( Val1:='String1', Val2:=true, Val3 :=23451)" }; + const char cTestString3[] = { "(Val1:='String1' , Val2:=true, Val3:= 23451)" }; + const char cTestString4[] = { "( Val1:= 'String1',Val2:= true, Val3:=23451)" }; + const char cTestString5[] = { "(Val1:='String1', Val2 := true,Val3:=23451)" }; + const char cTestString6[] = { "(Val1:='String1', Val2:=true, Val3:= 23451 )" }; + const char cTestString7[] = { "(Val2:=true, Val1:='String1', Val3:= 23451)" }; + const char cTestString8[] = { "(Val2:=true, Val3:= 23451, Val1:='String1')" }; + const char cTestString9[] = { "(Val3:= 23451, Val1:='String1', Val2:=true)" }; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString1), strlen(cTestString1)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString2), strlen(cTestString2)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString3), strlen(cTestString3)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString4), strlen(cTestString4)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString5), strlen(cTestString5)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString6), strlen(cTestString6)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString7), strlen(cTestString7)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString8), strlen(cTestString8)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString9), strlen(cTestString9)); + checkTestStruct1_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + //negative tests: these strings should produce error responses + const char cTestStringNIO1[] = { "(Val1:='String1', Val2:=true, Val3:=23451, seppi)" }; + const char cTestStringNIO2[] = { "(Val1:='String1', Val2:=1234, Val3:=23451)" }; + const char cTestStringNIO3[] = { "(Val1:='String1', Val2:=true, Val3:=23.3)" }; + const char cTestStringNIO4[] = { "(Val4:='String1', Val2:=true, Val3:=23.3)" }; + const char cTestStringNIO5[] = { "(Val2:='String1', Val2:=true, Val3:=23451)" }; + const char cTestStringNIO6[] = { "(Val1:='String1', Val3:=true, Val1:=23451)" }; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO1), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO2), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO3), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO4), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO5), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO6), -1); + + } + + void checkTestStruct2_fromStringTestData(CIEC_TestStruct2 &pa_stStruct){ + BOOST_CHECK_EQUAL(15.65789f, (*(CIEC_REAL *)pa_stStruct.getMemberNamed(g_nStringIdVal1))); + BOOST_CHECK_EQUAL(32765, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal2))); + BOOST_CHECK_EQUAL(true, (*(CIEC_BOOL *)pa_stStruct.getMemberNamed(g_nStringIdVal3))); + BOOST_CHECK_EQUAL(13, (*(CIEC_INT *)pa_stStruct.getMemberNamed(g_nStringIdVal4))); + } + + BOOST_AUTO_TEST_CASE(Struct_fromString_TestStruct2){ + CIEC_TestStruct2 stStruct1; + CIEC_TestStruct2 stStruct2; //emtpy struct for resting the values after each parse + + const char cTestString1[] = { "(Val1:=15.65789,Val2:=32765,Val3:=TRUE, Val4:=13)" }; + const char cTestString2[] = { "(Val1 := 15.65789 , Val2:= 32765,Val3:= TRUE, Val4:=13)" }; + const char cTestString3[] = { "(Val1:=15.65789, Val2 := 32765 , Val3 := TRUE, Val4:=13 )" }; + const char cTestString4[] = { "( Val1:=15.65789 , Val2 := 32765,Val3:=TRUE, Val4:=13)" }; + const char cTestString5[] = { "( Val1:=15.65789 , Val2:=32765,Val3:=TRUE, Val4:=13)" }; + const char cTestString6[] = { "(Val3:=TRUE, Val1:=15.65789,Val2:=32765,Val4:=13)" }; + const char cTestString7[] = { "(Val1:=15.65789,Val3:=TRUE, Val4:=13,Val2:=32765)" }; + const char cTestString8[] = { "(Val1:=15.65789,Val2:=32765,Val3:=TRUE, Val4:=13)" }; + const char cTestString9[] = { "(Val1:=15.65789, Val4:=13,Val3:=TRUE, Val2:=32765)" }; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString1), strlen(cTestString1)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString2), strlen(cTestString2)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString3), strlen(cTestString3)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString4), strlen(cTestString4)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString5), strlen(cTestString5)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString6), strlen(cTestString6)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString7), strlen(cTestString7)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString8), strlen(cTestString8)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestString9), strlen(cTestString9)); + checkTestStruct2_fromStringTestData(stStruct1); + stStruct1 = stStruct2; + + const char cTestStringNIO1[] = { "(Val1:=15.65789,Val2:=3,Val3:=TRUE, Val4:=13, seppi)" }; + const char cTestStringNIO2[] = { "(Hansi:=15.65789,Val2:=true,Val3:=TRUE, Val4:=13)" }; + const char cTestStringNIO3[] = { "(Val1:='test',Val2:=true,Val3:=TRUE, Val4:=13)" }; + const char cTestStringNIO4[] = { "(Val1:=15.65789 Val2:=23,Val3:=TRUE, Val4:=13)" }; + const char cTestStringNIO5[] = { "(Val1:=15.65789,Val2:=true,Val3:=TRUE, Val4:=13.13)" }; + + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO1), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO2), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO3), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO4), -1); + BOOST_CHECK_EQUAL(stStruct1.fromString(cTestStringNIO5), -1); + } + + void toStringTest_testStruct1(const char* pa_acVal1, bool pa_nVal2, int pa_nVal3, const char* pa_acResult){ + CIEC_TestStruct1 stStruct; + int nResultLenght = strlen(pa_acResult); + char acBuffer[50]; + + for(int i = (nResultLenght + 1); i < 50; i++){ + setDataTestStruct1(stStruct, pa_acVal1, pa_nVal2, pa_nVal3); + BOOST_CHECK_EQUAL(stStruct.toString(acBuffer, i), nResultLenght); + BOOST_CHECK_EQUAL(strcmp(acBuffer, pa_acResult), 0); + } + for(int i = 0; i <= nResultLenght; i++){ + BOOST_CHECK_EQUAL(stStruct.toString(acBuffer, i), -1); + } + } + + BOOST_AUTO_TEST_CASE(Struct_toString_TestStruct1){ + toStringTest_testStruct1("", false, 0, "(Val1:='',Val2:=FALSE,Val3:=0)"); + toStringTest_testStruct1("", true, 0, "(Val1:='',Val2:=TRUE,Val3:=0)"); + toStringTest_testStruct1("Hansi Test", true, 0, "(Val1:='Hansi Test',Val2:=TRUE,Val3:=0)"); + toStringTest_testStruct1("", true, 2345, "(Val1:='',Val2:=TRUE,Val3:=2345)"); + } + + void toStringTest_testStruct2(float pa_fVal1, int pa_nVal2, bool pa_bVal3, int pa_nVal4, const char* pa_acResult){ + CIEC_TestStruct2 stStruct; + int nResultLenght = strlen(pa_acResult); + char acBuffer[60]; + + for(int i = (nResultLenght + 1); i < 60; i++){ + setDataTestStruct2(stStruct, pa_fVal1, pa_nVal2, pa_bVal3, pa_nVal4); + BOOST_CHECK_EQUAL(stStruct.toString(acBuffer, i), nResultLenght); + BOOST_CHECK_EQUAL(strcmp(acBuffer, pa_acResult), 0); + } + for(int i = 0; i <= nResultLenght; i++){ + BOOST_CHECK_EQUAL(stStruct.toString(acBuffer, i), -1); + } + } + + BOOST_AUTO_TEST_CASE(Struct_toString_TestStruct2){ + toStringTest_testStruct2(0.0f, 0, false, 0, "(Val1:=0,Val2:=0,Val3:=FALSE,Val4:=0)"); + toStringTest_testStruct2(0.0f, 0, true, 0, "(Val1:=0,Val2:=0,Val3:=TRUE,Val4:=0)"); + toStringTest_testStruct2(0.0f, 32767, false, -32768, "(Val1:=0,Val2:=32767,Val3:=FALSE,Val4:=-32768)"); + toStringTest_testStruct2(1345.13f, 32767, false, -32768, "(Val1:=1345.13,Val2:=32767,Val3:=FALSE,Val4:=-32768)"); + toStringTest_testStruct2(1345.13f, -32767, false, -32768, "(Val1:=1345.13,Val2:=-32767,Val3:=FALSE,Val4:=-32768)"); + + } + + + // + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_TIME_OF_DAY_test.cpp b/tests/core/datatypes/CIEC_TIME_OF_DAY_test.cpp new file mode 100644 index 000000000..0d0eb789a --- /dev/null +++ b/tests/core/datatypes/CIEC_TIME_OF_DAY_test.cpp @@ -0,0 +1,215 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_time_of_day.h" + +BOOST_AUTO_TEST_SUITE(CIEC_TIME_OF_DAY_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_TIME_OF_DAY nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_TIME_OF_DAY); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteUInt64()), sizeof(TForteUInt64)); + +} + +BOOST_AUTO_TEST_CASE(Operator_test) +{ + CIEC_TIME_OF_DAY nTest1; + CIEC_TIME_OF_DAY nTest2; + + //check if data type is initialized with value of zero + BOOST_CHECK_EQUAL(nTest1,0ULL); + + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = 123894391ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 123894391ULL); + BOOST_CHECK_EQUAL(nTest2, 123894391ULL); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); + + nTest2 = 2145729524ULL; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, 2145729524ULL); + + ++nTest2; + BOOST_CHECK_EQUAL(nTest2, 2145729525ULL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_TIME_OF_DAY nTest; + + char cBuffer[17]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 0ULL); + + nTest = std::numeric_limits::min(); + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), std::numeric_limits::min()); + + nTest = -21654147L; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 18446744073687897469ULL); + + nTest = std::numeric_limits::max(); + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), std::numeric_limits::max()); + + //check toString and fromString + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.36"), 11); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.360"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55"), 8); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.000"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55."), 9); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.000"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.0"), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.000"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.1"), 10); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.100"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.10"), 11); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.100"), 0); + + nTest = 0; + strcpy(cBuffer, ""); + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.100"), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.100"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.12"), 11); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.120"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.120"), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.120"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.123"), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.123"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("15:36:55.1234"), 13); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.123"), 0); + strcpy(cBuffer, ""); + + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("TIME_OF_DAY#15:36:55.36"), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.360"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("time_of_day#15:36:55.36"), 23); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.360"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("TOD#15:36:55.36"), 15); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.360"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("tod#15:36:55.36"), 15); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "15:36:55.360"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("8:6:5.6"), 7); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "08:06:05.600"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("TIME_OF_DAY#8:6:5.6"), 19); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "08:06:05.600"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("time_of_day#8:6:5.6"), 19); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "08:06:05.600"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("TOD#8:6:5.6"), 11); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "08:06:05.600"), 0); + strcpy(cBuffer, ""); + + nTest = 0; + BOOST_CHECK_EQUAL(nTest.fromString("tod#8:6:5.6"), 11); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "08:06:05.600"), 0); + strcpy(cBuffer, ""); + +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_TIME_test.cpp b/tests/core/datatypes/CIEC_TIME_test.cpp new file mode 100644 index 000000000..718e13f4e --- /dev/null +++ b/tests/core/datatypes/CIEC_TIME_test.cpp @@ -0,0 +1,216 @@ +/******************************************************************************* + * Copyright (c) 2011, 2103 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_time.h" + +BOOST_AUTO_TEST_SUITE(CIEC_TIME_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_TIME nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_TIME); + //check operator bool data type size +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteInt64()), sizeof(TForteInt64)); +#else + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteInt32()), sizeof(TForteInt32)); +#endif +} + +BOOST_AUTO_TEST_CASE(Operator_test) +{ + CIEC_TIME nTest1; + CIEC_TIME nTest2; + + //check if data type is initialized with value of zero + BOOST_CHECK_EQUAL(nTest1,0); + +#ifdef FORTE_USE_64BIT_DATATYPES + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); +#endif + + nTest1 = std::numeric_limits::min(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::min()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::min()); + + nTest1 = 9657545ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 9657545LL); + BOOST_CHECK_EQUAL(nTest2, 9657545LL); + + nTest1 = std::numeric_limits::max(); + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, std::numeric_limits::max()); + + nTest2 = 564874642ULL; + BOOST_CHECK_EQUAL(nTest1, std::numeric_limits::max()); + BOOST_CHECK_EQUAL(nTest2, 564874642LL); + + ++nTest2; + BOOST_CHECK_EQUAL(nTest2, 564874643LL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_TIME nTest; + + char cBuffer[17]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), 0); +#else + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), 0); +#endif + + nTest = std::numeric_limits::min(); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), std::numeric_limits::min()); +#else + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), std::numeric_limits::min()); +#endif + nTest = -21654147L; +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), -21654147L); +#else + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), -21654147L); +#endif + nTest = std::numeric_limits::max(); +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_CHECK_EQUAL(nTest.operator TForteInt64(), std::numeric_limits::max()); +#else + BOOST_CHECK_EQUAL(nTest.operator TForteInt32(), std::numeric_limits::max()); +#endif + //check toString and fromString + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("4h36m"), 1); + /*BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#16560000ms"), 0); + strcpy(cBuffer, "");*/ + + BOOST_CHECK_EQUAL(nTest.fromString("TIME#4h36m"), 10); + BOOST_CHECK_EQUAL(nTest, 16560000LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000)); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#16560000ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("time#4h36m"), 10); + BOOST_CHECK_EQUAL(nTest, 16560000LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000)); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#16560000ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("T#4h36m"), 7); + BOOST_CHECK_EQUAL(nTest, 16560000LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000)); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#16560000ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("t#4h36m"), 7); + BOOST_CHECK_EQUAL(nTest, 16560000LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000)); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 12); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#16560000ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("3s_22ms"), 1); + /*BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 17); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#3022ms"), 0); + strcpy(cBuffer, "");*/ + + BOOST_CHECK_EQUAL(nTest.fromString("TIME#3s_22ms"), 12); + BOOST_CHECK_EQUAL(nTest, (CIEC_TIME::TValueType)(3022LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000LL))); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 8); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#3022ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("time#3s_22ms"), 12); + BOOST_CHECK_EQUAL(nTest, 3022LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000LL)); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 8); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#3022ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("T#3s_22ms"), 9); + BOOST_CHECK_EQUAL(nTest, 3022LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000LL)); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 8); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#3022ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("t#3s_22ms"), 9); + BOOST_CHECK_EQUAL(nTest, 3022LL * (FORTE_TIME_BASE_UNITS_PER_SECOND / 1000LL)); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 17), 8); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "T#3022ms"), 0); + strcpy(cBuffer, ""); + nTest = 0; +} + +BOOST_AUTO_TEST_CASE(time_comparision_tests) +{ + CIEC_TIME time1, time2; + + time1.setFromMiliSeconds(200); + time2.setFromMiliSeconds(200); + + BOOST_CHECK(time1 == time2); + BOOST_CHECK_EQUAL(true, time1 >= time2); + BOOST_CHECK_EQUAL(true, time1 <= time2); + + time2.setFromMiliSeconds(150); + + BOOST_CHECK_EQUAL(true, time1 > time2); + BOOST_CHECK_EQUAL(true, time1 >= time2); + BOOST_CHECK_EQUAL(true, time1 != time2); + BOOST_CHECK_EQUAL(false, time1 < time2); + BOOST_CHECK_EQUAL(false, time1 <= time2); + + time1.setFromMiliSeconds(120); + BOOST_CHECK_EQUAL(false, time1 > time2); + BOOST_CHECK_EQUAL(false, time1 >= time2); + BOOST_CHECK_EQUAL(true, time1 != time2); + BOOST_CHECK_EQUAL(true, time1 < time2); + BOOST_CHECK_EQUAL(true, time1 <= time2); + +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_UDINT_CASTS_test.cpp b/tests/core/datatypes/CIEC_UDINT_CASTS_test.cpp new file mode 100644 index 000000000..5f8378a1c --- /dev/null +++ b/tests/core/datatypes/CIEC_UDINT_CASTS_test.cpp @@ -0,0 +1,408 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//Time +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_UDINT_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_UDINT_to_BOOL) +{ + CIEC_UDINT nTestUDInt0; + CIEC_UDINT nTestUDInt1; + CIEC_UDINT nTestUDInt65536; + CIEC_UDINT nTestUDInt4294967295; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 0UL); + + nTestUDInt0=0UL; + nTestUDInt1=1UL; + nTestUDInt65536=65536UL; + nTestUDInt4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 1UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 65536UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 4294967295UL); + +//checks + bTestBool.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(false, bTestBool); + bTestBool.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_UDINT_to_BITDTs) +{ + CIEC_UDINT nTestUDInt0; + CIEC_UDINT nTestUDInt1; + CIEC_UDINT nTestUDInt65536; + CIEC_UDINT nTestUDInt4294967295; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 0UL); + + nTestUDInt0=0UL; + nTestUDInt1=1UL; + nTestUDInt65536=65536UL; + nTestUDInt4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 1UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 65536UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 4294967295UL); + +//toByte + nTestByte.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toWord + nTestWord.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestWord, 65535U); + +//toDWord + nTestDWord.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestDWord, 65536UL); + nTestDWord.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestDWord, 4294967295UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestLWord, 65536ULL); + nTestLWord.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestLWord, 4294967295ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_UDINT_to_INTS) +{ + CIEC_UDINT nTestUDInt0; + CIEC_UDINT nTestUDInt1; + CIEC_UDINT nTestUDInt65536; + CIEC_UDINT nTestUDInt4294967295; + + CIEC_SINT nTestSInt; + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 0UL); + + nTestUDInt0=0UL; + nTestUDInt1=1UL; + nTestUDInt65536=65536UL; + nTestUDInt4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 1UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 65536UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 4294967295UL); + +//toSINT + nTestSInt.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUSINT + nTestUSInt.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + +//toINT + nTestInt.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toUINT + nTestUInt.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + +//toDINT + nTestDInt.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestDInt, 0L); + nTestDInt.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestDInt, 1L); + nTestDInt.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestDInt, 65536L); + nTestDInt.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestDInt, -1L); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestLInt, 65536LL); + nTestLInt.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestLInt, 4294967295LL); + +//toULINT + nTestULInt.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(nTestULInt, 65536ULL); + nTestULInt.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(nTestULInt, 4294967295ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_UDINT_to_REAL) +{ + CIEC_UDINT nTestUDInt0; + CIEC_UDINT nTestUDInt1; + CIEC_UDINT nTestUDInt65536; + CIEC_UDINT nTestUDInt4294967295; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 0UL); + + nTestUDInt0=0UL; + nTestUDInt1=1UL; + nTestUDInt65536=65536UL; + nTestUDInt4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 1UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 65536UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 4294967295UL); + +//toREAL + nTestReal.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(65536.0f, nTestReal); + nTestReal.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(4294967295.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(65536.0, nTestLReal); + nTestLReal.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(4294967295.0,nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + + +BOOST_AUTO_TEST_CASE(CASTS_UDINT_to_TIME) +{ + CIEC_UDINT nTestUDInt0; + CIEC_UDINT nTestUDInt1; + CIEC_UDINT nTestUDInt65536; + CIEC_UDINT nTestUDInt4294967295; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 0UL); + + nTestUDInt0=0UL; + nTestUDInt1=1UL; + nTestUDInt65536=65536UL; + nTestUDInt4294967295=4294967295UL; + + BOOST_CHECK_EQUAL(nTestUDInt0, 0UL); + BOOST_CHECK_EQUAL(nTestUDInt1, 1UL); + BOOST_CHECK_EQUAL(nTestUDInt65536, 65536UL); + BOOST_CHECK_EQUAL(nTestUDInt4294967295, 4294967295UL); + +//toTime +#ifdef FORTE_USE_64BIT_DATATYPES + nTestTime.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(0LL, nTestTime); + nTestTime.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(1LL, nTestTime); + nTestTime.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(65536LL, nTestTime); + nTestTime.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(4294967295LL, nTestTime); +#else + nTestTime.setValue(nTestUDInt0); + BOOST_CHECK_EQUAL(0L, nTestTime); + nTestTime.setValue(nTestUDInt1); + BOOST_CHECK_EQUAL(1L, nTestTime); + nTestTime.setValue(nTestUDInt65536); + BOOST_CHECK_EQUAL(65536L, nTestTime); + nTestTime.setValue(nTestUDInt4294967295); + BOOST_CHECK_EQUAL(-1L, nTestTime); +#endif +} + +BOOST_AUTO_TEST_CASE(UDINT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UDINT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_UDINT_test.cpp b/tests/core/datatypes/CIEC_UDINT_test.cpp new file mode 100644 index 000000000..f4d1f84bc --- /dev/null +++ b/tests/core/datatypes/CIEC_UDINT_test.cpp @@ -0,0 +1,205 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_udint.h" + +BOOST_AUTO_TEST_SUITE(CIEC_UDINT_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_UDINT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_UDINT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteUInt32()), sizeof(TForteUInt32)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_UDINT nTest1; + CIEC_UDINT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0UL); + + nTest1 = 0; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0UL); + BOOST_CHECK_EQUAL(nTest2, 0UL); + + nTest1 = 13546842UL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 13546842UL); + BOOST_CHECK_EQUAL(nTest2, 13546842UL); + + nTest1 = 4294967295UL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 4294967295UL); + BOOST_CHECK_EQUAL(nTest2, 4294967295UL); + + //check that assignment operator does not intertwine objects + nTest2 = 951753258UL; + BOOST_CHECK_EQUAL(nTest1, 4294967295UL); + BOOST_CHECK_EQUAL(nTest2, 951753258UL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_UDINT nTest; + + char cBuffer[11]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteUInt32(), 0UL); + + nTest = 654753258UL; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt32(), 654753258UL); + + nTest = 4294967295UL; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt32(), 4294967295UL); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("147896321"), 9); + BOOST_CHECK_EQUAL(nTest, 147896321UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 9); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "147896321"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1000110100001011100000000001"), 30); + BOOST_CHECK_EQUAL(nTest, 147896321UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 9); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "147896321"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#1064134001"), 12); + BOOST_CHECK_EQUAL(nTest, 147896321UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 9); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "147896321"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#8D0B801"), 10); + BOOST_CHECK_EQUAL(nTest, 147896321UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 9); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "147896321"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("4294967295"), 10); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#11111111111111111111111111111111"), 34); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#37777777777"), 13); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFFFFFF"), 11); + BOOST_CHECK_EQUAL(nTest, 4294967295UL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 11), 10); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "4294967295"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("42949672958"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#1111111111111111111111111111111100"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#377777777770"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#5294967295"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFFFFFF0"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_UINT_CASTS_test.cpp b/tests/core/datatypes/CIEC_UINT_CASTS_test.cpp new file mode 100644 index 000000000..a1145c7d1 --- /dev/null +++ b/tests/core/datatypes/CIEC_UINT_CASTS_test.cpp @@ -0,0 +1,396 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_UINT_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_UINT_to_BOOL) +{ + CIEC_UINT nTestUInt0; + CIEC_UINT nTestUInt1; + CIEC_UINT nTestUInt256; + CIEC_UINT nTestUInt65535; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestUInt0, 0); + BOOST_CHECK_EQUAL(nTestUInt1, 0); + BOOST_CHECK_EQUAL(nTestUInt256, 0); + BOOST_CHECK_EQUAL(nTestUInt65535, 0); + + nTestUInt0=0; + nTestUInt1=1; + nTestUInt256=256; + nTestUInt65535=65535; + + BOOST_CHECK_EQUAL(nTestUInt0, 0); + BOOST_CHECK_EQUAL(nTestUInt1, 1); + BOOST_CHECK_EQUAL(nTestUInt256, 256); + BOOST_CHECK_EQUAL(nTestUInt65535, 65535); + +//checks + bTestBool.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(false, bTestBool); + bTestBool.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_UINT_to_BITDTs) +{ + CIEC_UINT nTestUInt0; + CIEC_UINT nTestUInt1; + CIEC_UINT nTestUInt256; + CIEC_UINT nTestUInt65535; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestUInt0, 0); + BOOST_CHECK_EQUAL(nTestUInt1, 0); + BOOST_CHECK_EQUAL(nTestUInt256, 0); + BOOST_CHECK_EQUAL(nTestUInt65535, 0); + + nTestUInt0=0; + nTestUInt1=1; + nTestUInt256=256; + nTestUInt65535=65535; + + BOOST_CHECK_EQUAL(nTestUInt0, 0); + BOOST_CHECK_EQUAL(nTestUInt1, 1); + BOOST_CHECK_EQUAL(nTestUInt256, 256); + BOOST_CHECK_EQUAL(nTestUInt65535, 65535); + +//toByte + nTestByte.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestByte, 0); + nTestByte.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestByte, 1); + nTestByte.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestByte, 0); + nTestByte.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestByte, 255); + +//toWord + nTestWord.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestWord, 0); + nTestWord.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestWord, 1); + nTestWord.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestWord, 256); + nTestWord.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestWord, 65535); + +//toDWord + nTestDWord.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestDWord, 256UL); + nTestDWord.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestDWord, 65535UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestLWord, 256ULL); + nTestLWord.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestLWord, 65535ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_UINT_to_INTS) +{ + CIEC_UINT nTestUInt0; + CIEC_UINT nTestUInt1; + CIEC_UINT nTestUInt256; + CIEC_UINT nTestUInt65535; + + CIEC_SINT nTestSInt; + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestUInt0, 0U); + BOOST_CHECK_EQUAL(nTestUInt1, 0U); + BOOST_CHECK_EQUAL(nTestUInt256, 0U); + BOOST_CHECK_EQUAL(nTestUInt65535, 0U); + + nTestUInt0=0U; + nTestUInt1=1U; + nTestUInt256=256U; + nTestUInt65535=65535U; + + BOOST_CHECK_EQUAL(nTestUInt0, 0U); + BOOST_CHECK_EQUAL(nTestUInt1, 1U); + BOOST_CHECK_EQUAL(nTestUInt256, 256U); + BOOST_CHECK_EQUAL(nTestUInt65535, 65535U); + +//toSINT + nTestSInt.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUSINT + nTestUSInt.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + +//toINT + nTestInt.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestInt, 256); + nTestInt.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestInt, -1); + + +//toDINT + nTestDInt.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestDInt, 1); + nTestDInt.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestDInt, 256); + nTestDInt.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestDInt, 65535); + +//toUDINT + nTestUDInt.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestUDInt, 256UL); + nTestUDInt.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestUDInt, 65535UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestLInt, 256LL); + nTestLInt.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestLInt, 65535LL); + +//toULINT + nTestULInt.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(nTestULInt, 256ULL); + nTestULInt.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(nTestULInt, 65535ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_UINT_to_REAL) +{ + CIEC_UINT nTestUInt0; + CIEC_UINT nTestUInt1; + CIEC_UINT nTestUInt256; + CIEC_UINT nTestUInt65535; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestUInt0, 0U); + BOOST_CHECK_EQUAL(nTestUInt1, 0U); + BOOST_CHECK_EQUAL(nTestUInt256, 0U); + BOOST_CHECK_EQUAL(nTestUInt65535, 0U); + + nTestUInt0=0U; + nTestUInt1=1U; + nTestUInt256=256U; + nTestUInt65535=65535U; + + BOOST_CHECK_EQUAL(nTestUInt0, 0U); + BOOST_CHECK_EQUAL(nTestUInt1, 1U); + BOOST_CHECK_EQUAL(nTestUInt256, 256U); + BOOST_CHECK_EQUAL(nTestUInt65535, 65535U); + +//toREAL + nTestReal.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(256.0f, nTestReal); + nTestReal.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(65535.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(256.0, nTestLReal); + nTestLReal.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(65535.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(CASTS_UINT_to_TIME) +{ + CIEC_UINT nTestUInt0; + CIEC_UINT nTestUInt1; + CIEC_UINT nTestUInt256; + CIEC_UINT nTestUInt65535; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestUInt0, 0U); + BOOST_CHECK_EQUAL(nTestUInt1, 0U); + BOOST_CHECK_EQUAL(nTestUInt256, 0U); + BOOST_CHECK_EQUAL(nTestUInt65535, 0U); + + nTestUInt0=0U; + nTestUInt1=1U; + nTestUInt256=256U; + nTestUInt65535=65535U; + + BOOST_CHECK_EQUAL(nTestUInt0, 0U); + BOOST_CHECK_EQUAL(nTestUInt1, 1U); + BOOST_CHECK_EQUAL(nTestUInt256, 256U); + BOOST_CHECK_EQUAL(nTestUInt65535, 65535U); + +//toTIME + nTestTime.setValue(nTestUInt0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestUInt1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestUInt256); + BOOST_CHECK_EQUAL(256, nTestTime); + nTestTime.setValue(nTestUInt65535); + BOOST_CHECK_EQUAL(65535, nTestTime); +} + +BOOST_AUTO_TEST_CASE(UINT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_UINT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_UINT_test.cpp b/tests/core/datatypes/CIEC_UINT_test.cpp new file mode 100644 index 000000000..5f5de5b6f --- /dev/null +++ b/tests/core/datatypes/CIEC_UINT_test.cpp @@ -0,0 +1,200 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_uint.h" + +BOOST_AUTO_TEST_SUITE(CIEC_UINT_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_UINT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_UINT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteUInt16()), sizeof(TForteUInt16)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_UINT nTest1; + CIEC_UINT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0); + + nTest1 = 0; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0); + BOOST_CHECK_EQUAL(nTest2, 0); + + nTest1 = 23584; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 23584); + BOOST_CHECK_EQUAL(nTest2, 23584); + + nTest1 = 65535; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 65535); + BOOST_CHECK_EQUAL(nTest2, 65535); + + //check that assignment operator does not intertwine objects + nTest2 = 12800; + BOOST_CHECK_EQUAL(nTest1, 65535); + BOOST_CHECK_EQUAL(nTest2, 12800); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_UINT nTest; + + char cBuffer[6]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteUInt16(), 0); + + nTest = 2453; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt16(), 2453); + + nTest = 65535; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt16(), 65535); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + + BOOST_CHECK_EQUAL(nTest.fromString("38549"), 5); + BOOST_CHECK_EQUAL(nTest, 38549); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "38549"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1001011010010101"), 18); + BOOST_CHECK_EQUAL(nTest, 38549); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "38549"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#113225"), 8); + BOOST_CHECK_EQUAL(nTest, 38549); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "38549"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#9695"), 7); + BOOST_CHECK_EQUAL(nTest, 38549); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "38549"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("65535"), 5); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1111111111111111"), 18); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#177777"), 8); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFF"), 7); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("70000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#111111111111111100"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#200000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#70000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFF0"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_ULINT_CASTS_test.cpp b/tests/core/datatypes/CIEC_ULINT_CASTS_test.cpp new file mode 100644 index 000000000..86c16fecc --- /dev/null +++ b/tests/core/datatypes/CIEC_ULINT_CASTS_test.cpp @@ -0,0 +1,392 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifdef FORTE_USE_64BIT_DATATYPES +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//time +#include "../../../src/core/datatypes/forte_time.h" + + + + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE + + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_ULINT_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_ULINT_to_BOOL) +{ + CIEC_ULINT nTestULInt0; + CIEC_ULINT nTestULInt1; + CIEC_ULINT nTestULInt2147483648; + CIEC_ULINT nTestULInt18446744073709551615; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 0ULL); + + nTestULInt0=0ULL; + nTestULInt1=1ULL; + nTestULInt2147483648=2147483648ULL; + nTestULInt18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 1ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 2147483648ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 18446744073709551615ULL); + +//checks + bTestBool.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(false, bTestBool); + bTestBool.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_ULINT_to_BITDTs) +{ + CIEC_ULINT nTestULInt0; + CIEC_ULINT nTestULInt1; + CIEC_ULINT nTestULInt2147483648; + CIEC_ULINT nTestULInt18446744073709551615; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; + CIEC_LWORD nTestLWord; + +//check initial values + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 0ULL); + + nTestULInt0=0ULL; + nTestULInt1=1ULL; + nTestULInt2147483648=2147483648ULL; + nTestULInt18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 1ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 2147483648ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 18446744073709551615ULL); + +//toByte + nTestByte.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toWord + nTestWord.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestWord, 65535U); + +//toDWord + nTestDWord.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestDWord, 2147483648UL); + nTestDWord.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestDWord, 4294967295UL); + + +//toLWord + nTestLWord.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestLWord, 2147483648ULL); + nTestLWord.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestLWord, 18446744073709551615ULL); + +} + +BOOST_AUTO_TEST_CASE(CASTS_ULINT_to_INTS) +{ + CIEC_ULINT nTestULInt0; + CIEC_ULINT nTestULInt1; + CIEC_ULINT nTestULInt2147483648; + CIEC_ULINT nTestULInt18446744073709551615; + + CIEC_USINT nTestUSInt; + CIEC_SINT nTestSInt; + CIEC_UINT nTestUInt; + CIEC_INT nTestInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; + CIEC_LINT nTestLInt; + + //check initial values + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 0ULL); + + nTestULInt0=0; + nTestULInt1=1; + nTestULInt2147483648=2147483648ULL; + nTestULInt18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 1ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 2147483648ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 18446744073709551615ULL); + + +//toUSINT + nTestUSInt.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + +//toSINT + nTestSInt.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUINT + nTestUInt.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + + +//toINT + nTestInt.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toDINT + nTestDInt.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestDInt, 1); + nTestDInt.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestDInt, -2147483648LL); + nTestDInt.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestDInt, -1); + + //toUDINT + nTestUDInt.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestUDInt, 0U); + nTestUDInt.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestUDInt, 1U); + nTestUDInt.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestUDInt, 2147483648U); + nTestUDInt.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestUDInt, 4294967295UL); + + +//toLINT + nTestLInt.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(nTestLInt, 0); + nTestLInt.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(nTestLInt, 1); + nTestLInt.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(nTestLInt, 2147483648LL); + nTestLInt.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(nTestLInt, -1LL); + + +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_ULINT_to_REAL) +{ + CIEC_ULINT nTestULInt0; + CIEC_ULINT nTestULInt1; + CIEC_ULINT nTestULInt2147483648; + CIEC_ULINT nTestULInt18446744073709551615; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 0ULL); + + nTestULInt0=0ULL; + nTestULInt1=1ULL; + nTestULInt2147483648=2147483648ULL; + nTestULInt18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 1ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 2147483648ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 18446744073709551615ULL); + +//toREAL + nTestReal.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(2147483648.0f, nTestReal); + nTestReal.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(18446744073709551615.0f, nTestReal); + + + + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(2147483648.0, nTestLReal); + nTestLReal.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(18446744073709551615.0, nTestLReal); +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(CASTS_ULINT_to_TIME) +{ + CIEC_ULINT nTestULInt0; + CIEC_ULINT nTestULInt1; + CIEC_ULINT nTestULInt2147483648; + CIEC_ULINT nTestULInt18446744073709551615; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 0ULL); + + nTestULInt0=0ULL; + nTestULInt1=1ULL; + nTestULInt2147483648=2147483648ULL; + nTestULInt18446744073709551615=18446744073709551615ULL; + + BOOST_CHECK_EQUAL(nTestULInt0, 0ULL); + BOOST_CHECK_EQUAL(nTestULInt1, 1ULL); + BOOST_CHECK_EQUAL(nTestULInt2147483648, 2147483648ULL); + BOOST_CHECK_EQUAL(nTestULInt18446744073709551615, 18446744073709551615ULL); + +//toTime + nTestTime.setValue(nTestULInt0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestULInt1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestULInt2147483648); + BOOST_CHECK_EQUAL(2147483648L, nTestTime); + nTestTime.setValue(nTestULInt18446744073709551615); + BOOST_CHECK_EQUAL(-1, nTestTime); +} + +BOOST_AUTO_TEST_CASE(ULINT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_ULINT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() +#endif //FORTE_USE_64BIT_DATATYPES diff --git a/tests/core/datatypes/CIEC_ULINT_test.cpp b/tests/core/datatypes/CIEC_ULINT_test.cpp new file mode 100644 index 000000000..74bf2212f --- /dev/null +++ b/tests/core/datatypes/CIEC_ULINT_test.cpp @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_ulint.h" + +BOOST_AUTO_TEST_SUITE(CIEC_ULINT_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_ULINT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_ULINT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteUInt64()), sizeof(TForteUInt64)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_ULINT nTest1; + CIEC_ULINT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0ULL); + + nTest1 = 0ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0ULL); + BOOST_CHECK_EQUAL(nTest2, 0ULL); + + nTest1 = 13546842ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 13546842ULL); + BOOST_CHECK_EQUAL(nTest2, 13546842ULL); + + nTest1 = 18446744073709551615ULL; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest2, 18446744073709551615ULL); + + //check that assignment operator does not intertwine objects + nTest2 = 3652584218745ULL; + BOOST_CHECK_EQUAL(nTest1, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest2, 3652584218745ULL); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_ULINT nTest; + + char cBuffer[21]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 0ULL); + + nTest = 5874125369851ULL; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 5874125369851ULL); + + nTest = 18446744073709551615ULL; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt64(), 18446744073709551615ULL); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + BOOST_CHECK_EQUAL(nTest.fromString("62584325147"), 11); + BOOST_CHECK_EQUAL(nTest, 62584325147ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "62584325147"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#111010010010010100010000010000011011"), 38); + BOOST_CHECK_EQUAL(nTest, 62584325147ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "62584325147"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#722224202033"), 14); + BOOST_CHECK_EQUAL(nTest, 62584325147ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "62584325147"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#E9251041B"), 12); + BOOST_CHECK_EQUAL(nTest, 62584325147ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 11); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "62584325147"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + + BOOST_CHECK_EQUAL(nTest.fromString("18446744073709551615"), 20); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1111111111111111111111111111111111111111111111111111111111111111"), 66); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#1777777777777777777777"), 24); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFFFFFFFFFFFFFF"), 19); + BOOST_CHECK_EQUAL(nTest, 18446744073709551615ULL); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 21), 20); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "18446744073709551615"), 0); + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("184467440737095516159"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#11111111111111111111111111111111111111111111111111111111111111110"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#17777777777777777777770"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#92233720368547758076"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFFFFFFFFFFFFFF0"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_USINT_CASTS_test.cpp b/tests/core/datatypes/CIEC_USINT_CASTS_test.cpp new file mode 100644 index 000000000..4081ff6ee --- /dev/null +++ b/tests/core/datatypes/CIEC_USINT_CASTS_test.cpp @@ -0,0 +1,396 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_USINT_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_USINT_to_BOOL) +{ + CIEC_USINT nTestUSInt0; + CIEC_USINT nTestUSInt1; + CIEC_USINT nTestUSInt45; + CIEC_USINT nTestUSInt255; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestUSInt0, 0); + BOOST_CHECK_EQUAL(nTestUSInt1, 0); + BOOST_CHECK_EQUAL(nTestUSInt45, 0); + BOOST_CHECK_EQUAL(nTestUSInt255, 0); + + nTestUSInt0=0; + nTestUSInt1=1; + nTestUSInt45=45; + nTestUSInt255=255; + + BOOST_CHECK_EQUAL(nTestUSInt0, 0); + BOOST_CHECK_EQUAL(nTestUSInt1, 1); + BOOST_CHECK_EQUAL(nTestUSInt45, 45); + BOOST_CHECK_EQUAL(nTestUSInt255, 255); + +//checks + bTestBool.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(false, bTestBool); + bTestBool.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(true, bTestBool); + bTestBool.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(true, bTestBool); + +} + +BOOST_AUTO_TEST_CASE(CASTS_USINT_to_BITDTs) +{ + CIEC_USINT nTestUSInt0; + CIEC_USINT nTestUSInt1; + CIEC_USINT nTestUSInt45; + CIEC_USINT nTestUSInt255; + + CIEC_BYTE nTestByte; + CIEC_WORD nTestWord; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 0U); + BOOST_CHECK_EQUAL(nTestUSInt45, 0U); + BOOST_CHECK_EQUAL(nTestUSInt255, 0U); + + nTestUSInt0=0U; + nTestUSInt1=1U; + nTestUSInt45=45U; + nTestUSInt255=255U; + + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 1U); + BOOST_CHECK_EQUAL(nTestUSInt45, 45U); + BOOST_CHECK_EQUAL(nTestUSInt255, 255U); + +//toByte + nTestByte.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestByte, 45U); + nTestByte.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toWord + nTestWord.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestWord, 0U); + nTestWord.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestWord, 1U); + nTestWord.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestWord, 45U); + nTestWord.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestWord, 255U); + +//toDWord + nTestDWord.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestDWord, 45UL); + nTestDWord.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestDWord, 255UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestLWord, 45ULL); + nTestLWord.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestLWord, 255ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_USINT_to_INTS) +{ + CIEC_USINT nTestUSInt0; + CIEC_USINT nTestUSInt1; + CIEC_USINT nTestUSInt45; + CIEC_USINT nTestUSInt255; + + CIEC_SINT nTestSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 0U); + BOOST_CHECK_EQUAL(nTestUSInt45, 0U); + BOOST_CHECK_EQUAL(nTestUSInt255, 0U); + + nTestUSInt0=0U; + nTestUSInt1=1U; + nTestUSInt45=45U; + nTestUSInt255=255U; + + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 1U); + BOOST_CHECK_EQUAL(nTestUSInt45, 45U); + BOOST_CHECK_EQUAL(nTestUSInt255, 255U); + +//toSINT + nTestSInt.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestSInt, 45); + nTestSInt.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestSInt, -1); + + +//toINT + nTestInt.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestInt, 45); + nTestInt.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestInt, 255); + +//toUINT + nTestUInt.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestUInt, 45U); + nTestUInt.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestUInt, 255U); + +//toDINT + nTestDInt.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestDInt, 1); + nTestDInt.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestDInt, 45); + nTestDInt.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestDInt, 255); + +//toUDINT + nTestUDInt.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestUDInt, 45UL); + nTestUDInt.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestUDInt, 255UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestLInt, 45LL); + nTestLInt.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestLInt, 255LL); + +//toULINT + nTestULInt.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(nTestULInt, 45ULL); + nTestULInt.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(nTestULInt, 255ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_USINT_to_REAL) +{ + CIEC_USINT nTestUSInt0; + CIEC_USINT nTestUSInt1; + CIEC_USINT nTestUSInt45; + CIEC_USINT nTestUSInt255; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 0U); + BOOST_CHECK_EQUAL(nTestUSInt45, 0U); + BOOST_CHECK_EQUAL(nTestUSInt255, 0U); + + nTestUSInt0=0U; + nTestUSInt1=1U; + nTestUSInt45=45U; + nTestUSInt255=255U; + + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 1U); + BOOST_CHECK_EQUAL(nTestUSInt45, 45U); + BOOST_CHECK_EQUAL(nTestUSInt255, 255U); + +//toREAL + nTestReal.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(45.0f, nTestReal); + nTestReal.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(255.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(45.0, nTestLReal); + nTestLReal.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(255.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_CASE(CASTS_USINT_to_TIME) +{ + CIEC_USINT nTestUSInt0; + CIEC_USINT nTestUSInt1; + CIEC_USINT nTestUSInt45; + CIEC_USINT nTestUSInt255; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 0U); + BOOST_CHECK_EQUAL(nTestUSInt45, 0U); + BOOST_CHECK_EQUAL(nTestUSInt255, 0U); + + nTestUSInt0=0U; + nTestUSInt1=1U; + nTestUSInt45=45U; + nTestUSInt255=255U; + + BOOST_CHECK_EQUAL(nTestUSInt0, 0U); + BOOST_CHECK_EQUAL(nTestUSInt1, 1U); + BOOST_CHECK_EQUAL(nTestUSInt45, 45U); + BOOST_CHECK_EQUAL(nTestUSInt255, 255U); + +//toTime + nTestTime.setValue(nTestUSInt0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestUSInt1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestUSInt45); + BOOST_CHECK_EQUAL(45, nTestTime); + nTestTime.setValue(nTestUSInt255); + BOOST_CHECK_EQUAL(255, nTestTime); +} + +BOOST_AUTO_TEST_CASE(USINT_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_USINT, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_USINT_test.cpp b/tests/core/datatypes/CIEC_USINT_test.cpp new file mode 100644 index 000000000..ffbea93dd --- /dev/null +++ b/tests/core/datatypes/CIEC_USINT_test.cpp @@ -0,0 +1,202 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_usint.h" + +BOOST_AUTO_TEST_SUITE(CIEC_USINT_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_USINT nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_USINT); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteUInt8()), sizeof(TForteUInt8)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_USINT nTest1; + CIEC_USINT nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0U); + + nTest1 = 0U; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0U); + BOOST_CHECK_EQUAL(nTest2, 0U); + + nTest1 = 12U; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 12U); + BOOST_CHECK_EQUAL(nTest2, 12U); + + nTest1 = 255U; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 255U); + BOOST_CHECK_EQUAL(nTest2, 255U); + + //check that assignment operator does not intertwine objects + nTest2 = 128U; + BOOST_CHECK_EQUAL(nTest1, 255U); + BOOST_CHECK_EQUAL(nTest2, 128U); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_USINT nTest; + + char cBuffer[4]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteUInt8(), 0U); + + nTest = 64U; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt8(), 64U); + + nTest = 255U; + BOOST_CHECK_EQUAL(nTest.operator TForteUInt8(), 255U); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 0), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("79"), 2); + BOOST_CHECK_EQUAL(nTest, 79U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1001111"), 9); + BOOST_CHECK_EQUAL(nTest, 79U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#117"), 5); + BOOST_CHECK_EQUAL(nTest, 79U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#4F"), 5); + BOOST_CHECK_EQUAL(nTest, 79U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("255"), 3); + BOOST_CHECK_EQUAL(nTest, 255U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#11111111"), 10); + BOOST_CHECK_EQUAL(nTest, 255U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#377"), 5); + BOOST_CHECK_EQUAL(nTest, 255U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FF"), 5); + BOOST_CHECK_EQUAL(nTest, 255U); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 4), 3); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "255"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("300"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#100101100"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#454"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#300"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#12C"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_WORD_CASTS_test.cpp b/tests/core/datatypes/CIEC_WORD_CASTS_test.cpp new file mode 100644 index 000000000..b95d0e9f6 --- /dev/null +++ b/tests/core/datatypes/CIEC_WORD_CASTS_test.cpp @@ -0,0 +1,398 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2012 ACIN, nxtControl + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//STRING-Datatypes +#include "../../../src/core/datatypes/forte_string.h" +#include "../../../src/core/datatypes/forte_wstring.h" +//TIME +#include "../../../src/core/datatypes/forte_time.h" + + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +using namespace boost::unit_test; + +BOOST_AUTO_TEST_SUITE(CIEC_WORD_casts_function_test) + + +BOOST_AUTO_TEST_CASE(CASTS_WORD_to_BOOL) +{ + CIEC_WORD nTestWord0; + CIEC_WORD nTestWord1; + CIEC_WORD nTestWord256; + CIEC_WORD nTestWord65535; + + CIEC_BOOL bTestBool; + +//check initial values + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 0U); + BOOST_CHECK_EQUAL(nTestWord256, 0U); + BOOST_CHECK_EQUAL(nTestWord65535, 0U); + + nTestWord0=0x00; + nTestWord1=0x01; + nTestWord256=0x0100; + nTestWord65535=0xffff; + + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 1U); + BOOST_CHECK_EQUAL(nTestWord256, 0x0100); + BOOST_CHECK_EQUAL(nTestWord65535, 0xffff); + +//checks + bTestBool.setValue(nTestWord0); + BOOST_CHECK_EQUAL(bTestBool, false); + bTestBool.setValue(nTestWord1); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestWord256); + BOOST_CHECK_EQUAL(bTestBool, true); + bTestBool.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(bTestBool, true); + +} + +BOOST_AUTO_TEST_CASE(CASTS_WORD_to_BITDTs) +{ + CIEC_WORD nTestWord0; + CIEC_WORD nTestWord1; + CIEC_WORD nTestWord256; + CIEC_WORD nTestWord65535; + + CIEC_BYTE nTestByte; + CIEC_DWORD nTestDWord; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_DWORD nTestLWord; +#endif //FORTE_USE_64BIT_DATATYPES + +//check initial values + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 0U); + BOOST_CHECK_EQUAL(nTestWord256, 0U); + BOOST_CHECK_EQUAL(nTestWord65535, 0U); + + nTestWord0=0U; + nTestWord1=1U; + nTestWord256=256U; + nTestWord65535=65535U; + + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 1U); + BOOST_CHECK_EQUAL(nTestWord256, 256U); + BOOST_CHECK_EQUAL(nTestWord65535, 65535U); + +//toByte + nTestByte.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestByte, 1U); + nTestByte.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestByte, 0U); + nTestByte.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestByte, 255U); + +//toDWord + nTestDWord.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestDWord, 0UL); + nTestDWord.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestDWord, 1UL); + nTestDWord.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestDWord, 256UL); + nTestDWord.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestDWord, 65535UL); + + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLWord + nTestLWord.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestLWord, 0ULL); + nTestLWord.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestLWord, 1ULL); + nTestLWord.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestLWord, 256ULL); + nTestLWord.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestLWord, 65535ULL); + +#endif +} + +BOOST_AUTO_TEST_CASE(CASTS_WORD_to_INTS) +{ + CIEC_WORD nTestWord0; + CIEC_WORD nTestWord1; + CIEC_WORD nTestWord256; + CIEC_WORD nTestWord65535; + + CIEC_SINT nTestSInt; + CIEC_USINT nTestUSInt; + CIEC_INT nTestInt; + CIEC_UINT nTestUInt; + CIEC_DINT nTestDInt; + CIEC_UDINT nTestUDInt; +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LINT nTestLInt; + CIEC_ULINT nTestULInt; +#endif //FORTE_USE_64BIT_DATATYPES + + //check initial values + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 0U); + BOOST_CHECK_EQUAL(nTestWord256, 0U); + BOOST_CHECK_EQUAL(nTestWord65535, 0U); + + nTestWord0=0U; + nTestWord1=1U; + nTestWord256=256U; + nTestWord65535=65535U; + + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 1U); + BOOST_CHECK_EQUAL(nTestWord256, 256U); + BOOST_CHECK_EQUAL(nTestWord65535, 65535U); + +//toSINT + nTestSInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestSInt, 1); + nTestSInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestSInt, 0); + nTestSInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestSInt, -1); + +//toUSINT + nTestUSInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestUSInt, 1U); + nTestUSInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestUSInt, 0U); + nTestUSInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestUSInt, 255U); + + +//toINT + nTestInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestInt, 0); + nTestInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestInt, 1); + nTestInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestInt, 256); + nTestInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestInt, -1); + +//toUINT + nTestUInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestUInt, 0U); + nTestUInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestUInt, 1U); + nTestUInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestUInt, 256U); + nTestUInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestUInt, 65535U); + +//toDINT + nTestDInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestDInt, 0); + nTestDInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestDInt, 1); + nTestDInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestDInt, 256); + nTestDInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestDInt, 65535); + +//toUDINT + nTestUDInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestUDInt, 0UL); + nTestUDInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestUDInt, 1UL); + nTestUDInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestUDInt, 256UL); + nTestUDInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestUDInt, 65535UL); + +#ifdef FORTE_USE_64BIT_DATATYPES +//toLINT + nTestLInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestLInt, 0LL); + nTestLInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestLInt, 1LL); + nTestLInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestLInt, 256LL); + nTestLInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestLInt, 65535LL); + +//toULINT + nTestULInt.setValue(nTestWord0); + BOOST_CHECK_EQUAL(nTestULInt, 0ULL); + nTestULInt.setValue(nTestWord1); + BOOST_CHECK_EQUAL(nTestULInt, 1ULL); + nTestULInt.setValue(nTestWord256); + BOOST_CHECK_EQUAL(nTestULInt, 256ULL); + nTestULInt.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(nTestULInt, 65535ULL); +#endif +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(CASTS_WORD_to_REAL) +{ + CIEC_WORD nTestWord0; + CIEC_WORD nTestWord1; + CIEC_WORD nTestWord256; + CIEC_WORD nTestWord65535; + + CIEC_REAL nTestReal; + +//check initial values + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 0U); + BOOST_CHECK_EQUAL(nTestWord256, 0U); + BOOST_CHECK_EQUAL(nTestWord65535, 0U); + + nTestWord0=0U; + nTestWord1=1U; + nTestWord256=256U; + nTestWord65535=65535U; + + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 1U); + BOOST_CHECK_EQUAL(nTestWord256, 256U); + BOOST_CHECK_EQUAL(nTestWord65535, 65535U); + +//toREAL + nTestReal.setValue(nTestWord0); + BOOST_CHECK_EQUAL(0.0f, nTestReal); + nTestReal.setValue(nTestWord1); + BOOST_CHECK_EQUAL(1.0f, nTestReal); + nTestReal.setValue(nTestWord256); + BOOST_CHECK_EQUAL(256.0f, nTestReal); + nTestReal.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(65535.0f, nTestReal); + + +#ifdef FORTE_USE_64BIT_DATATYPES + CIEC_LREAL nTestLReal; + +//toLREAL + nTestLReal.setValue(nTestWord0); + BOOST_CHECK_EQUAL(0.0, nTestLReal); + nTestLReal.setValue(nTestWord1); + BOOST_CHECK_EQUAL(1.0, nTestLReal); + nTestLReal.setValue(nTestWord256); + BOOST_CHECK_EQUAL(256.0, nTestLReal); + nTestLReal.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(65535.0, nTestLReal); +#endif //FORTE_USE_64BIT_DATATYPES + +} +#endif //FORTE_USE_REAL_DATATYPE + + +BOOST_AUTO_TEST_CASE(CASTS_WORD_to_TIME) +{ + CIEC_WORD nTestWord0; + CIEC_WORD nTestWord1; + CIEC_WORD nTestWord256; + CIEC_WORD nTestWord65535; + + CIEC_TIME nTestTime; + +//check initial values + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 0U); + BOOST_CHECK_EQUAL(nTestWord256, 0U); + BOOST_CHECK_EQUAL(nTestWord65535, 0U); + + nTestWord0=0U; + nTestWord1=1U; + nTestWord256=256U; + nTestWord65535=65535U; + + BOOST_CHECK_EQUAL(nTestWord0, 0U); + BOOST_CHECK_EQUAL(nTestWord1, 1U); + BOOST_CHECK_EQUAL(nTestWord256, 256U); + BOOST_CHECK_EQUAL(nTestWord65535, 65535U); + +//toTime + nTestTime.setValue(nTestWord0); + BOOST_CHECK_EQUAL(0, nTestTime); + nTestTime.setValue(nTestWord1); + BOOST_CHECK_EQUAL(1, nTestTime); + nTestTime.setValue(nTestWord256); + BOOST_CHECK_EQUAL(256, nTestTime); + nTestTime.setValue(nTestWord65535); + BOOST_CHECK_EQUAL(65535, nTestTime); + +} + +BOOST_AUTO_TEST_CASE(WORD_Castable_test) +{ + bool bUp, bDown; + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_BOOL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_SINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_INT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_DINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_LINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_USINT, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_UINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_UDINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_ULINT, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_BYTE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_WORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_DWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_LWORD, bUp, bDown)); BOOST_CHECK(bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_DATE, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_TIME_OF_DAY, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_DATE_AND_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_TIME, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_REAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + BOOST_CHECK(CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_LREAL, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(bDown); + + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_STRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); + BOOST_CHECK(!CIEC_ANY::isCastable(CIEC_ANY::e_WORD, CIEC_ANY::e_WSTRING, bUp, bDown)); BOOST_CHECK(! bUp); BOOST_CHECK(! bDown); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_WORD_test.cpp b/tests/core/datatypes/CIEC_WORD_test.cpp new file mode 100644 index 000000000..ce2adb28a --- /dev/null +++ b/tests/core/datatypes/CIEC_WORD_test.cpp @@ -0,0 +1,205 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_word.h" + +BOOST_AUTO_TEST_SUITE(CIEC_WORD_function_test) + +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_WORD nTest; + //check type information + BOOST_CHECK_EQUAL(nTest.getDataTypeID(), CIEC_ANY::e_WORD); + //check operator bool data type size + BOOST_CHECK_EQUAL(sizeof(nTest.operator TForteWord()), sizeof(TForteWord)); + +} + +BOOST_AUTO_TEST_CASE(Assignment_test) +{ + CIEC_WORD nTest1; + CIEC_WORD nTest2; + + //initial value must be 0 + BOOST_CHECK_EQUAL(nTest1, 0); + + nTest1 = 0; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 0); + BOOST_CHECK_EQUAL(nTest2, 0); + + nTest1 = 523; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 523); + BOOST_CHECK_EQUAL(nTest2, 523); + + nTest1 = 65535; + nTest2 = nTest1; + BOOST_CHECK_EQUAL(nTest1, 65535); + BOOST_CHECK_EQUAL(nTest2, 65535); + + //check that assignment operator does not intertwine objects + nTest2 = 40396; + BOOST_CHECK_EQUAL(nTest1, 65535); + BOOST_CHECK_EQUAL(nTest2, 40396); + +} + +BOOST_AUTO_TEST_CASE(Conversion_test) +{ + CIEC_WORD nTest; + + char cBuffer[6]; + char cBufferFail[2]; + + //check cast operator + nTest = 0; + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.operator TForteWord(), 0); + + nTest = 8756; + BOOST_CHECK_EQUAL(nTest.operator TForteWord(), 8756); + + nTest = 65535; + BOOST_CHECK_EQUAL(nTest.operator TForteWord(), 65535); + + //check toString and fromString + BOOST_CHECK_EQUAL(nTest.fromString("0"), 1); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("2#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("8#0"), 3); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + + BOOST_CHECK_EQUAL(nTest.fromString("16#0"), 4); + BOOST_CHECK_EQUAL(nTest, 0); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 1); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "0"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 1), -1); + + strcpy(cBuffer, ""); + + BOOST_CHECK_EQUAL(nTest.fromString("79"), 2); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1001111"), 9); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#117"), 5); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#4F"), 5); + BOOST_CHECK_EQUAL(nTest, 79); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 2); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "79"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("65535"), 5); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("2#1111111111111111"), 18); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("8#177777"), 8); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + BOOST_CHECK_EQUAL(nTest.fromString("16#FFFF"), 7); + BOOST_CHECK_EQUAL(nTest, 65535); + BOOST_CHECK_EQUAL(nTest.toString(cBuffer, 6), 5); + BOOST_CHECK_EQUAL(strcmp(cBuffer, "65535"), 0); + + BOOST_CHECK_EQUAL(nTest.toString(cBufferFail, 2), -1); + + strcpy(cBuffer, ""); + nTest = 0; + + //testing values outside of allowed range + BOOST_CHECK_EQUAL(nTest.fromString("70000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("2#10001000101110000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("8#210560"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("10#70000"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("16#11170"), -1); + BOOST_CHECK_EQUAL(nTest.fromString("-130"), -1); + + //check invalid fromString string + BOOST_CHECK_EQUAL(nTest.fromString("NOT A VALID STRING"), -1); +} +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CIEC_WSTRING_test.cpp b/tests/core/datatypes/CIEC_WSTRING_test.cpp new file mode 100644 index 000000000..41f6eee90 --- /dev/null +++ b/tests/core/datatypes/CIEC_WSTRING_test.cpp @@ -0,0 +1,486 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, nxtControl, Profactor GmbH, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny, Alois Zoitl, Stanislav Meduna, Matthias Plasch - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/forte_wstring.h" + +BOOST_AUTO_TEST_SUITE(CIEC_WSTRING_function_test) +BOOST_AUTO_TEST_CASE(Type_test) +{ + CIEC_WSTRING sTest; + //check type information + BOOST_CHECK_EQUAL(sTest.getDataTypeID(), CIEC_ANY::e_WSTRING); + //check operator const char* data type size + BOOST_CHECK_EQUAL(sizeof(sTest.getValue()), sizeof(char*)); + +} + +BOOST_AUTO_TEST_CASE(String_manilulation_interface) +{ + CIEC_WSTRING sTest; + char cWStringTest[] = "This is a test string!"; //length 22 without trailing \0 + BOOST_CHECK_EQUAL(sTest.length(), 0); + sTest = cWStringTest; + BOOST_CHECK_EQUAL(sTest.length(), 22); + BOOST_CHECK_EQUAL(strcmp(sTest.getValue(), cWStringTest), 0); + + CIEC_WSTRING* psTest = new CIEC_WSTRING(cWStringTest); + BOOST_CHECK_EQUAL(psTest->length(), 22); + BOOST_CHECK_EQUAL(strcmp(psTest->getValue(), cWStringTest), 0); + delete psTest; + +} + +BOOST_AUTO_TEST_CASE(String_assignment) +{ + CIEC_WSTRING sTest1; + CIEC_WSTRING sTest2; + char cWStringTest1[] = "This is another test string!"; + char cWStringTest2[] = "Check string!"; + sTest1 = cWStringTest1; + sTest2 = sTest1; + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), sTest2.getValue()), 0); + BOOST_CHECK_EQUAL(sTest1.length(), 28); + BOOST_CHECK_EQUAL(sTest2.length(), 28); + sTest2 = cWStringTest2; + BOOST_CHECK(0 != strcmp(sTest1.getValue(), sTest2.getValue())); + BOOST_CHECK_EQUAL(sTest1 != sTest2, true); + BOOST_CHECK_EQUAL(strcmp(cWStringTest2, sTest2.getValue()), 0); +} + +BOOST_AUTO_TEST_CASE(String_compare) +{ + CIEC_WSTRING sTest1; + CIEC_WSTRING sTest2; + CIEC_WSTRING sTest3; + + const char cWStringTest1[] = "Check string!"; + char cWStringTest2[] = "Check string!"; + char cWStringTest3[] = "checkstring!"; + + sTest1 = cWStringTest1; + sTest2 = cWStringTest2; + sTest3 = cWStringTest3; + BOOST_CHECK(sTest1 == sTest2); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cWStringTest1), 0); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cWStringTest2), 0); + + BOOST_CHECK(!(sTest1 == sTest3)); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cWStringTest1), 0); + BOOST_CHECK_EQUAL(strcmp(sTest3.getValue(), cWStringTest3), 0); + + BOOST_CHECK(sTest2 != sTest3); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cWStringTest2), 0); + BOOST_CHECK_EQUAL(strcmp(sTest3.getValue(), cWStringTest3), 0); + + BOOST_CHECK(!(sTest2 != sTest1)); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cWStringTest2), 0); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cWStringTest1), 0); + + + BOOST_CHECK(sTest1 == cWStringTest2); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cWStringTest1), 0); + + BOOST_CHECK(cWStringTest2 == sTest1); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cWStringTest1), 0); + + BOOST_CHECK(!(sTest1 == cWStringTest3)); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cWStringTest1), 0); + + BOOST_CHECK(!(cWStringTest3 == sTest1)); + BOOST_CHECK_EQUAL(strcmp(sTest1.getValue(), cWStringTest1), 0); + + BOOST_CHECK(sTest2 != cWStringTest3); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cWStringTest2), 0); + + BOOST_CHECK(cWStringTest3 != sTest2); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cWStringTest2), 0); + + BOOST_CHECK(!(sTest2 != cWStringTest1)); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cWStringTest2), 0); + + BOOST_CHECK(!(cWStringTest1 != sTest2)); + BOOST_CHECK_EQUAL(strcmp(sTest2.getValue(), cWStringTest2), 0); +} + +BOOST_AUTO_TEST_CASE(Memory_Allocation) +{ + CIEC_WSTRING sTest; + sTest.reserve(10); + BOOST_CHECK_EQUAL(sTest.length(), 0); + sTest = "Test"; + BOOST_CHECK_EQUAL(sTest.length(), 4); + sTest = "Test with more than ten characters"; + BOOST_CHECK_EQUAL(sTest.length(), 34); +} + +BOOST_AUTO_TEST_CASE(WString_fromUTF16) +{ + const TForteByte cBOMBE[] = { 0xFE, 0xFF }; + const TForteByte cBOMLE[] = { 0xFF, 0xFE }; + + const TForteByte cWStringTest1Default[] = { 0x00, 0x7a }; + const TForteByte cWStringTest1BE[] = { 0xFE, 0xFF, 0x00, 0x7a }; + const TForteByte cWStringTest1LE[] = { 0xFF, 0xFE, 0x7a, 0x00 }; + + // Japanese "nihongo", meaning "the Japanese language" + const TForteByte cWStringTest2[] = { 0xFE, 0xFF, 0x65, 0xe5, 0x67, 0x2c, 0x8a, 0x9e }; + const TForteByte cWStringTest2Result[] = { 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, 0 }; + + // a Chinese character meaning 'stump of tree' + const TForteByte cWStringTest3[] = { 0xFE, 0xFF, 0xd8, 0x4c, 0xdf, 0xb4 }; + const TForteByte cWStringTest3Result[] = { 0xF0, 0xA3, 0x8E, 0xB4, 0 }; + + bool nRes; + CIEC_WSTRING sTest; + + nRes = sTest.fromUTF16(cBOMBE, sizeof(cBOMBE)); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 0); + + nRes = sTest.fromUTF16(cBOMLE, sizeof(cBOMLE)); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 0); + + nRes = sTest.fromUTF16(cWStringTest1Default, sizeof(cWStringTest1Default)); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 1); + BOOST_CHECK(!strcmp(sTest.getValue(), "z")); + nRes = sTest.fromUTF16(cWStringTest1BE, sizeof(cWStringTest1BE)); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 1); + BOOST_CHECK(!strcmp(sTest.getValue(), "z")); + nRes = sTest.fromUTF16(cWStringTest1LE, sizeof(cWStringTest1LE)); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 1); + BOOST_CHECK(!strcmp(sTest.getValue(), "z")); + + nRes = sTest.fromUTF16(cWStringTest2, sizeof(cWStringTest2)); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 9); + BOOST_CHECK(!strcmp(sTest.getValue(), (const char *) cWStringTest2Result)); + + nRes = sTest.fromUTF16(cWStringTest3, sizeof(cWStringTest3)); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 4); + BOOST_CHECK(!strcmp(sTest.getValue(), (const char *) cWStringTest3Result)); + + nRes = sTest.fromUTF16(cWStringTest3, 0); + BOOST_CHECK(nRes); + BOOST_CHECK_EQUAL(sTest.length(), 0); + + nRes = sTest.fromUTF16(cWStringTest3, 3); + BOOST_CHECK(! nRes); +} + +BOOST_AUTO_TEST_CASE(WString_toUTF16) +{ + const TForteByte cWStringTest1Result[] = { 0x00, 0x7a }; + + // Japanese "nihongo", meaning "the Japanese language" + const TForteByte cWStringTest2[] = { 0xE6, 0x97, 0xA5, 0xE6, 0x9C, 0xAC, 0xE8, 0xAA, 0x9E, 0 }; + const TForteByte cWStringTest2Result[] = { 0x65, 0xe5, 0x67, 0x2c, 0x8a, 0x9e }; + + // a Chinese character meaning 'stump of tree' + const TForteByte cWStringTest3[] = { 0xF0, 0xA3, 0x8E, 0xB4, 0 }; + const TForteByte cWStringTest3Result[] = { 0xd8, 0x4c, 0xdf, 0xb4 }; + + TForteByte cBuffer[32]; + + int nRes; + CIEC_WSTRING sTest; + + nRes = sTest.toUTF16(cBuffer, sizeof(cWStringTest1Result)); + BOOST_CHECK_EQUAL(nRes, 0); + + sTest = "z"; + nRes = sTest.toUTF16(cBuffer, sizeof(cWStringTest1Result)); + BOOST_CHECK_EQUAL(nRes, 2); + BOOST_CHECK(! memcmp(cBuffer, cWStringTest1Result, 2)); + + sTest = (const char *) cWStringTest2; + nRes = sTest.toUTF16(cBuffer, sizeof(cWStringTest2Result)); + BOOST_CHECK_EQUAL(nRes, 6); + BOOST_CHECK(! memcmp(cBuffer, cWStringTest2Result, 6)); + + sTest = (const char *) cWStringTest3; + nRes = sTest.toUTF16(cBuffer, sizeof(cWStringTest3Result)); + BOOST_CHECK_EQUAL(nRes, 4); + BOOST_CHECK(! memcmp(cBuffer, cWStringTest3Result, 4)); + + nRes = sTest.toUTF16(cBuffer, sizeof(cWStringTest3Result)-1); + BOOST_CHECK_EQUAL(nRes, -1); +} + +BOOST_AUTO_TEST_CASE(WString_fromUTF8) +{ + const TForteByte cASCII1[] = { 0 }; + const TForteByte cASCII2[] = { 'A', 0 }; + const TForteByte cASCII3[] = { 0x7f, 0 }; + const TForteByte cUpper1[] = { 'A', 0xc2, 0xa2, 'A', 0 }; + const TForteByte cUpper2[] = { 'A', 0xe2, 0x82, 0xac, 'B', 0 }; + const TForteByte cUpper2Capped[] = { 'A', 0xe2, 0x82, 0xac, 0 }; + const TForteByte cUpper3[] = { 0xf0, 0xa4, 0xad, 0xa2, 0 }; + const TForteByte cInvalid1[] = { 0x80, 0 }; + const TForteByte cInvalid2[] = { 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80, 0 }; + + int bRes; + CIEC_WSTRING sTest; + + bRes = sTest.fromUTF8((const char *) cASCII1, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cASCII1), bRes); + BOOST_CHECK_EQUAL(sTest.length(), 0); + + bRes = sTest.fromUTF8((const char *) cASCII2, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cASCII2), bRes); + BOOST_CHECK(! strcmp("A", sTest.getValue())); + + bRes = sTest.fromUTF8((const char *) cASCII3, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cASCII3), bRes); + BOOST_CHECK(! strcmp("\x7f", sTest.getValue())); + + bRes = sTest.fromUTF8((const char *) cUpper1, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cUpper1), bRes); + BOOST_CHECK(! strcmp((const char *) cUpper1, sTest.getValue())); + + bRes = sTest.fromUTF8((const char *) cUpper2, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *)cUpper2), bRes); + BOOST_CHECK(! strcmp((const char *) cUpper2, sTest.getValue())); + + bRes = sTest.fromUTF8((const char *) cUpper2, 4, false); + BOOST_CHECK_EQUAL(4, bRes); //as we capp to 4 we expact the number of taken bytes to be 4 + BOOST_CHECK(! strcmp((const char *) cUpper2Capped, sTest.getValue())); + + bRes = sTest.fromUTF8((const char *) cUpper3, -1, false); + BOOST_CHECK_EQUAL(strlen((const char *) cUpper3), bRes); + BOOST_CHECK(! strcmp("?", sTest.getValue())); + + bRes = sTest.fromUTF8((const char *) cInvalid1, -1, false); + BOOST_CHECK_EQUAL(-1, bRes); + + bRes = sTest.fromUTF8((const char *) cInvalid2, -1, false); + BOOST_CHECK_EQUAL(-1, bRes); +} + +BOOST_AUTO_TEST_CASE(WString_toUTF8) +{ + const TForteByte cASCII1[] = { 0 }; + const TForteByte cASCII2[] = { 'A', 0 }; + const TForteByte cASCII3[] = { 0x7f, 0 }; + const TForteByte cUpper1[] = { 'A', 0xc2, 0xa2, 'A', 0 }; + const TForteByte cUpper2[] = { 'A', 0xe2, 0x82, 0xac, 'B', 0 }; + const TForteByte cUpper3[] = { 'A', 0xe2, 0x82, 0xac, '$', 'B', 0 }; + const TForteByte cUpper3Escaped[] = { '"', 'A', 0xe2, 0x82, 0xac, '$', '$', 'B', '"', 0 }; + + int nRes; + CIEC_WSTRING sTest; + char sResult[32]; + + sTest = ""; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 0); + BOOST_CHECK(! memcmp(sResult, cASCII1, sizeof(cASCII1))); + + sTest = "A"; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 1); + BOOST_CHECK(! memcmp(sResult, cASCII2, sizeof(cASCII2))); + + sTest = "\x7f"; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 1); + BOOST_CHECK(! memcmp(sResult, cASCII3, sizeof(cASCII3))); + nRes = sTest.toUTF8((char *) sResult, 1, false); + BOOST_CHECK_EQUAL(nRes, -1); + nRes = sTest.toUTF8((char *) sResult, 2, false); + BOOST_CHECK_EQUAL(nRes, 1); + + sTest = (const char *) cUpper1; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 4); + BOOST_CHECK(! memcmp(sResult, cUpper1, sizeof(cUpper1))); + nRes = sTest.toUTF8(sResult, 4, false); + BOOST_CHECK_EQUAL(nRes, -1); + nRes = sTest.toUTF8(sResult, 5, false); + BOOST_CHECK_EQUAL(nRes, 4); + + sTest = (const char *) cUpper2; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), false); + BOOST_CHECK_EQUAL(nRes, 5); + BOOST_CHECK(! memcmp(sResult, cUpper2, sizeof(cUpper2))); + + sTest = (const char *) cUpper3; + sResult[0] = '\0'; + nRes = sTest.toUTF8(sResult, sizeof(sResult), true); + BOOST_CHECK_EQUAL(nRes, 9); + BOOST_CHECK(! memcmp(sResult, cUpper3Escaped, sizeof(cUpper3Escaped))); +} + +const char cWStringTestLiteral1[] = "Test String"; +const char cWStringTestResult1[] = "Test String"; +const char cWStringTestToStringResult1[] = "\"Test String\""; +const char cWStringTestLiteral2[] = "\"This is another test string!\""; +const char cWStringTestResult2[] = "This is another test string!"; +const char cWStringTestDollarLiteral[] ="\"$$\""; +const char cWStringTestDollarResult[] = "$"; +const char cWStringTestDollarToStringResult[] = "\"$$\""; +const char cWStringTestLineFeedLiteral[] = "\"$L$l\""; +const char cWStringTestLineFeedResult[] = {0x10, 0x10, '\0'}; +const char cWStringTestLineFeedToStringResult[] = "\"$l$l\""; +const char cWStringTestNewLineLiteral[] = "\"$N$n\""; +const char cWStringTestNewLineResult[] = "\n\n"; +const char cWStringTestNewLineToStringResult[] = "\"$n$n\""; +const char cWStringTestFormFeedLiteral[] = "\"$P$p\""; +const char cWStringTestFormFeedResult[] = "\f\f"; +const char cWStringTestFormFeedToStringResult[] = "\"$p$p\""; +const char cWStringTestCarriageReturnLiteral[] = "\"$R$r\""; +const char cWStringTestCarriageReturnResult[] = "\r\r"; +const char cWStringTestCarriageReturnToStringResult[] = "\"$r$r\""; +const char cWStringTestTabLiteral[] = "\"$T$t\""; +const char cWStringTestTabResult[] = "\t\t"; +const char cWStringTestTabToStringResult[] = "\"$t$t\""; +const char cWStringTestSingleQuoteLiteral[] = "\"$\"\""; +const char cWStringTestSingleQuoteResult[] = "\""; +const char cWStringTestSingleQuoteToStringResult[] = "\"$\"\""; +const char cWStringTestDoubleQuoteLiteral[] = "\"$\"\""; +const char cWStringTestDoubleQuoteResult[] = "\""; +const char cWStringTestDoubleQuoteToStringResult[] = "\"$\"\""; +const char cWStringTestEscapedCharacterLiteral[] = "\"$0030\""; +const char cWStringTestEscapedCharacterResult[] = "0"; +const char cWStringTestEscapedCharacterToStringResult[] = "\"0\""; +const char cWStringTestEscapedWCharacterLiteral[] = "\"$01a0\""; +const char cWStringTestEscapedWCharacterResult[] = "\xc6\xa0"; +const char cWStringTestEscapedWCharacterToStringResult[] = "\"xc6\xa0\""; + + +BOOST_AUTO_TEST_CASE(WString_fromString) +{ + CIEC_WSTRING sTestee; + + BOOST_CHECK_EQUAL(strlen(cWStringTestLiteral1), sTestee.fromString(cWStringTestLiteral1)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestResult1)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestResult1)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestLiteral2), sTestee.fromString(cWStringTestLiteral2)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestResult2)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestResult2)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestDollarLiteral), sTestee.fromString(cWStringTestDollarLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestDollarResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestDollarResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestLineFeedLiteral), sTestee.fromString(cWStringTestLineFeedLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestLineFeedResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestLineFeedResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestDollarLiteral), sTestee.fromString(cWStringTestDollarLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestDollarResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestDollarResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestFormFeedLiteral), sTestee.fromString(cWStringTestFormFeedLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestFormFeedResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestFormFeedResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestCarriageReturnLiteral), sTestee.fromString(cWStringTestCarriageReturnLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestCarriageReturnResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestCarriageReturnResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestTabLiteral), sTestee.fromString(cWStringTestTabLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestTabResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestTabResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestSingleQuoteLiteral), sTestee.fromString(cWStringTestSingleQuoteLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestSingleQuoteResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestSingleQuoteResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestDoubleQuoteLiteral), sTestee.fromString(cWStringTestDoubleQuoteLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestDoubleQuoteResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestDoubleQuoteResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestEscapedCharacterLiteral), sTestee.fromString(cWStringTestEscapedCharacterLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestEscapedCharacterResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestEscapedCharacterResult)); + + BOOST_CHECK_EQUAL(strlen(cWStringTestEscapedWCharacterLiteral), sTestee.fromString(cWStringTestEscapedWCharacterLiteral)); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(cWStringTestEscapedWCharacterResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), cWStringTestEscapedWCharacterResult)); +} + +void wStringTypedFromString(const std::string &pa_sSrc, const char* pa_acResult){ + CIEC_WSTRING sTestee; + BOOST_CHECK_EQUAL(pa_sSrc.length(), sTestee.fromString(pa_sSrc.c_str())); + BOOST_CHECK_EQUAL(sTestee.length(), strlen(pa_acResult)); + BOOST_CHECK_EQUAL(0, strcmp(sTestee.getValue(), pa_acResult)); +} + +BOOST_AUTO_TEST_CASE(WString_fromString_typed) +{ + wStringTypedFromString(std::string("WSTRING#") + cWStringTestLiteral1, cWStringTestResult1); + wStringTypedFromString(std::string("WSTRING#") + cWStringTestLiteral2, cWStringTestResult2); + wStringTypedFromString(std::string("WSTRING#") + cWStringTestDollarLiteral, cWStringTestDollarResult); +} + +BOOST_AUTO_TEST_CASE(WString_toString) +{ + CIEC_WSTRING sTestee; + char acBuffer[200]; + + sTestee = cWStringTestResult1; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestToStringResult1)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestToStringResult1, acBuffer, strlen(cWStringTestToStringResult1))); + + sTestee = cWStringTestResult2; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestLiteral2)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestLiteral2, acBuffer, strlen(cWStringTestLiteral2))); + + sTestee = cWStringTestDollarResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestDollarToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestDollarToStringResult, acBuffer, strlen(cWStringTestDollarToStringResult))); + + sTestee = cWStringTestLineFeedResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestLineFeedToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestLineFeedToStringResult, acBuffer, strlen(cWStringTestLineFeedToStringResult))); + + sTestee = cWStringTestNewLineResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestNewLineToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestNewLineToStringResult, acBuffer, strlen(cWStringTestNewLineToStringResult))); + + sTestee = cWStringTestFormFeedResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestFormFeedToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestFormFeedToStringResult, acBuffer, strlen(cWStringTestFormFeedToStringResult))); + + sTestee = cWStringTestCarriageReturnResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestCarriageReturnToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestCarriageReturnToStringResult, acBuffer, strlen(cWStringTestCarriageReturnToStringResult))); + + sTestee = cWStringTestTabResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestTabToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestTabToStringResult, acBuffer, strlen(cWStringTestTabToStringResult))); + + sTestee = cWStringTestSingleQuoteResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestSingleQuoteToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestSingleQuoteToStringResult, acBuffer, strlen(cWStringTestSingleQuoteToStringResult))); + + sTestee = cWStringTestDoubleQuoteResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestDoubleQuoteToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestDoubleQuoteToStringResult, acBuffer, strlen(cWStringTestDoubleQuoteToStringResult))); + + sTestee = cWStringTestEscapedCharacterResult; + BOOST_CHECK_EQUAL(sTestee.toString(acBuffer, 200), strlen(cWStringTestEscapedCharacterToStringResult)); + BOOST_CHECK_EQUAL(0, strncmp(cWStringTestEscapedCharacterToStringResult, acBuffer, strlen(cWStringTestEscapedCharacterToStringResult))); +} + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/CMakeLists.txt b/tests/core/datatypes/CMakeLists.txt new file mode 100644 index 000000000..df54c3346 --- /dev/null +++ b/tests/core/datatypes/CMakeLists.txt @@ -0,0 +1,118 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2014 nxtControl, ACIN, fortiss GmbH, Profactor GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Stanislav Meduna, Ingo Hegny, Alois Zoitl, Monika Wenger, Matthias Plasch - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +#SET(SOURCE_GROUP ${SOURCE_GROUP}\\core) + + forte_test_add_inc_directories(${CMAKE_CURRENT_SOURCE_DIR}) + forte_test_add_link_directories(${CMAKE_BINARY_DIR}/src/core/datatypes) + + forte_test_add_sourcefile_cpp(CIEC_ANY_tests.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_any.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_any_elementary.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_any_date.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_any_string.cpp) + +#Unicode utilities + forte_test_add_sourcefile_cpp(CUnicodeUtilities_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/unicode_utils.cpp) + +#BOOLEAN Datatype + forte_test_add_sourcefile_cpp(CIEC_BOOL_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_BOOL_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_bool.cpp) + +#BIT-Datatypes + forte_test_add_sourcefile_cpp(CIEC_BYTE_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_BYTE_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_byte.cpp) + forte_test_add_sourcefile_cpp(CIEC_WORD_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_WORD_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_word.cpp) + forte_test_add_sourcefile_cpp(CIEC_DWORD_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_DWORD_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_dword.cpp) +IF (FORTE_USE_64BIT_DATATYPES) + forte_test_add_sourcefile_cpp(CIEC_LWORD_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_LWORD_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_lword.cpp) +ENDIF (FORTE_USE_64BIT_DATATYPES) + +#INT-Datatypes + forte_test_add_sourcefile_cpp(CIEC_SINT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_SINT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_sint.cpp) + forte_test_add_sourcefile_cpp(CIEC_USINT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_USINT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_usint.cpp) + forte_test_add_sourcefile_cpp(CIEC_INT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_INT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_int.cpp) + forte_test_add_sourcefile_cpp(CIEC_UINT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_UINT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_uint.cpp) + forte_test_add_sourcefile_cpp(CIEC_DINT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_DINT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_dint.cpp) + forte_test_add_sourcefile_cpp(CIEC_UDINT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_UDINT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_udint.cpp) +IF (FORTE_USE_64BIT_DATATYPES) + forte_test_add_sourcefile_cpp(CIEC_LINT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_LINT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_lint.cpp) + forte_test_add_sourcefile_cpp(CIEC_ULINT_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_ULINT_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_ulint.cpp) +ENDIF (FORTE_USE_64BIT_DATATYPES) + + + +IF (FORTE_USE_REAL_DATATYPE) + forte_test_add_sourcefile_cpp(CIEC_REAL_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_REAL_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_real.cpp) +ENDIF (FORTE_USE_REAL_DATATYPE) +IF (FORTE_USE_64BIT_DATATYPES) +IF (FORTE_USE_LREAL_DATATYPE) + forte_test_add_sourcefile_cpp(CIEC_LREAL_test.cpp) + forte_test_add_sourcefile_cpp(CIEC_LREAL_CASTS_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_lreal.cpp) +ENDIF (FORTE_USE_LREAL_DATATYPE) +ENDIF (FORTE_USE_64BIT_DATATYPES) + + forte_test_add_sourcefile_cpp(CIEC_STRING_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_string.cpp) + forte_test_add_sourcefile_cpp(CIEC_WSTRING_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_wstring.cpp) + +IF (FORTE_SUPPORT_ARRAYS) + forte_test_add_sourcefile_cpp(CIEC_ARRAY_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_array.cpp) +ENDIF(FORTE_SUPPORT_ARRAYS) + + forte_test_add_sourcefile_cpp(CIEC_TIME_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_time.cpp) + forte_test_add_sourcefile_cpp(CIEC_DATE_AND_TIME_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_date_and_time.cpp) + forte_test_add_sourcefile_cpp(CIEC_DATE_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_date.cpp) + forte_test_add_sourcefile_cpp(CIEC_TIME_OF_DAY_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_time_of_day.cpp) + + forte_test_add_sourcefile_cpp(CIEC_STRUCT_test.cpp) + forte_test_add_sourcefile_cpp(../../../src/core/datatypes/forte_struct.cpp) + +# convert functions for TO_(W)STRING conversions + forte_test_add_sourcefile_cpp(convert_to_STRING_test.cpp) + +IF(FORTE_USE_WSTRING_DATATYPE) + forte_test_add_sourcefile_cpp(convert_to_WSTRING_test.cpp) +ENDIF(FORTE_USE_WSTRING_DATATYPE) \ No newline at end of file diff --git a/tests/core/datatypes/CUnicodeUtilities_test.cpp b/tests/core/datatypes/CUnicodeUtilities_test.cpp new file mode 100644 index 000000000..6b13158dd --- /dev/null +++ b/tests/core/datatypes/CUnicodeUtilities_test.cpp @@ -0,0 +1,311 @@ +/******************************************************************************* + * Copyright (c) 2011, 2015 nxtControl, ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stanislav Meduna, Ingo Hegny, Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/datatypes/unicode_utils.h" + +BOOST_AUTO_TEST_SUITE(CUnicodeUtilities_function_test) + +BOOST_AUTO_TEST_CASE(CUnicodeUtilities_parseEncode8) +{ + int nRet; + TForteUInt32 nValue; + + const TForteByte cBOM[] = { 0xEF, 0xBB, 0xBF }; + const TForteByte cASCII1[] = { 0 }; + const TForteByte cASCII2[] = { 'A' }; + const TForteByte cASCII3[] = { 0x7f }; + const TForteByte cUpper1[] = { 0xc2, 0xa2 }; + const TForteByte cUpper2[] = { 0xe2, 0x82, 0xac }; + const TForteByte cUpper3[] = { 0xf0, 0xa4, 0xad, 0xa2 }; + const TForteByte cInvalid1[] = { 0x80 }; + const TForteByte cInvalid2[] = { 0xfe, 0x80, 0x80, 0x80, 0x80, 0x80 }; + TForteByte cBuffer[32]; + + nRet = CUnicodeUtilities::parseUTF8Codepoint(cBOM, nValue); + BOOST_CHECK_EQUAL(nRet, 3); + BOOST_CHECK_EQUAL(nValue, CUnicodeUtilities::scm_unBOMMarker); + + nRet = CUnicodeUtilities::parseUTF8Codepoint(cASCII1, nValue); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nValue, 0); + nRet = CUnicodeUtilities::parseUTF8Codepoint(cASCII2, nValue); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nValue, 'A'); + nRet = CUnicodeUtilities::parseUTF8Codepoint(cASCII3, nValue); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nValue, 0x7f); + + nRet = CUnicodeUtilities::parseUTF8Codepoint(cUpper1, nValue); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, 0xa2); + nRet = CUnicodeUtilities::parseUTF8Codepoint(cUpper2, nValue); + BOOST_CHECK_EQUAL(nRet, 3); + BOOST_CHECK_EQUAL(nValue, 0x20ac); + nRet = CUnicodeUtilities::parseUTF8Codepoint(cUpper3, nValue); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nValue, 0x24b62); + + nRet = CUnicodeUtilities::parseUTF8Codepoint(cInvalid1, nValue); + BOOST_CHECK_EQUAL(nRet, -1); + nRet = CUnicodeUtilities::parseUTF8Codepoint(cInvalid2, nValue); + BOOST_CHECK_EQUAL(nRet, -1); + + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 3, CUnicodeUtilities::scm_unBOMMarker); + BOOST_CHECK_EQUAL(nRet, 3); + BOOST_CHECK(! memcmp(cBOM, cBuffer, 3)); + + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 1, 0); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK(! memcmp(cASCII1, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 1, 'A'); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK(! memcmp(cASCII2, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 1, 0x7f); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK(! memcmp(cASCII3, cBuffer, 1)); + + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 2, 0xa2); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK(! memcmp(cUpper1, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 3, 0x20ac); + BOOST_CHECK_EQUAL(nRet, 3); + BOOST_CHECK(! memcmp(cUpper2, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 4, 0x24b62); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK(! memcmp(cUpper3, cBuffer, 1)); + + cBuffer[0] = '\0'; + nRet = CUnicodeUtilities::encodeUTF8Codepoint(0, 0, 0x7f); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(cBuffer[0], 0); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(0, 0, 0xa2); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(cBuffer[0], 0); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(0, 0, 0x20ac); + BOOST_CHECK_EQUAL(nRet, 3); + BOOST_CHECK_EQUAL(cBuffer[0], 0); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(0, 0, 0x24b62); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(cBuffer[0], 0); + + + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 0, 0x7f); + BOOST_CHECK_EQUAL(nRet, -1); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 1, 0xa2); + BOOST_CHECK_EQUAL(nRet, -1); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 2, 0x20ac); + BOOST_CHECK_EQUAL(nRet, -1); + nRet = CUnicodeUtilities::encodeUTF8Codepoint(cBuffer, 3, 0x24b62); + BOOST_CHECK_EQUAL(nRet, -1); +} + +BOOST_AUTO_TEST_CASE(CUnicodeUtilities_parseEncode16) +{ + int nRet; + TForteUInt32 nValue; + + const TForteByte cBOMBE[] = { 0xFE, 0xFF }; + const TForteByte cBOMLE[] = { 0xFF, 0xFE }; + const TForteByte cTest1BE[] = { 0x00, 0x7a }; + const TForteByte cTest1LE[] = { 0x7a, 0x00 }; + const TForteByte cTest2BE[] = { 0x6c, 0x34 }; + const TForteByte cTest2LE[] = { 0x34, 0x6c }; + const TForteByte cTest3BE[] = { 0xd8, 0x00, 0xdc, 0x00 }; + const TForteByte cTest3LE[] = { 0x00, 0xd8, 0x00, 0xdc }; + const TForteByte cTest4BE[] = { 0xd8, 0x34, 0xdd, 0x1e }; + const TForteByte cTest4LE[] = { 0x34, 0xd8, 0x1e, 0xdd }; + const TForteByte cTest5BE[] = { 0xdb, 0xff, 0xdf, 0xfd }; + const TForteByte cTest5LE[] = { 0xff, 0xdb, 0xfd, 0xdf }; + TForteByte cBuffer[32]; + + nRet = CUnicodeUtilities::parseUTF16Codepoint(cBOMBE, nValue, false); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, CUnicodeUtilities::scm_unBOMMarker); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cBOMLE, nValue, false); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, CUnicodeUtilities::scm_unBOMMarkerSwapped); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cBOMBE, nValue, true); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, CUnicodeUtilities::scm_unBOMMarkerSwapped); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cBOMLE, nValue, true); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, CUnicodeUtilities::scm_unBOMMarker); + + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest1BE, nValue, false); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, 0x7a); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest1LE, nValue, true); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, 0x7a); + + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest2BE, nValue, false); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, 0x6c34); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest2LE, nValue, true); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nValue, 0x6c34); + + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest3BE, nValue, false); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nValue, 0x10000); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest3LE, nValue, true); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nValue, 0x10000); + + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest4BE, nValue, false); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nValue, 0x1d11e); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest4LE, nValue, true); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nValue, 0x1d11e); + + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest5BE, nValue, false); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nValue, 0x10fffd); + nRet = CUnicodeUtilities::parseUTF16Codepoint(cTest5LE, nValue, true); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nValue, 0x10fffd); + + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 2, 0x7a, false); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK(! memcmp(cTest1BE, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 2, 0x7a, true); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK(! memcmp(cTest1LE, cBuffer, 1)); + + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 2, 0x6c34, false); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK(! memcmp(cTest2BE, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 2, 0x6c34, true); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK(! memcmp(cTest2LE, cBuffer, 1)); + + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 4, 0x10000, false); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK(! memcmp(cTest3BE, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 4, 0x10000, true); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK(! memcmp(cTest3LE, cBuffer, 1)); + + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 4, 0x1d11e, false); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK(! memcmp(cTest4BE, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 4, 0x1d11e, true); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK(! memcmp(cTest4LE, cBuffer, 1)); + + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 4, 0x10fffd, false); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK(! memcmp(cTest5BE, cBuffer, 1)); + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 4, 0x10fffd, true); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK(! memcmp(cTest5LE, cBuffer, 1)); + + nRet = CUnicodeUtilities::encodeUTF16Codepoint(0, 0, 0x6c34, false); + BOOST_CHECK_EQUAL(nRet, 2); + nRet = CUnicodeUtilities::encodeUTF16Codepoint(0, 0, 0x10fffd, false); + BOOST_CHECK_EQUAL(nRet, 4); + + cBuffer[0] = '\0'; + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 1, 0x6c34, false); + BOOST_CHECK_EQUAL(nRet, -1); + BOOST_CHECK_EQUAL(cBuffer[0], 0); + nRet = CUnicodeUtilities::encodeUTF16Codepoint(cBuffer, 3, 0x10fffd, false); + BOOST_CHECK_EQUAL(nRet, -1); + BOOST_CHECK_EQUAL(cBuffer[0], 0); +} + +BOOST_AUTO_TEST_CASE(CUnicodeUtilities_checkUTF8) +{ + int nRet; + + const TForteByte cASCII1[] = { 0 }; + const TForteByte cASCII2[] = { 'A', 0 }; + const TForteByte cASCII3[] = { 0x7f, 0 }; + const TForteByte cUpper1[] = { 0xc2, 0xa2, 0 }; + const TForteByte cUpper2[] = { 0xe2, 0x82, 0xac, 0 }; + const TForteByte cUpper3[] = { 0xf0, 0xa4, 0xad, 0xa2, 0 }; + const TForteByte cSeq[] = { 0x7f, 0xc2, 0xa2, 0xe2, 0x82, 0xac, 0xf0, 0xa4, 0xad, 0xa2, 0x7f, 0 }; + unsigned int nWidth; + + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cASCII1, -1, nWidth); + BOOST_CHECK_EQUAL(nRet, 0); + BOOST_CHECK_EQUAL(nWidth, 7); + + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cASCII2, -1, nWidth); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nWidth, 7); + + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cASCII3, -1, nWidth); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nWidth, 7); + + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cUpper1, -1, nWidth); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nWidth, 8); + + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cUpper2, -1, nWidth); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nWidth, 16); + + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cUpper3, -1, nWidth); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nWidth, 21); + + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 1, nWidth); + BOOST_CHECK_EQUAL(nRet, 1); + BOOST_CHECK_EQUAL(nWidth, 7); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 2, nWidth); + BOOST_CHECK_EQUAL(nRet, -1); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 3, nWidth); + BOOST_CHECK_EQUAL(nRet, 2); + BOOST_CHECK_EQUAL(nWidth, 8); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 4, nWidth); + BOOST_CHECK_EQUAL(nRet, -1); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 5, nWidth); + BOOST_CHECK_EQUAL(nRet, -1); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 6, nWidth); + BOOST_CHECK_EQUAL(nRet, 3); + BOOST_CHECK_EQUAL(nWidth, 16); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 7, nWidth); + BOOST_CHECK_EQUAL(nRet, -1); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 8, nWidth); + BOOST_CHECK_EQUAL(nRet, -1); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 9, nWidth); + BOOST_CHECK_EQUAL(nRet, -1); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 10, nWidth); + BOOST_CHECK_EQUAL(nRet, 4); + BOOST_CHECK_EQUAL(nWidth, 21); + nWidth = 0; + nRet = CUnicodeUtilities::checkUTF8((const char *) cSeq, 11, nWidth); + BOOST_CHECK_EQUAL(nRet, 5); + BOOST_CHECK_EQUAL(nWidth, 21); +} + + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/convert_to_STRING_test.cpp b/tests/core/datatypes/convert_to_STRING_test.cpp new file mode 100644 index 000000000..da365afed --- /dev/null +++ b/tests/core/datatypes/convert_to_STRING_test.cpp @@ -0,0 +1,229 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/convert_functions.h" +#include "../../../src/core/datatypes/forte_string.h" + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//Time +#include "../../../src/core/datatypes/forte_time.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +BOOST_AUTO_TEST_SUITE(Datatypes_to_STRING_conversion_test) + +BOOST_AUTO_TEST_CASE(BOOLS_AND_BITS_to_STRING_test) +{ + CIEC_STRING sTest; + CIEC_STRING sResult; + //check BOOL + CIEC_BOOL bTest = true; + sResult = "TRUE"; + sTest = BOOL_TO_STRING(bTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 4); + + //check WORD + CIEC_WORD nWTest = 0xffff; + sResult = "65535"; + sTest = WORD_TO_STRING(nWTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 5); + + //check DWORD 4294967295 + CIEC_DWORD nDWTest = 0xffffffff; + sResult = "4294967295"; + sTest = DWORD_TO_STRING(nDWTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 10); + + //check BYTE 255U + CIEC_BYTE nBTest; + nBTest= 255U; + sResult = "255"; + sTest = BYTE_TO_STRING(nBTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 3); + +#ifdef FORTE_USE_64BIT_DATATYPES + //check LWORD 255U + CIEC_LWORD nLWTest; + nLWTest= 18446744073709551615ULL; + sResult = "18446744073709551615"; + sTest = LWORD_TO_STRING(nLWTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 20); +#endif //FORTE_USE_64BIT_DATATYPES +} + +BOOST_AUTO_TEST_CASE(INTEGERS_to_STRING_test) +{ + CIEC_STRING sTest; + CIEC_STRING sResult; + + //check SINT + CIEC_SINT nSTest = 127; + sResult = "127"; + sTest = SINT_TO_STRING(nSTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 3); + + //check USINT + CIEC_USINT nUSTest = 255; + sResult = "255"; + sTest = USINT_TO_STRING(nUSTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 3); + + //check INT + CIEC_INT nITest = 32767; + sResult = "32767"; + sTest = INT_TO_STRING(nITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 5); + + //check UINT + CIEC_UINT nUITest = 65535; + sResult = "65535"; + sTest = UINT_TO_STRING(nUITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 5); + + //check DINT + CIEC_DINT nDITest = 2147483647; + sResult = "2147483647"; + sTest = DINT_TO_STRING(nDITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 10); + + //check UDINT + CIEC_UDINT nUDITest = 4294967295ULL; + sResult = "4294967295"; + sTest = UDINT_TO_STRING(nUDITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 10); + +#ifdef FORTE_USE_64BIT_DATATYPES + //check LINT + CIEC_LINT nLITest; + nLITest= 9223372036854775807LL; + sResult = "9223372036854775807"; + sTest = LINT_TO_STRING(nLITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 19); + + //check ULINT + CIEC_ULINT nULITest; + nULITest= 18446744073709551615ULL; + sResult = "18446744073709551615"; + sTest = ULINT_TO_STRING(nULITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 20); +#endif //FORTE_USE_64BIT_DATATYPES +} + +BOOST_AUTO_TEST_CASE(TIME_to_STRING_test) +{ + CIEC_STRING sTest; + CIEC_STRING sResult; + + //check TIME + CIEC_TIME tTest = "T#3000ms"; + sResult = "T#3000ms"; + sTest = TIME_TO_STRING(tTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 8); +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(REAL_to_STRING_test) +{ + CIEC_STRING sTest; + CIEC_STRING sResult; + + //check REAL + CIEC_REAL nRTest = 1.46e-3f; + sResult = "0.00146"; + sTest = REAL_TO_STRING(nRTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 7); + +#ifdef FORTE_USE_64BIT_DATATYPES + //check LREAL + CIEC_LREAL nLRTest = -2.2874e6; + sResult = "-2287400"; + sTest = LREAL_TO_STRING(nLRTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 8); +#endif //FORTE_USE_64BIT_DATATYPES +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/datatypes/convert_to_WSTRING_test.cpp b/tests/core/datatypes/convert_to_WSTRING_test.cpp new file mode 100644 index 000000000..caedfd7e3 --- /dev/null +++ b/tests/core/datatypes/convert_to_WSTRING_test.cpp @@ -0,0 +1,229 @@ +/******************************************************************************* + * Copyright (c) 2014 Profactor GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Matthias Plasch - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include + +#include "../../../src/core/convert_functions.h" +#include "../../../src/core/datatypes/forte_wstring.h" + +//BOOLEAN +#include "../../../src/core/datatypes/forte_bool.h" +//BIT-Datatypes +#include "../../../src/core/datatypes/forte_byte.h" +#include "../../../src/core/datatypes/forte_word.h" +#include "../../../src/core/datatypes/forte_dword.h" +//INT-Datatypes +#include "../../../src/core/datatypes/forte_sint.h" +#include "../../../src/core/datatypes/forte_usint.h" +#include "../../../src/core/datatypes/forte_int.h" +#include "../../../src/core/datatypes/forte_uint.h" +#include "../../../src/core/datatypes/forte_dint.h" +#include "../../../src/core/datatypes/forte_udint.h" +//Time +#include "../../../src/core/datatypes/forte_time.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include + + #include "../../../src/core/datatypes/forte_real.h" +#endif //FORTE_USE_REAL_DATATYPE + +#ifdef FORTE_USE_64BIT_DATATYPES + #include "../../../src/core/datatypes/forte_lword.h" + #include "../../../src/core/datatypes/forte_lint.h" + #include "../../../src/core/datatypes/forte_ulint.h" + +#ifdef FORTE_USE_REAL_DATATYPE + #include "../../../src/core/datatypes/forte_lreal.h" +#endif //FORTE_USE_REAL_DATATYPE +#endif //FORTE_USE_64BIT_DATATYPES + +BOOST_AUTO_TEST_SUITE(Datatypes_to_WSTRING_conversion_test) + +BOOST_AUTO_TEST_CASE(BOOLS_AND_BITS_to_WSTRING_test) +{ + CIEC_WSTRING sTest; + CIEC_WSTRING sResult; + //check BOOL + CIEC_BOOL bTest = true; + sResult = "TRUE"; + sTest = BOOL_TO_WSTRING(bTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 4); + + //check WORD + CIEC_WORD nWTest = 0xffff; + sResult = "65535"; + sTest = WORD_TO_WSTRING(nWTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 5); + + //check DWORD 4294967295 + CIEC_DWORD nDWTest = 0xffffffff; + sResult = "4294967295"; + sTest = DWORD_TO_WSTRING(nDWTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 10); + + //check BYTE 255U + CIEC_BYTE nBTest; + nBTest= 255U; + sResult = "255"; + sTest = BYTE_TO_WSTRING(nBTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 3); + +#ifdef FORTE_USE_64BIT_DATATYPES + //check LWORD 255U + CIEC_LWORD nLWTest; + nLWTest= 18446744073709551615ULL; + sResult = "18446744073709551615"; + sTest = LWORD_TO_WSTRING(nLWTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 20); +#endif //FORTE_USE_64BIT_DATATYPES +} + +BOOST_AUTO_TEST_CASE(INTEGERS_to_WSTRING_test) +{ + CIEC_WSTRING sTest; + CIEC_WSTRING sResult; + + //check SINT + CIEC_SINT nSTest = 127; + sResult = "127"; + sTest = SINT_TO_WSTRING(nSTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 3); + + //check USINT + CIEC_USINT nUSTest = 255; + sResult = "255"; + sTest = USINT_TO_WSTRING(nUSTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 3); + + //check INT + CIEC_INT nITest = 32767; + sResult = "32767"; + sTest = INT_TO_WSTRING(nITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 5); + + //check UINT + CIEC_UINT nUITest = 65535; + sResult = "65535"; + sTest = UINT_TO_WSTRING(nUITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 5); + + //check DINT + CIEC_DINT nDITest = 2147483647; + sResult = "2147483647"; + sTest = DINT_TO_WSTRING(nDITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 10); + + //check UDINT + CIEC_UDINT nUDITest = 4294967295ULL; + sResult = "4294967295"; + sTest = UDINT_TO_WSTRING(nUDITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 10); + +#ifdef FORTE_USE_64BIT_DATATYPES + //check LINT + CIEC_LINT nLITest; + nLITest= 9223372036854775807LL; + sResult = "9223372036854775807"; + sTest = LINT_TO_WSTRING(nLITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 19); + + //check ULINT + CIEC_ULINT nULITest; + nULITest= 18446744073709551615ULL; + sResult = "18446744073709551615"; + sTest = ULINT_TO_WSTRING(nULITest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 20); +#endif //FORTE_USE_64BIT_DATATYPES +} + +BOOST_AUTO_TEST_CASE(TIME_to_WSTRING_test) +{ + CIEC_WSTRING sTest; + CIEC_WSTRING sResult; + + //check TIME + CIEC_TIME tTest = "T#3000ms"; + sResult = "T#3000ms"; + sTest = TIME_TO_WSTRING(tTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 8); +} + +#ifdef FORTE_USE_REAL_DATATYPE +BOOST_AUTO_TEST_CASE(REAL_to_WSTRING_test) +{ + CIEC_WSTRING sTest; + CIEC_WSTRING sResult; + + //check REAL + CIEC_REAL nRTest = 1.46e-3f; + sResult = "0.00146"; + sTest = REAL_TO_WSTRING(nRTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 7); + +#ifdef FORTE_USE_64BIT_DATATYPES + //check LREAL + CIEC_LREAL nLRTest = -2.2874e6; + sResult = "-2287400"; + sTest = LREAL_TO_WSTRING(nLRTest); + //check result value + BOOST_CHECK(sTest == sResult); + //check length value + BOOST_CHECK_EQUAL(sTest.length(), 8); +#endif //FORTE_USE_64BIT_DATATYPES +} +#endif //FORTE_USE_REAL_DATATYPE + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/fbtests/CMakeLists.txt b/tests/core/fbtests/CMakeLists.txt new file mode 100644 index 000000000..39e79fde0 --- /dev/null +++ b/tests/core/fbtests/CMakeLists.txt @@ -0,0 +1,17 @@ +#******************************************************************************* +# * Copyright (c) 2011 - 2015 ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ +SET(SOURCE_GROUP ${SOURCE_GROUP}\\fbtests) + +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + + +forte_test_add_sourcefile_cpp(fbtester.cpp) +forte_test_add_sourcefile_cpp(fbtestsmanager.cpp) diff --git a/tests/core/fbtests/fbtester.cpp b/tests/core/fbtests/fbtester.cpp new file mode 100644 index 000000000..72d2e0448 --- /dev/null +++ b/tests/core/fbtests/fbtester.cpp @@ -0,0 +1,424 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "fbtester.h" +#include +#include "stringdict.h" +#include +#include +#include +#include +#include + +#ifdef WIN32 +#include +#define usleep(x) Sleep((x)/1000) +#else +#include +#endif +#include + +/**Helper functor for deleting stuff in containers + * + */ +struct SDeleteFunctor{ + template + void operator()(T* paVal) const{ + delete paVal; + } +}; + +//! Helper class allowing to access the can be connected function from the FBTester +class CFBTestConn : public CDataConnection{ + public: + static bool canBeConnected(const CIEC_ANY *pa_poSrcDataPoint, + const CIEC_ANY *pa_poDstDataPoint){ + bool bSpecialCast; + return CDataConnection::canBeConnected(pa_poSrcDataPoint, pa_poDstDataPoint, bSpecialCast); + } + private: + //you should not be allowed to create this class their for constructor and destructor are private + CFBTestConn(); + virtual ~CFBTestConn(); +}; + +CFBTester::CFBTester(CResource *pa_poTestResource) : + CFunctionBlock(pa_poTestResource, 0, 0, 0, 0), + mFBUnderTest(0), + m_nNumSuccesfulTestCases(0), m_nNumUnsuccesfulTestCases( + 0){ + + changeFBExecutionState(cg_nMGM_CMD_Start); +} + +CFBTester::~CFBTester(){ +} + +void CFBTester::executeTests(){ + printf("*****************************************************\n"); + printf("*** Testing FB: %s\n", + CStringDictionary::getInstance().get(getFBTypeId())); + printf("*** \n"); + + if(prepareTests()){ + evaluateTestResult(testCaseWrongInputEvent(), "Wrong Input Event"); + executeAllTests(); + } + cleanupTestData(); + + printf("***\n"); + printf("*** Test Summary:\n"); + printf("*** Executed %d test cases (%d successful, %d unsuccessful)\n", + m_nNumSuccesfulTestCases + m_nNumUnsuccesfulTestCases, + m_nNumSuccesfulTestCases, m_nNumUnsuccesfulTestCases); + printf("*****************************************************\n"); + +} + +bool CFBTester::prepareTests(){ + bool retVal = false; + + m_nNumSuccesfulTestCases = 0; + m_nNumUnsuccesfulTestCases = 0; + + performCreationTest(); + + if(0 != mFBUnderTest){ + performDataInterfaceTests(); + + mFBUnderTest->changeFBExecutionState(cg_nMGM_CMD_Start); + + createEventOutputConnections(); + if(createDataInputConnections()){ + if(createDataOutputConnections()){ + retVal = true; + } + } + if(false == retVal){ + //Inform test runner that we had an issue + m_nNumUnsuccesfulTestCases++; + } + } + + return retVal; +} + +void CFBTester::cleanupTestData(){ + + const SFBInterfaceSpec* interfaceSpec = mFBUnderTest->getFBInterfaceSpec(); + + for(TPortId i = 0; i < interfaceSpec->m_nNumEOs; i++){ + CEventConnection *eventCon = mFBUnderTest->getEOConection(interfaceSpec->m_aunEONames[i]); + BOOST_CHECK_EQUAL(e_RDY, eventCon->disconnect(this, interfaceSpec->m_aunEONames[i])); + } + + for(unsigned int i = 0; i < interfaceSpec->m_nNumDOs; ++i){ + CDataConnection *dataCon = mFBUnderTest->getDOConnection(interfaceSpec->m_aunDONames[i]); + //set it to zero so that when the FB under test is deleted it will not delete our test output data + dataCon->setValue(0); + + BOOST_CHECK_EQUAL(e_RDY, dataCon->disconnect(this, interfaceSpec->m_aunDONames[i])); + } + + for(unsigned int i = 0; i < interfaceSpec->m_nNumDIs; ++i){ + BOOST_CHECK_EQUAL(e_RDY, mDIConnections[i]->disconnect(mFBUnderTest, interfaceSpec->m_aunDINames[i])); + } + + for_each(mDIConnections.begin(), mDIConnections.end(), SDeleteFunctor()); + + performFBDeleteTests(); +} + +void CFBTester::performFBDeleteTests(){ + bool bTestResult = true; + + if(0 != mFBUnderTest){ + if(mFBUnderTest->isCurrentlyDeleteable()){ + bTestResult = false; + } + + if(e_RDY != mFBUnderTest->changeFBExecutionState(cg_nMGM_CMD_Stop)){ + bTestResult = false; + } + + if(!mFBUnderTest->isCurrentlyDeleteable()){ + bTestResult = false; + } + + if(!CTypeLib::deleteFB(mFBUnderTest)){ + bTestResult = false; + } + } + else{ + bTestResult = false; + } + + mFBUnderTest = 0; + + evaluateTestResult(bTestResult, "Type deletion"); +} + +void CFBTester::executeEvent(int pa_nEIID){ + CCriticalRegion criticalRegion(mOutputEventLock); + mFBOutputEvents.push_back(pa_nEIID); +} + +void CFBTester::triggerEvent(TPortId pa_nEIId){ + CEventChainExecutionThread *execThread = getResource().getResourceEventExecution(); + SEventEntry entry(mFBUnderTest, pa_nEIId); + + execThread->startEventChain(&entry); + + //Wait till event execution for this input event has finished + do{ + usleep(1); + } while(execThread->isProcessingEvents()); + +} + +void CFBTester::performCreationTest(){ + bool bTestResult = true; + + mFBUnderTest = CTypeLib::createFB(getFBTypeId(), getFBTypeId(), getResourcePtr()); + + if(0 == mFBUnderTest){ + bTestResult = false; + } + else{ + if((getFBTypeId() != mFBUnderTest->getFBTypeId()) + && (getFBTypeId() != mFBUnderTest->getInstanceNameId())){ + bTestResult = false; + } + else{ + + const SFBInterfaceSpec* interfaceSpec = mFBUnderTest->getFBInterfaceSpec(); + + SFBInterfaceSpec* testerInterfaceSpec = new SFBInterfaceSpec; + testerInterfaceSpec->m_nNumEIs = interfaceSpec->m_nNumEOs; + testerInterfaceSpec->m_aunEINames = interfaceSpec->m_aunEONames; + testerInterfaceSpec->m_anEIWith = 0; + testerInterfaceSpec->m_anEIWithIndexes = 0; + testerInterfaceSpec->m_nNumEOs = 0; + testerInterfaceSpec->m_aunEONames = 0; + testerInterfaceSpec->m_anEOWith = 0; + testerInterfaceSpec->m_anEOWithIndexes = 0; + testerInterfaceSpec->m_nNumDIs = interfaceSpec->m_nNumDOs; + testerInterfaceSpec->m_aunDINames = interfaceSpec->m_aunDONames; + testerInterfaceSpec->m_aunDIDataTypeNames = interfaceSpec->m_aunDODataTypeNames; + testerInterfaceSpec->m_nNumDOs = 0; + testerInterfaceSpec->m_aunDONames = 0; + testerInterfaceSpec->m_aunDODataTypeNames = 0; + testerInterfaceSpec->m_nNumAdapters = 0; + testerInterfaceSpec->m_pstAdapterInstanceDefinition = 0; + + setupFBInterface(testerInterfaceSpec, + (0 != testerInterfaceSpec->m_nNumDIs) ? + new TForteByte[genFBConnDataSize(testerInterfaceSpec->m_nNumEOs, + testerInterfaceSpec->m_nNumDIs, testerInterfaceSpec->m_nNumDOs)] : + 0, + (0 != testerInterfaceSpec->m_nNumDIs) ? + new TForteByte[genFBVarsDataSize(testerInterfaceSpec->m_nNumDIs, testerInterfaceSpec->m_nNumDOs)] : + 0, + true); + } + } + + evaluateTestResult(bTestResult, "Type creation"); +} + +void CFBTester::evaluateTestResult(bool pa_bSuccess, + const char* pa_acTestCaseName){ + if(pa_bSuccess){ + ++m_nNumSuccesfulTestCases; + } + else{ + ++m_nNumUnsuccesfulTestCases; + } + + printf("*** Test case: %s: %s\n", pa_acTestCaseName, + (pa_bSuccess) ? "ok" : "error"); +} + +int CFBTester::pullFirstChainEventID(){ + CCriticalRegion criticalRegion(mOutputEventLock); + int retVal = mFBOutputEvents.front(); + mFBOutputEvents.pop_front(); + return retVal; +} + +bool CFBTester::eventChainEmpty(){ + CCriticalRegion criticalRegion(mOutputEventLock); + bool retVal = mFBOutputEvents.empty(); + return retVal; +} + +void CFBTester::clearEventChain(){ + mFBOutputEvents.clear(); +} + +bool CFBTester::checkForSingleOutputEventOccurence(int pa_nExpectedEOId){ + bool bResult = (pullFirstChainEventID() == pa_nExpectedEOId); + + //Test if event chain is empty + if(!eventChainEmpty()){ + bResult = false; + } + + return bResult; +} + +void CFBTester::setInputData(TIEC_ANYPtr paInputData[], size_t paLenght){ + mInputDataBuffers.reserve(paLenght); + mInputDataBuffers.assign(paInputData, paInputData + paLenght); +} + +void CFBTester::setOutputData(TIEC_ANYPtr paOutputData[], size_t paLenght){ + mOutputDataBuffers.reserve(paLenght); + mOutputDataBuffers.assign(paOutputData, paOutputData + paLenght); +} + +void CFBTester::createEventOutputConnections(){ + const SFBInterfaceSpec* interfaceSpec = mFBUnderTest->getFBInterfaceSpec(); + + for(TPortId i = 0; i < interfaceSpec->m_nNumEOs; i++){ + CEventConnection *eventCon = mFBUnderTest->getEOConection(interfaceSpec->m_aunEONames[i]); + BOOST_CHECK_EQUAL(e_RDY, eventCon->connect(this, interfaceSpec->m_aunEONames[i])); + } +} + +bool CFBTester::createDataInputConnections(){ + bool retVal = true; + + const SFBInterfaceSpec* interfaceSpec = mFBUnderTest->getFBInterfaceSpec(); + + if(interfaceSpec->m_nNumDIs == mInputDataBuffers.size()){ + for(TPortId i = 0; i < interfaceSpec->m_nNumDIs; ++i){ + CInterface2InternalDataConnection *con = new CInterface2InternalDataConnection(); + mDIConnections.push_back(con); + con->setValue(mInputDataBuffers[i]); + if(e_RDY != con->connect(mFBUnderTest, interfaceSpec->m_aunDINames[i])){ + printf("*** FB test preparation: Given input data value for input %s can not be connected!\n", + CStringDictionary::getInstance().get(interfaceSpec->m_aunDINames[i])); + retVal = false; + break; + } + } + } + else{ + printf( + "*** FB test preparation: Wrong amount of input data given! Expected: %d, got: %lu\n", + interfaceSpec->m_nNumDIs, mInputDataBuffers.size()); + retVal = false; + } + + return retVal; +} + +bool CFBTester::createDataOutputConnections(){ + bool retVal = true; + + const SFBInterfaceSpec* interfaceSpec = mFBUnderTest->getFBInterfaceSpec(); + + if(interfaceSpec->m_nNumDOs == mOutputDataBuffers.size()){ + for(unsigned int i = 0; i < interfaceSpec->m_nNumDOs; ++i){ + if(CFBTestConn::canBeConnected(mOutputDataBuffers[i], mFBUnderTest->getDataOutput(interfaceSpec->m_aunDONames[i]))){ + CDataConnection *dataCon = mFBUnderTest->getDOConnection(interfaceSpec->m_aunDONames[i]); + dataCon->setValue(mOutputDataBuffers[i]); + if(e_RDY != dataCon->connect(this, interfaceSpec->m_aunDONames[i])){ + printf("*** FB test preparation: Cannot create data connection for output %s!\n", + CStringDictionary::getInstance().get(interfaceSpec->m_aunDONames[i])); + retVal = false; + break; + } + } + else{ + printf("*** FB test preparation: Given output data value for output %s can not be connected!\n", + CStringDictionary::getInstance().get(interfaceSpec->m_aunDONames[i])); + retVal = false; + break; + } + } + } + else{ + printf("*** FB test preparation: Wrong amount of output data given! Expected: %d, got: %lu\n", + interfaceSpec->m_nNumDOs, mOutputDataBuffers.size()); + retVal = false; + } + + return retVal; + +} + +bool CFBTester::testCaseWrongInputEvent(){ + bool bResult = true; + + for(TPortId i = mFBUnderTest->getFBInterfaceSpec()->m_nNumEIs; i < cg_nExternalEventID; i++){ + triggerEvent(i); + if(!eventChainEmpty()){ + bResult = false; + break; + } + } + + return bResult; +} + +void CFBTester::performDataInterfaceTests(){ + const SFBInterfaceSpec* interfaceSpec = mFBUnderTest->getFBInterfaceSpec(); + + BOOST_CHECK_EQUAL(interfaceSpec->m_nNumDIs, mInputDataBuffers.size()); + + BOOST_CHECK(0 == mFBUnderTest->getDataInput(CStringDictionary::scm_nInvalidStringId)); + BOOST_CHECK_EQUAL(cg_unInvalidPortId, mFBUnderTest->getDIID(CStringDictionary::scm_nInvalidStringId)); + + for(TPortId i = 0; i < interfaceSpec->m_nNumDIs; ++i){ + CIEC_ANY *val = mFBUnderTest->getDataInput(interfaceSpec->m_aunDINames[i]); + BOOST_CHECK(0 != val); + //either we have the same datatypeid or the input is any + BOOST_CHECK((mInputDataBuffers[i]->getDataTypeID(), val->getDataTypeID()) || + (CIEC_ANY::e_ANY == val->getDataTypeID())); + + BOOST_CHECK_EQUAL(val, mFBUnderTest->getDIFromPortId(i)); + CStringDictionary::TStringId stringIdBuf = interfaceSpec->m_aunDINames[i]; + BOOST_CHECK_EQUAL(val, mFBUnderTest->getVar(&stringIdBuf, 1)); + + BOOST_CHECK_EQUAL(i, mFBUnderTest->getDIID(interfaceSpec->m_aunDINames[i])); + + //we should not be able to get a data output with a data input name + BOOST_CHECK(0 == mFBUnderTest->getDataOutput(interfaceSpec->m_aunDINames[i])); + BOOST_CHECK_EQUAL(cg_unInvalidPortId, mFBUnderTest->getDOID(interfaceSpec->m_aunDINames[i])); + } + + for(TPortId i = interfaceSpec->m_nNumDIs; i <= cg_unInvalidPortId; ++i){ + BOOST_CHECK(0 == mFBUnderTest->getDIFromPortId(i)); + } + + BOOST_CHECK_EQUAL(interfaceSpec->m_nNumDOs, mOutputDataBuffers.size()); + + BOOST_CHECK(0 == mFBUnderTest->getDataOutput(CStringDictionary::scm_nInvalidStringId)); + BOOST_CHECK_EQUAL(cg_unInvalidPortId, mFBUnderTest->getDOID(CStringDictionary::scm_nInvalidStringId)); + + for(TPortId i = 0; i < interfaceSpec->m_nNumDOs; ++i){ + CIEC_ANY *val = mFBUnderTest->getDataOutput(interfaceSpec->m_aunDONames[i]); + BOOST_CHECK(0 != val); + //either we have the same datatypeid or the input is any + BOOST_CHECK((mOutputDataBuffers[i]->getDataTypeID(), val->getDataTypeID()) || + (CIEC_ANY::e_ANY == val->getDataTypeID())); + + CStringDictionary::TStringId stringIdBuf = interfaceSpec->m_aunDONames[i]; + BOOST_CHECK_EQUAL(val, mFBUnderTest->getVar(&stringIdBuf, 1)); + + BOOST_CHECK_EQUAL(i, mFBUnderTest->getDOID(interfaceSpec->m_aunDONames[i])); + + //we should not be able to get a data out with a data output name + BOOST_CHECK(0 == mFBUnderTest->getDataInput(interfaceSpec->m_aunDONames[i])); + BOOST_CHECK_EQUAL(cg_unInvalidPortId, mFBUnderTest->getDIID(interfaceSpec->m_aunDONames[i])); + } +} diff --git a/tests/core/fbtests/fbtester.h b/tests/core/fbtests/fbtester.h new file mode 100644 index 000000000..8062a89c5 --- /dev/null +++ b/tests/core/fbtests/fbtester.h @@ -0,0 +1,145 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FBTESTER_H_ +#define FBTESTER_H_ + +#include "funcbloc.h" +#include "fbtestsmanager.h" +#include +#include + + +#define SETUP_INPUTDATA(...) \ + { \ + TIEC_ANYPtr inputData[] = {__VA_ARGS__}; \ + setInputData(inputData, (sizeof(inputData) / sizeof(inputData[0])) ); \ + } \ + + +#define SETUP_OUTPUTDATA(...) \ + { \ + TIEC_ANYPtr outputData[] = {__VA_ARGS__}; \ + setOutputData(outputData, (sizeof(outputData) / sizeof(outputData[0])) ); \ + } \ + + +class CFBTester : public CFunctionBlock{ + public: + virtual ~CFBTester(); + + //!execute the test cases for the FB and generate a test report + void executeTests(); + + unsigned int getNumSuccesfullTestCases(){ + return m_nNumSuccesfulTestCases; + } + + unsigned int getNumUnsuccesfullTestCases(){ + return m_nNumUnsuccesfulTestCases; + } + + virtual bool connectDI(TPortId , CDataConnection *){ + //for the FB test we can just return true here + return true; + } + + protected: + CFBTester(CResource *pa_poTestResource); + + /*!\brief invoke the FB under Test with the given event id + * + * @param pa_nEIId input event id to be sent to the fb under test + */ + void triggerEvent(TPortId pa_nEIId); + + /*!\brief report the status of a test case + * + * This function should be invoked for each test case executed within + * executeAllTests(). + * + * @param pa_bSuccess true if the test case was successful + * @param pa_acTestCaseName name of the test case + */ + void evaluateTestResult(bool pa_bSuccess, const char* pa_acTestCaseName); + + int pullFirstChainEventID(); + + bool eventChainEmpty(); + + /*!\brief Remove all events from the event chain bringing the tester into a defined state + * + */ + void clearEventChain(); + + /** Check if only one output event of the given event output Id has been sent by the FB + * + * @param pa_nExpectedEOId the output event Id to be checked for + * @return true if only one event of the given Id is in the event queue + */ + bool checkForSingleOutputEventOccurence(int pa_nExpectedEOId); + + void setInputData(TIEC_ANYPtr paInputData[], size_t paLenght); + void setOutputData(TIEC_ANYPtr paInputData[], size_t paLenght); + + private: + virtual void executeEvent(int pa_nEIID); + /*!\brief attempt to create the type from the type library + * + */ + void performCreationTest(); + + /*! \brief execute all tests cases of the FB + * + * This function needs to be implemented by the specific test class of + * a FB. each test cases has to report its results by invoking + * evaluateTestResult(bool pa_bSuccess, const char* pa_acTestCaseName) + */ + virtual void executeAllTests() = 0; + + /*! Prepare internal variables and the testee for the test + * + */ + bool prepareTests(); + void cleanupTestData(); + void performFBDeleteTests(); + void createEventOutputConnections(); + bool createDataInputConnections(); + bool createDataOutputConnections(); + + bool testCaseWrongInputEvent(); + + /* Check if all data inputs and data outputs as given in the interface struct can be accessed and + * if the data types are equal to the data provided by the fb tester + */ + void performDataInterfaceTests(); + + + std::vector mInputDataBuffers; + std::vector mOutputDataBuffers; + + + CFunctionBlock *mFBUnderTest; + std::vector mDIConnections; + + /*! \brief list for storing the output events received from the testee + * + * TODO add timestamps to the list + */ + std::deque mFBOutputEvents; + + CSyncObject mOutputEventLock; + + unsigned int m_nNumSuccesfulTestCases; + unsigned int m_nNumUnsuccesfulTestCases; + +}; + +#endif /* FBTESTER_H_ */ diff --git a/tests/core/fbtests/fbtestsmanager.cpp b/tests/core/fbtests/fbtestsmanager.cpp new file mode 100644 index 000000000..a0764df24 --- /dev/null +++ b/tests/core/fbtests/fbtestsmanager.cpp @@ -0,0 +1,108 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2015 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "fbtestsmanager.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "fbtestsmanager_gen.cpp" +#endif +#include "fbtester.h" +#include +#include "../../src/core/device.h" +#include + +CFBTesterEntry::CFBTesterEntry(CStringDictionary::TStringId pa_nTypeNameId, + TFBTesterCreateFunc pa_pfuncCreateTester) : + CTypeLib::CTypeEntry(pa_nTypeNameId), m_pfuncCreateTester(pa_pfuncCreateTester){ + CFBTestsManager::getInstance().addFBTester(this); +} + +/*******************************************************************************/ +DEFINE_SINGLETON(CFBTestsManager) + +CFBTestsManager::CFBTestsManager(): m_nNumSuccessfulTestCases(0), m_nNumUnsuccessfulTestCases(0){ +} + +CFBTestsManager::~CFBTestsManager(){ +} + +unsigned int CFBTestsManager::runAllTests(CResource *paRessource){ + clearTestLog(); + + printf("*****************************************************\n"); + printf("*** Running all FB Tests!"); + printf("*** \n"); + + for(TFBTesterList::Iterator itRunner = m_lstroFBTesterList.begin(); + itRunner != m_lstroFBTesterList.end(); ++itRunner){ + executeFBTests(*itRunner, paRessource); + } + + printf("*****************************************************\n"); + printf("*** Overall Test Summary:\n"); + printf("*** Executed %d test cases (%u successful, %u unsuccessful)\n", m_nNumSuccessfulTestCases + + m_nNumUnsuccessfulTestCases, m_nNumSuccessfulTestCases, m_nNumUnsuccessfulTestCases); + printf("*****************************************************\n"); + + return m_nNumUnsuccessfulTestCases; +} + +void CFBTestsManager::addFBTester(CFBTesterEntry* pa_poFBTester){ + m_lstroFBTesterList.push_back(pa_poFBTester); +} + +void CFBTestsManager::executeFBTests(CFBTesterEntry* pa_poFBTestEntery, CResource *paRessource){ + CFBTester* poTester = pa_poFBTestEntery->createFBInstance(paRessource); + poTester->executeTests(); + + m_nNumSuccessfulTestCases += poTester->getNumSuccesfullTestCases(); + m_nNumUnsuccessfulTestCases += poTester->getNumUnsuccesfullTestCases(); + + delete poTester; +} + +void CFBTestsManager::clearTestLog(){ + m_nNumSuccessfulTestCases = 0; + m_nNumUnsuccessfulTestCases = 0; +} + +BOOST_AUTO_TEST_SUITE(FBTests) + + const SFBInterfaceSpec scm_stFBInterfaceSpec = { 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, + 0, + 0 }; + + BOOST_AUTO_TEST_CASE(runallFBTests){ + CDevice dev(&scm_stFBInterfaceSpec, CStringDictionary::scm_nInvalidStringId, 0, 0); + + CResource *res = (CResource *)CTypeLib::createFB(g_nStringIdEMB_RES, g_nStringIdEMB_RES, &dev); + BOOST_CHECK(0 != res); + + if(res != 0){ + dev.addFB(res); + + BOOST_CHECK_EQUAL(1, dev.startDevice()); + CFunctionBlock::E_FBStates state = dev.getState(); + BOOST_CHECK_EQUAL(CFunctionBlock::e_RUNNING, state); + + if(CFunctionBlock::e_RUNNING == state){ + //only run fb tests if the environment is correctly up and running + BOOST_CHECK_EQUAL(0, CFBTestsManager::getInstance().runAllTests(res)); + } + + BOOST_CHECK_EQUAL(false, res->isCurrentlyDeleteable()); + BOOST_CHECK_EQUAL(e_RDY, dev.changeFBExecutionState(cg_nMGM_CMD_Stop)); + BOOST_CHECK_EQUAL(true, res->isCurrentlyDeleteable()); + //as we added the resource to the device's object handler it will be deleted by it + } + + } + + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/fbtests/fbtestsmanager.h b/tests/core/fbtests/fbtestsmanager.h new file mode 100644 index 000000000..df0f512b7 --- /dev/null +++ b/tests/core/fbtests/fbtestsmanager.h @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef FBTESTSMANAGER_H_ +#define FBTESTSMANAGER_H_ + +#include +#include +#include +#include + +class CFBTester; + +typedef CFBTester *(*TFBTesterCreateFunc)(CResource *); + + +#define DECLARE_FB_TESTER(testerclass) \ + private: \ + const static CFBTesterEntry csm_oFBTesterEntry_##fbclass; \ + public: \ + static CFBTester *createFBTester(CResource *m_poTestResource){ \ + return new testerclass(m_poTestResource); \ + }; \ + virtual CStringDictionary::TStringId getFBTypeId(void) const; \ + private: + +#define DEFINE_FB_TESTER(testerclass, fbTypeNameId)\ + const CFBTesterEntry testerclass::csm_oFBTesterEntry_##fbclass((fbTypeNameId), testerclass::createFBTester); \ + CStringDictionary::TStringId testerclass::getFBTypeId(void) const {return (fbTypeNameId); } + + +class CFBTesterEntry : public CTypeLib::CTypeEntry{ + public: + CFBTesterEntry(CStringDictionary::TStringId pa_nTypeNameId, TFBTesterCreateFunc pa_pfuncCreateTester); + + CFBTester *createFBInstance(CResource *m_poTestResource){ + return m_pfuncCreateTester(m_poTestResource); + } + private: + TFBTesterCreateFunc m_pfuncCreateTester; +}; + + +class CFBTestsManager{ + DECLARE_SINGLETON(CFBTestsManager) + + public: + /**\brief Run the FB test for all registered function block tests. + * + * \return returns the number of unsuccessful test cases + */ + unsigned int runAllTests(CResource *paRessource); + void runTestsForFB(CStringDictionary::TStringId pa_nFBTypeNameId); + + void addFBTester(CFBTesterEntry* pa_poFBTester); + + private: + void executeFBTests(CFBTesterEntry* pa_poFBTestEntery, CResource *paRessource); + void clearTestLog(); + + typedef CSinglyLinkedList TFBTesterList; + + TFBTesterList m_lstroFBTesterList; + + unsigned int m_nNumSuccessfulTestCases; + unsigned int m_nNumUnsuccessfulTestCases; +}; + +#endif /* FBTESTSMANGER_H_ */ diff --git a/tests/core/mgmstatemachinetest.cpp b/tests/core/mgmstatemachinetest.cpp new file mode 100644 index 000000000..4404f8313 --- /dev/null +++ b/tests/core/mgmstatemachinetest.cpp @@ -0,0 +1,172 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "../../src/core/funcbloc.h" + +class CFunctionBlockMock : public CFunctionBlock{ + public: + CFunctionBlockMock() : + CFunctionBlock(0, 0, 0, 0, 0){ + } + + virtual CStringDictionary::TStringId getFBTypeId(void) const{ + return CStringDictionary::scm_nInvalidStringId; + } + + private: + virtual void executeEvent(int){ + } +}; + +BOOST_AUTO_TEST_SUITE(ManagedObjectStateMachine) + + BOOST_AUTO_TEST_CASE(idleTest){ + CFunctionBlockMock testee; + + BOOST_CHECK_EQUAL(CFunctionBlock::e_IDLE, testee.getState()); + + BOOST_CHECK(testee.isCurrentlyDeleteable()); + + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Stop)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_IDLE, testee.getState()); + + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Kill)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_IDLE, testee.getState()); + + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Reset)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_IDLE, testee.getState()); + + BOOST_CHECK_EQUAL(e_RDY, testee.changeFBExecutionState(cg_nMGM_CMD_Start)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_RUNNING, testee.getState()); + } + + void putTesteeIntoRun(CFunctionBlock &paTestee){ + paTestee.changeFBExecutionState(cg_nMGM_CMD_Start); + } + + BOOST_AUTO_TEST_CASE(runningTest){ + CFunctionBlockMock testee; + putTesteeIntoRun(testee); + + BOOST_CHECK_EQUAL(false, testee.isCurrentlyDeleteable()); + + BOOST_CHECK_EQUAL(CFunctionBlock::e_RUNNING, testee.getState()); + + //we should not be able to reset it + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Reset)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_RUNNING, testee.getState()); + + //we should not be able to start it + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Start)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_RUNNING, testee.getState()); + + //we should be able to stop it + BOOST_CHECK_EQUAL(e_RDY, testee.changeFBExecutionState(cg_nMGM_CMD_Stop)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_STOPPED, testee.getState()); + + //we shold be able to kill it, use a new testee to have a clean running state + CFunctionBlockMock killTestee; + putTesteeIntoRun(killTestee); + + BOOST_CHECK_EQUAL(e_RDY, killTestee.changeFBExecutionState(cg_nMGM_CMD_Kill)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_KILLED, killTestee.getState()); + } + + void putTesteeIntoStopped(CFunctionBlock &paTestee){ + putTesteeIntoRun(paTestee); + paTestee.changeFBExecutionState(cg_nMGM_CMD_Stop); + } + + BOOST_AUTO_TEST_CASE(stoppedTest){ + CFunctionBlockMock testee; + putTesteeIntoStopped(testee); + + BOOST_CHECK(testee.isCurrentlyDeleteable()); + + //we should not be able to kill it + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Kill)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_STOPPED, testee.getState()); + + //we should not be able to stop it + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Stop)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_STOPPED, testee.getState()); + + //we should be able to start it + BOOST_CHECK_EQUAL(e_RDY, testee.changeFBExecutionState(cg_nMGM_CMD_Start)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_RUNNING, testee.getState()); + + //we should be able to reset it, use new testeee for a clean stopped state + CFunctionBlockMock resetTestee; + putTesteeIntoStopped(resetTestee); + + BOOST_CHECK_EQUAL(e_RDY, resetTestee.changeFBExecutionState(cg_nMGM_CMD_Reset)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_IDLE, resetTestee.getState()); + + } + + void putTesteeIntoKilled(CFunctionBlock &paTestee){ + putTesteeIntoRun(paTestee); + paTestee.changeFBExecutionState(cg_nMGM_CMD_Kill); + } + + BOOST_AUTO_TEST_CASE(killedTest){ + CFunctionBlockMock testee; + putTesteeIntoKilled(testee); + + BOOST_CHECK(testee.isCurrentlyDeleteable()); + + //we should not be able to kill it + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Kill)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_KILLED, testee.getState()); + + //we should not be able to stop it + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Stop)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_KILLED, testee.getState()); + + //we should not be able to start it + BOOST_CHECK_EQUAL(e_INVALID_STATE, testee.changeFBExecutionState(cg_nMGM_CMD_Start)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_KILLED, testee.getState()); + + //we should be able to reset it + BOOST_CHECK_EQUAL(e_RDY, testee.changeFBExecutionState(cg_nMGM_CMD_Reset)); + BOOST_CHECK_EQUAL(CFunctionBlock::e_IDLE, testee.getState()); + } + + void testAllOtherCommands(CFunctionBlock &paTestee, CFunctionBlock::E_FBStates paState){ + for(unsigned int i = 0; i <= cg_nMGM_CMD_INVALID; i++){ + if((i != cg_nMGM_CMD_Start) && (i != cg_nMGM_CMD_Stop) && (i != cg_nMGM_CMD_Kill) && (i != cg_nMGM_CMD_Reset)){ + BOOST_CHECK_EQUAL(e_INVALID_OPERATION, paTestee.changeFBExecutionState(static_cast(i))); + BOOST_CHECK_EQUAL(paState, paTestee.getState()); + } + } + } + + BOOST_AUTO_TEST_CASE(testOtherCommands){ + CFunctionBlockMock testee; + + //test for idle + testAllOtherCommands(testee, CFunctionBlock::e_IDLE); + + //test for running + testee.changeFBExecutionState(cg_nMGM_CMD_Start); + testAllOtherCommands(testee, CFunctionBlock::e_RUNNING); + + //test for stopped + testee.changeFBExecutionState(cg_nMGM_CMD_Stop); + testAllOtherCommands(testee, CFunctionBlock::e_STOPPED); + + //test for killed + testee.changeFBExecutionState(cg_nMGM_CMD_Start); + testee.changeFBExecutionState(cg_nMGM_CMD_Kill); + testAllOtherCommands(testee, CFunctionBlock::e_KILLED); + } + + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/nameidentifiertest.cpp b/tests/core/nameidentifiertest.cpp new file mode 100644 index 000000000..c1f442be6 --- /dev/null +++ b/tests/core/nameidentifiertest.cpp @@ -0,0 +1,109 @@ +/******************************************************************************* + * Copyright (c) 2015 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "../../src/core/mgmcmdstruct.h" + +/*!Tests for the TNameIdentifier class used to store name identifier lists + * + * Although it officially holds CstringDicitionalry::TStringIds we can use for most tests normal strings + * as there exists an own test for StringDict and TSringIds are just ints. + * + */ +BOOST_AUTO_TEST_SUITE(TNameIdentifierTests) + + BOOST_AUTO_TEST_CASE(newEmptyNameList){ + forte::core::TNameIdentifier identifier; + + BOOST_CHECK(identifier.isEmpty()); + + BOOST_CHECK_EQUAL(0, identifier.size()); + } + + BOOST_AUTO_TEST_CASE(capacity){ + //check that we have the capacity as configured in cmake + forte::core::TNameIdentifier identifier; + + for(size_t i = 0; i < FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY; i++){ + BOOST_CHECK(identifier.pushBack(static_cast(i))); + BOOST_CHECK_EQUAL(false, identifier.isEmpty()); + } + + BOOST_CHECK_EQUAL(false, identifier.pushBack(10)); + + identifier.clear(); + BOOST_CHECK(identifier.isEmpty()); + } + + BOOST_AUTO_TEST_CASE(pushBack){ + forte::core::TNameIdentifier identifier; + + identifier.pushBack(5); + BOOST_CHECK_EQUAL(1, identifier.size()); + BOOST_CHECK_EQUAL(5, identifier[0]); + BOOST_CHECK_EQUAL(5, identifier.back()); + BOOST_CHECK_EQUAL(5, identifier.front()); + + identifier.pushBack(10); + BOOST_CHECK_EQUAL(2, identifier.size()); + BOOST_CHECK_EQUAL(5, identifier[0]); + BOOST_CHECK_EQUAL(10, identifier[1]); + BOOST_CHECK_EQUAL(10, identifier.back()); + BOOST_CHECK_EQUAL(5, identifier.front()); + + identifier.pushBack(215); + BOOST_CHECK_EQUAL(3, identifier.size()); + BOOST_CHECK_EQUAL(5, identifier[0]); + BOOST_CHECK_EQUAL(10, identifier[1]); + BOOST_CHECK_EQUAL(215, identifier[2]); + BOOST_CHECK_EQUAL(215, identifier.back()); + BOOST_CHECK_EQUAL(5, identifier.front()); + + identifier.pushBack(3564); + BOOST_CHECK_EQUAL(4, identifier.size()); + BOOST_CHECK_EQUAL(5, identifier[0]); + BOOST_CHECK_EQUAL(10, identifier[1]); + BOOST_CHECK_EQUAL(215, identifier[2]); + BOOST_CHECK_EQUAL(3564, identifier[3]); + BOOST_CHECK_EQUAL(3564, identifier.back()); + BOOST_CHECK_EQUAL(5, identifier.front()); + } + + BOOST_AUTO_TEST_CASE(popBack){ + forte::core::TNameIdentifier identifier; + //fill with testdata + for(size_t i = 0; i < FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY; i++){ + identifier.pushBack(static_cast(i)); + } + + for(size_t i = 0; i < FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY; i++){ + BOOST_CHECK_EQUAL((FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY - 1 - i), identifier.back()); + BOOST_CHECK_EQUAL((FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY - i), identifier.size()); + identifier.popBack(); + BOOST_CHECK_EQUAL((FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY - 1 - i), identifier.size()); + } + BOOST_CHECK(identifier.isEmpty()); + } + + BOOST_AUTO_TEST_CASE(iterator){ + forte::core::TNameIdentifier identifier; + //fill with testdata + for(size_t i = 0; i < FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY; i++){ + identifier.pushBack(static_cast(i)); + } + + int i = 0; + for(forte::core::TNameIdentifier::CIterator it(identifier.begin()); it != identifier.end(); ++it, ++i){ + BOOST_CHECK_EQUAL(i, *it); + } + BOOST_CHECK_EQUAL(FORTE_MGM_MAX_SUPPORTED_NAME_HIERARCHY, i); //we should have exactly visited each element once but started at zero + } + + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/stringdicttests.cpp b/tests/core/stringdicttests.cpp new file mode 100644 index 000000000..01134cc9a --- /dev/null +++ b/tests/core/stringdicttests.cpp @@ -0,0 +1,112 @@ +/******************************************************************************* + * Copyright (c) 2013 - 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "../../src/core/stringdict.h" + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "stringdicttests_gen.cpp" +#else +#include "stringlist.h" +#endif + +#include +#include + +#ifndef _WIN32 + //somehow required here + const CStringDictionary::TStringId CStringDictionary::scm_nInvalidStringId; +#endif + +BOOST_AUTO_TEST_SUITE(StringDictTests) + + BOOST_AUTO_TEST_CASE(newString){ + //TEst new string if it is not in string dict and after inserting is inside and the correct string + const std::string sTestString("FORTE_4DIAC_TestString"); + + BOOST_CHECK_EQUAL(CStringDictionary::scm_nInvalidStringId, CStringDictionary::getInstance().getId(sTestString.c_str())); + + CStringDictionary::TStringId unNewID = CStringDictionary::getInstance().insert(sTestString.c_str()); + BOOST_CHECK(CStringDictionary::scm_nInvalidStringId != unNewID); + + BOOST_CHECK_EQUAL(unNewID, CStringDictionary::getInstance().getId(sTestString.c_str())); + + BOOST_CHECK_EQUAL(sTestString, CStringDictionary::getInstance().get(unNewID)); + } + + BOOST_AUTO_TEST_CASE(availableString){ + //test if a string that should be pre inserted in the stringdict on compile time is available + std::string sBool(CStringDictionary::getInstance().get(g_nStringIdBOOL)); + BOOST_CHECK_EQUAL(sBool, "BOOL"); + + BOOST_CHECK_EQUAL(g_nStringIdBOOL, CStringDictionary::getInstance().getId(sBool.c_str())); + + } + + void stringIdTest(CStringDictionary::TStringId pa_unId, const std::string &pa_rsExpectedString){ + std::string sTestString(CStringDictionary::getInstance().get(pa_unId)); + BOOST_CHECK_EQUAL(sTestString, pa_rsExpectedString); + BOOST_CHECK_EQUAL(pa_unId, CStringDictionary::getInstance().getId(pa_rsExpectedString.c_str())); + } + + BOOST_AUTO_TEST_CASE(reinsertAvailableString){ + //Test that a reinsert of a string does not corrupt the string dict + BOOST_CHECK_EQUAL(g_nStringIdSTRING, CStringDictionary::getInstance().insert("STRING")); + } + + BOOST_AUTO_TEST_CASE(availableLowerUpperCaseTest){ + //test if lower and upper case strings are correctly sorted by the build system and look up of them works + stringIdTest(g_nStringIdlowercasetest, "lowercasetest"); + stringIdTest(g_nStringIdLOWERCASETEST, "LOWERCASETEST"); + } + + BOOST_AUTO_TEST_CASE(newLowerUpperCaseTest){ + //test if lower and upper case strings are correctly sorted when inserting at runtime and look up of them works + stringIdTest(CStringDictionary::getInstance().insert("newteststring"), "newteststring"); + stringIdTest(CStringDictionary::getInstance().insert("NEWTESTSTRING"), "NEWTESTSTRING"); + } + + struct SBuffer{ + CStringDictionary::TStringId mID; + std::string mString; + }; + + BOOST_AUTO_TEST_CASE(reallocateTest){ + //Test a large amount of strings so that a reallocation of the stringdict buffers is necessary + + std::list stringList; + + + for(unsigned int i = 0; i < 1000; i++){ + SBuffer buffer; + char newStringDictEntry[40]; + #ifdef WIN32 + _snprintf( + #else + snprintf( + #endif + newStringDictEntry, 40, "LargeStringTestStringNumber%ud", i); + + buffer.mString = newStringDictEntry; + BOOST_CHECK_EQUAL(CStringDictionary::scm_nInvalidStringId, CStringDictionary::getInstance().getId(newStringDictEntry)); + buffer.mID = CStringDictionary::getInstance().insert(newStringDictEntry); + + stringList.push_back(buffer); + + //Check that every entry is still in the stringdict + for(std::list::iterator itRunner = stringList.begin(); itRunner != stringList.end(); ++itRunner){ + BOOST_CHECK_EQUAL(itRunner->mID, CStringDictionary::getInstance().getId(itRunner->mString.c_str())); + BOOST_CHECK_EQUAL(itRunner->mString, CStringDictionary::getInstance().get(itRunner->mID)); + } + } + + } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/typelibdatatypetests.cpp b/tests/core/typelibdatatypetests.cpp new file mode 100644 index 000000000..5c08f9ead --- /dev/null +++ b/tests/core/typelibdatatypetests.cpp @@ -0,0 +1,322 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "../../src/core/typelib.h" +#include "../../src/core/datatypes/forte_any.h" +#include "../../src/core/datatypes/forte_bool.h" +#include "../../src/core/datatypes/forte_sint.h" +#include "../../src/core/datatypes/forte_int.h" +#include "../../src/core/datatypes/forte_dint.h" +#include "../../src/core/datatypes/forte_lint.h" +#include "../../src/core/datatypes/forte_usint.h" +#include "../../src/core/datatypes/forte_uint.h" +#include "../../src/core/datatypes/forte_udint.h" +#include "../../src/core/datatypes/forte_ulint.h" +#include "../../src/core/datatypes/forte_byte.h" +#include "../../src/core/datatypes/forte_word.h" +#include "../../src/core/datatypes/forte_dword.h" +#include "../../src/core/datatypes/forte_lword.h" +#include "../../src/core/datatypes/forte_date.h" +#include "../../src/core/datatypes/forte_date_and_time.h" +#include "../../src/core/datatypes/forte_time_of_day.h" +#include "../../src/core/datatypes/forte_time.h" +#include "../../src/core/datatypes/forte_real.h" +#include "../../src/core/datatypes/forte_lreal.h" +#include "../../src/core/datatypes/forte_string.h" +#include "../../src/core/datatypes/forte_wstring.h" + + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "typelibdatatypetests_gen.cpp" +#else +#include "stringlist.h" +#endif + +BOOST_AUTO_TEST_SUITE(TypeLibDataTypeTests) + + BOOST_AUTO_TEST_CASE(createANY){ + TForteByte acDataBuf[sizeof(CIEC_ANY)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdANY, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_ANY, poVal->getDataTypeID()); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdANY, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_ANY, poVal->getDataTypeID()); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createBOOL){ + TForteByte acDataBuf[sizeof(CIEC_BOOL)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdBOOL, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_BOOL, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(false, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdBOOL, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_BOOL, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(false, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createSINT){ + TForteByte acDataBuf[sizeof(CIEC_SINT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdSINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_SINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdSINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_SINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createINT){ + TForteByte acDataBuf[sizeof(CIEC_INT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_INT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_INT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createDINT){ + TForteByte acDataBuf[sizeof(CIEC_DINT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdDINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdDINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_AUTO_TEST_CASE(createLINT){ + TForteByte acDataBuf[sizeof(CIEC_LINT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdLINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_LINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdLINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_LINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } +#endif + + BOOST_AUTO_TEST_CASE(createUSINT){ + TForteByte acDataBuf[sizeof(CIEC_USINT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdUSINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_USINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdUSINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_USINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createUINT){ + TForteByte acDataBuf[sizeof(CIEC_UINT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdUINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_UINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdUINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_UINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createUDINT){ + TForteByte acDataBuf[sizeof(CIEC_UDINT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdUDINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_UDINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdUDINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_UDINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_AUTO_TEST_CASE(createULINT){ + TForteByte acDataBuf[sizeof(CIEC_ULINT)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdULINT, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_ULINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdULINT, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_ULINT, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } +#endif + + BOOST_AUTO_TEST_CASE(createBYTE){ + TForteByte acDataBuf[sizeof(CIEC_BYTE)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdBYTE, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_BYTE, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdBYTE, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_BYTE, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createWORD){ + TForteByte acDataBuf[sizeof(CIEC_WORD)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdWORD, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_WORD, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdWORD, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_WORD, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createDWORD){ + TForteByte acDataBuf[sizeof(CIEC_DWORD)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdDWORD, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DWORD, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdDWORD, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DWORD, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + +#ifdef FORTE_USE_64BIT_DATATYPES + BOOST_AUTO_TEST_CASE(createLWORD){ + TForteByte acDataBuf[sizeof(CIEC_LWORD)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdLWORD, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_LWORD, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdLWORD, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_LWORD, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } +#endif + + BOOST_AUTO_TEST_CASE(createDATE){ + TForteByte acDataBuf[sizeof(CIEC_DATE)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdDATE, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DATE, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdDATE, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DATE, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createTIME_OF_DAY){ + TForteByte acDataBuf[sizeof(CIEC_TIME_OF_DAY)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdTIME_OF_DAY, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_TIME_OF_DAY, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdTIME_OF_DAY, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_TIME_OF_DAY, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createDATE_AND_TIME){ + TForteByte acDataBuf[sizeof(CIEC_DATE_AND_TIME)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdDATE_AND_TIME, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DATE_AND_TIME, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdDATE_AND_TIME, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_DATE_AND_TIME, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + + BOOST_AUTO_TEST_CASE(createTIME){ + TForteByte acDataBuf[sizeof(CIEC_TIME)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdTIME, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_TIME, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdTIME, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_TIME, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0, *static_cast(poVal)); + delete poVal; + } + +#ifdef FORTE_USE_REAL_DATATYPE + BOOST_AUTO_TEST_CASE(createREAL){ + TForteByte acDataBuf[sizeof(CIEC_REAL)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdREAL, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_REAL, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0.0f, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdREAL, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_REAL, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0.0f, *static_cast(poVal)); + delete poVal; + } +#endif + +#ifdef FORTE_USE_LREAL_DATATYPE + BOOST_AUTO_TEST_CASE(createLREAL){ + TForteByte acDataBuf[sizeof(CIEC_LREAL)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdLREAL, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_LREAL, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0.0f, *static_cast(poVal)); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdLREAL, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_LREAL, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL(0.0f, *static_cast(poVal)); + delete poVal; + } +#endif + + BOOST_AUTO_TEST_CASE(createSTRING){ + TForteByte acDataBuf[sizeof(CIEC_STRING)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdSTRING, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_STRING, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL("", static_cast(poVal)->getValue()); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdSTRING, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_STRING, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL("", static_cast(poVal)->getValue()); + delete poVal; + } + +#ifdef FORTE_USE_WSTRING_DATATYPE + BOOST_AUTO_TEST_CASE(createWSTRING){ + TForteByte acDataBuf[sizeof(CIEC_WSTRING)]; + CIEC_ANY *poVal = CTypeLib::createDataTypeInstance(g_nStringIdWSTRING, acDataBuf); + BOOST_CHECK_EQUAL(CIEC_ANY::e_WSTRING, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL("", static_cast(poVal)->getValue()); + + poVal = CTypeLib::createDataTypeInstance(g_nStringIdWSTRING, 0); + BOOST_CHECK_EQUAL(CIEC_ANY::e_WSTRING, poVal->getDataTypeID()); + BOOST_CHECK_EQUAL("", static_cast(poVal)->getValue()); + delete poVal; + } +#endif + + //TODO check array + + BOOST_AUTO_TEST_SUITE_END() + diff --git a/tests/core/utils/CMakeLists.txt b/tests/core/utils/CMakeLists.txt new file mode 100644 index 000000000..88cde1198 --- /dev/null +++ b/tests/core/utils/CMakeLists.txt @@ -0,0 +1,19 @@ +#/******************************************************************************* +# * Copyright (c) 2013 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + + +forte_test_add_inc_directories(${CMAKE_CURRENT_SOURCE_DIR}) +forte_test_add_link_directories(${CMAKE_BINARY_DIR}/src/core/utils) + +forte_test_add_sourcefile_cpp(string_utils_test.cpp) + + +forte_test_add_sourcefile_cpp(testsingleton.cpp singeltontest.cpp singletontest2ndunit.cpp) \ No newline at end of file diff --git a/tests/core/utils/singeltontest.cpp b/tests/core/utils/singeltontest.cpp new file mode 100644 index 000000000..5ae84a5da --- /dev/null +++ b/tests/core/utils/singeltontest.cpp @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "testsingleton.h" + +BOOST_AUTO_TEST_SUITE(Singleton_Test) + + BOOST_AUTO_TEST_CASE(singleton_SingleInstanceTest){ + + TestSingleton *pSingleton1 = &(TestSingleton::getInstance()); + TestSingleton *pSingleton2 = &(TestSingleton::getInstance()); + + BOOST_CHECK_EQUAL(pSingleton1, pSingleton2); + + BOOST_CHECK_EQUAL(1, TestSingleton::getInstance().getSingletonID()); + } + + BOOST_AUTO_TEST_CASE(singleton_DifferentFunctionTest){ + BOOST_CHECK_EQUAL(1, TestSingleton::getInstance().getSingletonID()); + } + + +BOOST_AUTO_TEST_SUITE_END() + diff --git a/tests/core/utils/singletontest2ndunit.cpp b/tests/core/utils/singletontest2ndunit.cpp new file mode 100644 index 000000000..bcbb8f7e3 --- /dev/null +++ b/tests/core/utils/singletontest2ndunit.cpp @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "testsingleton.h" + +BOOST_AUTO_TEST_SUITE(Singleton_2ndCompilationUnitTest) + + BOOST_AUTO_TEST_CASE(singleton_2ndCompilationSingleInstanceTest){ + BOOST_CHECK_EQUAL(1, TestSingleton::getInstance().getSingletonID()); + } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/utils/string_utils_test.cpp b/tests/core/utils/string_utils_test.cpp new file mode 100644 index 000000000..cfbb1bff0 --- /dev/null +++ b/tests/core/utils/string_utils_test.cpp @@ -0,0 +1,416 @@ +/******************************************************************************* + * Copyright (c) 2013 - 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include +#include "../../../src/core/utils/string_utils.h" +#include +#include + +BOOST_AUTO_TEST_SUITE(CIEC_ARRAY_function_test) + + BOOST_AUTO_TEST_CASE(isDigit_Test){ + + for(char i = 0; i < '0'; i++){ + BOOST_CHECK(!forte::core::util::isDigit(i)); + } + + BOOST_CHECK(forte::core::util::isDigit('0')); + BOOST_CHECK(forte::core::util::isDigit('1')); + BOOST_CHECK(forte::core::util::isDigit('2')); + BOOST_CHECK(forte::core::util::isDigit('3')); + BOOST_CHECK(forte::core::util::isDigit('4')); + BOOST_CHECK(forte::core::util::isDigit('5')); + BOOST_CHECK(forte::core::util::isDigit('6')); + BOOST_CHECK(forte::core::util::isDigit('7')); + BOOST_CHECK(forte::core::util::isDigit('8')); + BOOST_CHECK(forte::core::util::isDigit('9')); + + for(int i = '9' + 1; i <= 255; i++){ + BOOST_CHECK(!forte::core::util::isDigit((char )i)); + } + } + + BOOST_AUTO_TEST_CASE(isAtoFChar){ + BOOST_CHECK(forte::core::util::isAtoFChar('a')); + BOOST_CHECK(forte::core::util::isAtoFChar('b')); + BOOST_CHECK(forte::core::util::isAtoFChar('c')); + BOOST_CHECK(forte::core::util::isAtoFChar('d')); + BOOST_CHECK(forte::core::util::isAtoFChar('e')); + BOOST_CHECK(forte::core::util::isAtoFChar('f')); + + BOOST_CHECK(forte::core::util::isAtoFChar('A')); + BOOST_CHECK(forte::core::util::isAtoFChar('B')); + BOOST_CHECK(forte::core::util::isAtoFChar('C')); + BOOST_CHECK(forte::core::util::isAtoFChar('D')); + BOOST_CHECK(forte::core::util::isAtoFChar('E')); + BOOST_CHECK(forte::core::util::isAtoFChar('F')); + + BOOST_CHECK(!forte::core::util::isAtoFChar('g')); + BOOST_CHECK(!forte::core::util::isAtoFChar('a' - 1)); + + BOOST_CHECK(!forte::core::util::isAtoFChar('G')); + BOOST_CHECK(!forte::core::util::isAtoFChar('A' - 1)); + + BOOST_CHECK(!forte::core::util::isAtoFChar(0)); + BOOST_CHECK(!forte::core::util::isAtoFChar('\0')); + BOOST_CHECK(!forte::core::util::isAtoFChar('\n')); + BOOST_CHECK(!forte::core::util::isAtoFChar('\r')); + BOOST_CHECK(!forte::core::util::isAtoFChar('\t')); + BOOST_CHECK(!forte::core::util::isAtoFChar('-')); + BOOST_CHECK(!forte::core::util::isAtoFChar('x')); + BOOST_CHECK(!forte::core::util::isAtoFChar('X')); + BOOST_CHECK(!forte::core::util::isAtoFChar('/')); + BOOST_CHECK(!forte::core::util::isAtoFChar('<')); + BOOST_CHECK(!forte::core::util::isAtoFChar('>')); + + BOOST_CHECK(!forte::core::util::isAtoFChar((char )255)); + } + + BOOST_AUTO_TEST_CASE(isHexDigit){ + BOOST_CHECK(forte::core::util::isHexDigit('0')); + BOOST_CHECK(forte::core::util::isHexDigit('1')); + BOOST_CHECK(forte::core::util::isHexDigit('2')); + BOOST_CHECK(forte::core::util::isHexDigit('3')); + BOOST_CHECK(forte::core::util::isHexDigit('4')); + BOOST_CHECK(forte::core::util::isHexDigit('5')); + BOOST_CHECK(forte::core::util::isHexDigit('6')); + BOOST_CHECK(forte::core::util::isHexDigit('7')); + BOOST_CHECK(forte::core::util::isHexDigit('8')); + BOOST_CHECK(forte::core::util::isHexDigit('9')); + + BOOST_CHECK(forte::core::util::isHexDigit('a')); + BOOST_CHECK(forte::core::util::isHexDigit('b')); + BOOST_CHECK(forte::core::util::isHexDigit('c')); + BOOST_CHECK(forte::core::util::isHexDigit('d')); + BOOST_CHECK(forte::core::util::isHexDigit('e')); + BOOST_CHECK(forte::core::util::isHexDigit('f')); + + BOOST_CHECK(forte::core::util::isHexDigit('A')); + BOOST_CHECK(forte::core::util::isHexDigit('B')); + BOOST_CHECK(forte::core::util::isHexDigit('C')); + BOOST_CHECK(forte::core::util::isHexDigit('D')); + BOOST_CHECK(forte::core::util::isHexDigit('E')); + BOOST_CHECK(forte::core::util::isHexDigit('F')); + + //some significant negative test cases + + BOOST_CHECK(!forte::core::util::isHexDigit('g')); + BOOST_CHECK(!forte::core::util::isHexDigit('a' - 1)); + + BOOST_CHECK(!forte::core::util::isHexDigit('G')); + BOOST_CHECK(!forte::core::util::isHexDigit('A' - 1)); + + BOOST_CHECK(!forte::core::util::isHexDigit('0' - 1)); + BOOST_CHECK(!forte::core::util::isHexDigit('9' + 1)); + + BOOST_CHECK(!forte::core::util::isHexDigit(0)); + BOOST_CHECK(!forte::core::util::isHexDigit('\0')); + BOOST_CHECK(!forte::core::util::isHexDigit('\n')); + BOOST_CHECK(!forte::core::util::isHexDigit('\r')); + BOOST_CHECK(!forte::core::util::isHexDigit('\t')); + BOOST_CHECK(!forte::core::util::isHexDigit('-')); + BOOST_CHECK(!forte::core::util::isHexDigit('x')); + BOOST_CHECK(!forte::core::util::isHexDigit('X')); + BOOST_CHECK(!forte::core::util::isHexDigit('/')); + BOOST_CHECK(!forte::core::util::isHexDigit('<')); + BOOST_CHECK(!forte::core::util::isHexDigit('>')); + + BOOST_CHECK(!forte::core::util::isHexDigit((char )255)); + } + + BOOST_AUTO_TEST_CASE(charDigitToInt){ + + BOOST_CHECK_EQUAL(0, forte::core::util::charDigitToInt('0')); + BOOST_CHECK_EQUAL(1, forte::core::util::charDigitToInt('1')); + BOOST_CHECK_EQUAL(2, forte::core::util::charDigitToInt('2')); + BOOST_CHECK_EQUAL(3, forte::core::util::charDigitToInt('3')); + BOOST_CHECK_EQUAL(4, forte::core::util::charDigitToInt('4')); + BOOST_CHECK_EQUAL(5, forte::core::util::charDigitToInt('5')); + BOOST_CHECK_EQUAL(6, forte::core::util::charDigitToInt('6')); + BOOST_CHECK_EQUAL(7, forte::core::util::charDigitToInt('7')); + BOOST_CHECK_EQUAL(8, forte::core::util::charDigitToInt('8')); + BOOST_CHECK_EQUAL(9, forte::core::util::charDigitToInt('9')); + } + + BOOST_AUTO_TEST_CASE(charAtoFToInt){ + + BOOST_CHECK_EQUAL(10, forte::core::util::charAtoFToInt('a')); + BOOST_CHECK_EQUAL(10, forte::core::util::charAtoFToInt('A')); + + BOOST_CHECK_EQUAL(11, forte::core::util::charAtoFToInt('b')); + BOOST_CHECK_EQUAL(11, forte::core::util::charAtoFToInt('B')); + + BOOST_CHECK_EQUAL(12, forte::core::util::charAtoFToInt('c')); + BOOST_CHECK_EQUAL(12, forte::core::util::charAtoFToInt('C')); + + BOOST_CHECK_EQUAL(13, forte::core::util::charAtoFToInt('d')); + BOOST_CHECK_EQUAL(13, forte::core::util::charAtoFToInt('D')); + + BOOST_CHECK_EQUAL(14, forte::core::util::charAtoFToInt('e')); + BOOST_CHECK_EQUAL(14, forte::core::util::charAtoFToInt('E')); + + BOOST_CHECK_EQUAL(15, forte::core::util::charAtoFToInt('f')); + BOOST_CHECK_EQUAL(15, forte::core::util::charAtoFToInt('F')); + } + + BOOST_AUTO_TEST_CASE(charHexDigitToInt){ + + BOOST_CHECK_EQUAL(0, forte::core::util::charHexDigitToInt('0')); + BOOST_CHECK_EQUAL(1, forte::core::util::charHexDigitToInt('1')); + BOOST_CHECK_EQUAL(2, forte::core::util::charHexDigitToInt('2')); + BOOST_CHECK_EQUAL(3, forte::core::util::charHexDigitToInt('3')); + BOOST_CHECK_EQUAL(4, forte::core::util::charHexDigitToInt('4')); + BOOST_CHECK_EQUAL(5, forte::core::util::charHexDigitToInt('5')); + BOOST_CHECK_EQUAL(6, forte::core::util::charHexDigitToInt('6')); + BOOST_CHECK_EQUAL(7, forte::core::util::charHexDigitToInt('7')); + BOOST_CHECK_EQUAL(8, forte::core::util::charHexDigitToInt('8')); + BOOST_CHECK_EQUAL(9, forte::core::util::charHexDigitToInt('9')); + + BOOST_CHECK_EQUAL(10, forte::core::util::charHexDigitToInt('a')); + BOOST_CHECK_EQUAL(10, forte::core::util::charHexDigitToInt('A')); + + BOOST_CHECK_EQUAL(11, forte::core::util::charHexDigitToInt('b')); + BOOST_CHECK_EQUAL(11, forte::core::util::charHexDigitToInt('B')); + + BOOST_CHECK_EQUAL(12, forte::core::util::charHexDigitToInt('c')); + BOOST_CHECK_EQUAL(12, forte::core::util::charHexDigitToInt('C')); + + BOOST_CHECK_EQUAL(13, forte::core::util::charHexDigitToInt('d')); + BOOST_CHECK_EQUAL(13, forte::core::util::charHexDigitToInt('D')); + + BOOST_CHECK_EQUAL(14, forte::core::util::charHexDigitToInt('e')); + BOOST_CHECK_EQUAL(14, forte::core::util::charHexDigitToInt('E')); + + BOOST_CHECK_EQUAL(15, forte::core::util::charHexDigitToInt('f')); + BOOST_CHECK_EQUAL(15, forte::core::util::charHexDigitToInt('F')); + } + + void strtolWrongInputCheck(const char* pa_acString, long int pa_nResult, unsigned int pa_unErrorPos){ + char *pacEndptr; + BOOST_CHECK_EQUAL(pa_nResult, forte::core::util::strtol(pa_acString, &pacEndptr, 10)); + BOOST_CHECK_EQUAL(pa_acString[pa_unErrorPos], *pacEndptr); + } + + //*assumes that overflow will happen when the last digit is parsed + void strtolOverflowCheck(const char* pa_acString, long int pa_nResult){ + strtolWrongInputCheck(pa_acString, pa_nResult, strlen(pa_acString) - 1); + BOOST_CHECK_EQUAL(ERANGE, errno); + } + + BOOST_AUTO_TEST_CASE(strtol){ + char *pacEndptr; + const unsigned int unTestData = 12; + std::string sTestData10[unTestData] = { "0", "255", "256", "65535", "65536", "2147483647", "-255", "-256", "-257", "-65536", "-65537", "-2147483648" }; + std::string sTestData16[unTestData] = { "0x0", "0xFF", "0x100", "0xFFFF", "0x10000", "0x7FFFFFFF", "-0xFF", "-0x100", "-0x101", "-0x10000", "-0x10001", "-0x80000000" }; + long int sTestDataResult[unTestData] = { 0, 255, 256, 65535, 65536, 2147483647, -255, -256, -257, -65536, -65537, -2147483648 }; + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtol(sTestData10[i].c_str(), &pacEndptr, 10)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtol(sTestData16[i].c_str(), &pacEndptr, 16)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + strtolOverflowCheck("2147483648", 2147483647); + strtolOverflowCheck("2147483649", 2147483647); + strtolOverflowCheck("2147483650", 2147483647); + strtolOverflowCheck("2147483651", 2147483647); + strtolOverflowCheck("2147483652", 2147483647); + strtolOverflowCheck("2147483653", 2147483647); + strtolOverflowCheck("2147483654", 2147483647); + strtolOverflowCheck("2147483655", 2147483647); + strtolOverflowCheck("2147483656", 2147483647); + strtolOverflowCheck("2147483657", 2147483647); + strtolOverflowCheck("2147483658", 2147483647); + strtolOverflowCheck("2147483659", 2147483647); + strtolOverflowCheck("2147483660", 2147483647); + strtolOverflowCheck("2147483661", 2147483647); + strtolOverflowCheck("2147483662", 2147483647); + + strtolOverflowCheck("-2147483649", -2147483648); + strtolOverflowCheck("-2147483650", -2147483648); + strtolOverflowCheck("-2147483651", -2147483648); + strtolOverflowCheck("-2147483652", -2147483648); + strtolOverflowCheck("-2147483653", -2147483648); + + strtolWrongInputCheck("hansi", 0, 0); + strtolWrongInputCheck("3267x23", 3267, 4); + strtolWrongInputCheck("-74219x52", -74219, 6); + + } + + void strtoulWrongInputCheck(const char* pa_acString, unsigned long int pa_unResult, unsigned int pa_unErrorPos, int base){ + char *pacEndptr; + BOOST_CHECK_EQUAL(pa_unResult, forte::core::util::strtoul(pa_acString, &pacEndptr, base)); + BOOST_CHECK_EQUAL(pa_acString[pa_unErrorPos], *pacEndptr); + } + + //*assumes that overflow will happen when the last digit is parsed + void strtoulOverflowCheck(const char* pa_acString, unsigned long int pa_unResult, int base){ + strtoulWrongInputCheck(pa_acString, pa_unResult, strlen(pa_acString) - 1, base); + BOOST_CHECK_EQUAL(ERANGE, errno); + } + + BOOST_AUTO_TEST_CASE(strtoul){ + char *pacEndptr; + const unsigned int unTestData = 7; + std::string sTestData10[unTestData] = { "0", "255", "256", "65535", "65536", "2147483647", "4294967295" }; + std::string sTestData16[unTestData] = { "0x0", "0xFF", "0x100", "0xFFFF", "0x10000", "0x7FFFFFFF", "0xFFFFFFFF" }; + long int sTestDataResult[unTestData] = { 0, 255, 256, 65535, 65536, 2147483647, 4294967295 }; + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtoul(sTestData10[i].c_str(), &pacEndptr, 10)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtoul(sTestData16[i].c_str(), &pacEndptr, 16)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + strtoulOverflowCheck("4294967296", 4294967295, 10); + strtoulOverflowCheck("4294967297", 4294967295, 10); + strtoulOverflowCheck("4294967298", 4294967295, 10); + strtoulOverflowCheck("4294967299", 4294967295, 10); + strtoulOverflowCheck("4294967300", 4294967295, 10); + strtoulOverflowCheck("0xFFFFFFFF1", 4294967295, 16); + strtoulOverflowCheck("0xFFFFFFF3a", 4294967295, 16); + + strtoulWrongInputCheck("hansi", 0, 0, 10); + strtoulWrongInputCheck("3267x23", 3267, 4, 10); + strtoulWrongInputCheck("-74219x52", 0, 0, 10); + + strtoulWrongInputCheck("0x74x219x52", 116, 4, 16); + strtoulWrongInputCheck("0x0x74x219x52", 0, 3, 16); + } + +#ifdef FORTE_USE_64BIT_DATATYPES + void strtollWrongInputCheck(const char* pa_acString, long long int pa_nResult, unsigned int pa_unErrorPos){ + char *pacEndptr; + BOOST_CHECK_EQUAL(pa_nResult, forte::core::util::strtoll(pa_acString, &pacEndptr, 10)); + BOOST_CHECK_EQUAL(pa_acString[pa_unErrorPos], *pacEndptr); + } + + //*assumes that overflow will happen when the last digit is parsed + void strtollOverflowCheck(const char* pa_acString, long long int pa_nResult){ + strtollWrongInputCheck(pa_acString, pa_nResult, strlen(pa_acString) - 1); + BOOST_CHECK_EQUAL(ERANGE, errno); + } + + BOOST_AUTO_TEST_CASE(strtoll){ + char *pacEndptr; + const unsigned int unTestData = 19; + std::string sTestData10[unTestData] ={"0", "255", "256", "65535", "65536", "2147483647", "2147483648", "4294967296", "4294967297", "9223372036854775807", + "-255", "-256", "-257", "-65536", "-65537", "-2147483648", "-4294967296", "-4294967297", "-9223372036854775808"}; + std::string sTestData16[unTestData] ={"0x0", "0xFF", "0x100", "0xFFFF", "0x10000", "0x7FFFFFFF", "0x80000000", "0x100000000", "0x100000001", "0x7FFFFFFFFFFFFFFF", + "-0xFF", "-0x100", "-0x101", "-0x10000", "-0x10001", "-0x80000000", "-0x100000000", "-0x100000001", "-0x8000000000000000" + }; + long long int sTestDataResult[unTestData] ={0, 255, 256, 65535, 65536, 2147483647, 2147483648, 4294967296, 4294967297, 9223372036854775807LL, + -255, -256, -257, -65536, -65537, -2147483648LL, -4294967296LL, -4294967297LL, -9223372036854775808LL}; + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtoll(sTestData10[i].c_str(), &pacEndptr, 10)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtoll(sTestData16[i].c_str(), &pacEndptr, 16)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + strtollOverflowCheck("9223372036854775808", 9223372036854775807LL); + strtollOverflowCheck("9223372036854775809", 9223372036854775807LL); + strtollOverflowCheck("9223372036854775810", 9223372036854775807LL); + strtollOverflowCheck("9223372036854775811", 9223372036854775807LL); + + strtollOverflowCheck("-9223372036854775809", -9223372036854775808LL); + strtollOverflowCheck("-9223372036854775810", -9223372036854775808LL); + strtollOverflowCheck("-9223372036854775811", -9223372036854775808LL); + strtollOverflowCheck("-9223372036854775812", -9223372036854775808LL); + + strtollWrongInputCheck("hansi", 0, 0); + strtollWrongInputCheck("3267x23", 3267, 4); + strtollWrongInputCheck("-74219x52", -74219, 6); + + } + + void strtoullWrongInputCheck(const char* pa_acString, unsigned long long int pa_unResult, unsigned int pa_unErrorPos){ + char *pacEndptr; + BOOST_CHECK_EQUAL(pa_unResult, forte::core::util::strtoull(pa_acString, &pacEndptr, 10)); + BOOST_CHECK_EQUAL(pa_acString[pa_unErrorPos], *pacEndptr); + } + + //*assumes that overflow will happen when the last digit is parsed + void strtoullOverflowCheck(const char* pa_acString, unsigned long long int pa_unResult){ + strtoullWrongInputCheck(pa_acString, pa_unResult, strlen(pa_acString) - 1); + BOOST_CHECK_EQUAL(ERANGE, errno); + } + + BOOST_AUTO_TEST_CASE(strtoull){ + char *pacEndptr; + const unsigned int unTestData = 11; + std::string sTestData10[unTestData] ={"0", "255", "256", "65535", "65536", "2147483647", "2147483648", "4294967296", "4294967297", "9223372036854775807", + "18446744073709551615"}; + std::string sTestData16[unTestData] ={"0x0", "0xFF", "0x100", "0xFFFF", "0x10000", "0x7FFFFFFF", "0x80000000", "0x100000000", "0x100000001", "0x7FFFFFFFFFFFFFFF", + "0xFFFFFFFFFFFFFFFF"}; + unsigned long long int sTestDataResult[unTestData] ={0, 255, 256, 65535, 65536, 2147483647, 2147483648, 4294967296, 4294967297, 9223372036854775807LL, + 18446744073709551615ULL}; + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtoull(sTestData10[i].c_str(), &pacEndptr, 10)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + for(unsigned int i = 0; i < unTestData; i++){ + BOOST_CHECK_EQUAL(sTestDataResult[i], forte::core::util::strtoull(sTestData16[i].c_str(), &pacEndptr, 16)); + BOOST_CHECK(0 != pacEndptr); + if(0 != pacEndptr){ + BOOST_CHECK_EQUAL('\0', *pacEndptr); + } + } + + strtoullOverflowCheck("18446744073709551616", 18446744073709551615ULL); + strtoullOverflowCheck("18446744073709551617", 18446744073709551615ULL); + strtoullOverflowCheck("18446744073709551618", 18446744073709551615ULL); + strtoullOverflowCheck("18446744073709551619", 18446744073709551615ULL); + strtoullOverflowCheck("18446744073709551620", 18446744073709551615ULL); + + strtoullWrongInputCheck("hansi", 0, 0); + strtoullWrongInputCheck("3267x23", 3267, 4); + strtoullWrongInputCheck("-74219x52", 0, 0); + + } +#endif + + BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/core/utils/testsingleton.cpp b/tests/core/utils/testsingleton.cpp new file mode 100644 index 000000000..91b5fe943 --- /dev/null +++ b/tests/core/utils/testsingleton.cpp @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "testsingleton.h" + +DEFINE_SINGLETON(TestSingleton); + +unsigned int TestSingleton::sm_unInstanceCount = 0; + +TestSingleton::TestSingleton(){ + sm_unInstanceCount++; + m_unSingletonID = sm_unInstanceCount; +} + +TestSingleton::~TestSingleton(){ +} + diff --git a/tests/core/utils/testsingleton.h b/tests/core/utils/testsingleton.h new file mode 100644 index 000000000..538dfe0d9 --- /dev/null +++ b/tests/core/utils/testsingleton.h @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2013 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "../../../src/core/utils/singlet.h" + +#ifndef TESTSINGLETON_H_ +#define TESTSINGLETON_H_ + +class TestSingleton{ + DECLARE_SINGLETON(TestSingleton); + + public: + + int getSingletonID() { + return m_unSingletonID; + } + + private: + static unsigned int sm_unInstanceCount; + + unsigned int m_unSingletonID; +}; + +#endif /* TESTSINGLETON_H_ */ diff --git a/tests/forte_boost_tester.cpp b/tests/forte_boost_tester.cpp new file mode 100644 index 000000000..2b274b265 --- /dev/null +++ b/tests/forte_boost_tester.cpp @@ -0,0 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2011 ACIN + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Ingo Hegny - initial API and implementation and/or initial documentation + *******************************************************************************/ +#define BOOST_TEST_MODULE FORTE_TESTS +#include + diff --git a/tests/stdfblib/CFB_TEST.cpp b/tests/stdfblib/CFB_TEST.cpp new file mode 100644 index 000000000..e904f1ce1 --- /dev/null +++ b/tests/stdfblib/CFB_TEST.cpp @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "CFB_TEST.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "CFB_TEST_gen.cpp" +#endif + +DEFINE_FIRMWARE_FB(FORTE_CFB_TEST, g_nStringIdCFB_TEST) + +const CStringDictionary::TStringId FORTE_CFB_TEST::scm_anDataInputNames[] = {g_nStringIdQI}; + +const CStringDictionary::TStringId FORTE_CFB_TEST::scm_anDataInputTypeIds[] = {g_nStringIdBOOL}; + +const CStringDictionary::TStringId FORTE_CFB_TEST::scm_anDataOutputNames[] = {g_nStringIdSR}; + +const CStringDictionary::TStringId FORTE_CFB_TEST::scm_anDataOutputTypeIds[] = {g_nStringIdBOOL}; + +const TForteInt16 FORTE_CFB_TEST::scm_anEIWithIndexes[] = {0, 2}; +const TDataIOID FORTE_CFB_TEST::scm_anEIWith[] = {0, 255, 0, 255}; +const CStringDictionary::TStringId FORTE_CFB_TEST::scm_anEventInputNames[] = {g_nStringIdSET, g_nStringIdRESET}; + +const TDataIOID FORTE_CFB_TEST::scm_anEOWith[] = {0, 255, 0, 255}; +const TForteInt16 FORTE_CFB_TEST::scm_anEOWithIndexes[] = {0, 2, -1}; +const CStringDictionary::TStringId FORTE_CFB_TEST::scm_anEventOutputNames[] = {g_nStringIdCNF, g_nStringIdCHANGED}; + +const SFBInterfaceSpec FORTE_CFB_TEST::scm_stFBInterfaceSpec = { + 2, scm_anEventInputNames, scm_anEIWith, scm_anEIWithIndexes, + 2, scm_anEventOutputNames, scm_anEOWith, scm_anEOWithIndexes, 1, scm_anDataInputNames, scm_anDataInputTypeIds, + 1, scm_anDataOutputNames, scm_anDataOutputTypeIds, + 0, 0 +}; + + +const SCFB_FBInstanceData FORTE_CFB_TEST::scm_astInternalFBs[] = { + {g_nStringIdPERMIT_OP, g_nStringIdE_PERMIT}, + {g_nStringIdE_SR, g_nStringIdE_SR}, + {g_nStringIdSET_CHANGED, g_nStringIdE_SWITCH}, + {g_nStringIdE_DEMUX_2, g_nStringIdE_DEMUX_2}, + {g_nStringIdE_MUX_2, g_nStringIdE_MUX_2}, + {g_nStringIdRESET_CHANGED, g_nStringIdE_SWITCH}, +}; + +const SCFB_FBConnectionData FORTE_CFB_TEST::scm_astEventConnections[] = { + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdSET), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_MUX_2, g_nStringIdEI1), 4}, + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdRESET), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_MUX_2, g_nStringIdEI2), 4}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_MUX_2, g_nStringIdEO), 4, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdPERMIT_OP, g_nStringIdEI), 0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSET_CHANGED, g_nStringIdEO1), 2, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdCNF), -1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSET_CHANGED, g_nStringIdEO0), 2, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SR, g_nStringIdS), 1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRESET_CHANGED, g_nStringIdEO0), 5, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdCNF), -1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRESET_CHANGED, g_nStringIdEO1), 5, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SR, g_nStringIdR), 1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdPERMIT_OP, g_nStringIdEO), 0, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_DEMUX_2, g_nStringIdEI), 3}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_DEMUX_2, g_nStringIdEO1), 3, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSET_CHANGED, g_nStringIdEI), 2}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_DEMUX_2, g_nStringIdEO2), 3, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRESET_CHANGED, g_nStringIdEI), 5}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SR, g_nStringIdEO), 1, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdCNF), -1}, +}; + +const SCFB_FBFannedOutConnectionData FORTE_CFB_TEST::scm_astFannedOutEventConnections[] = { + {10, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdCHANGED), -1}, +}; + +const SCFB_FBConnectionData FORTE_CFB_TEST::scm_astDataConnections[] = { + {GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdQI), -1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdPERMIT_OP, g_nStringIdPERMIT), 0}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_SR, g_nStringIdQ), 1, GENERATE_CONNECTION_PORT_ID_1_ARG(g_nStringIdSR), -1}, + {GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_MUX_2, g_nStringIdK), 4, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdE_DEMUX_2, g_nStringIdK), 3}, +}; + +const SCFB_FBFannedOutConnectionData FORTE_CFB_TEST::scm_astFannedOutDataConnections[] = { + {1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdSET_CHANGED, g_nStringIdG), 2}, + {1, GENERATE_CONNECTION_PORT_ID_2_ARG(g_nStringIdRESET_CHANGED, g_nStringIdG), 5}, +}; + +const SCFB_FBNData FORTE_CFB_TEST::scm_stFBNData = { + 6, scm_astInternalFBs, + 11, scm_astEventConnections, + 1, scm_astFannedOutEventConnections, + 3, scm_astDataConnections, + 2, scm_astFannedOutDataConnections, + 0, 0 +}; + + diff --git a/tests/stdfblib/CFB_TEST.h b/tests/stdfblib/CFB_TEST.h new file mode 100644 index 000000000..fa42f699f --- /dev/null +++ b/tests/stdfblib/CFB_TEST.h @@ -0,0 +1,70 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _CFB_TEST_H_ +#define _CFB_TEST_H_ + +#include +#include +#include + +class FORTE_CFB_TEST: public CCompositeFB{ + DECLARE_FIRMWARE_FB(FORTE_CFB_TEST) + +private: + static const CStringDictionary::TStringId scm_anDataInputNames[]; + static const CStringDictionary::TStringId scm_anDataInputTypeIds[]; + CIEC_BOOL &QI() { + return *static_cast(getDI(0)); + }; + + static const CStringDictionary::TStringId scm_anDataOutputNames[]; + static const CStringDictionary::TStringId scm_anDataOutputTypeIds[]; + CIEC_BOOL &SR() { + return *static_cast(getDO(0)); + }; + + static const TEventID scm_nEventSETID = 0; + static const TEventID scm_nEventRESETID = 1; + static const TForteInt16 scm_anEIWithIndexes[]; + static const TDataIOID scm_anEIWith[]; + static const CStringDictionary::TStringId scm_anEventInputNames[]; + + static const TEventID scm_nEventCNFID = 0; + static const TEventID scm_nEventCHANGEDID = 1; + static const TForteInt16 scm_anEOWithIndexes[]; + static const TDataIOID scm_anEOWith[]; + static const CStringDictionary::TStringId scm_anEventOutputNames[]; + + static const SFBInterfaceSpec scm_stFBInterfaceSpec; + + FORTE_FB_DATA_ARRAY(2, 1, 1, 0); + + static const SCFB_FBInstanceData scm_astInternalFBs[]; + + static const SCFB_FBConnectionData scm_astEventConnections[]; + + static const SCFB_FBFannedOutConnectionData scm_astFannedOutEventConnections[]; + + static const SCFB_FBConnectionData scm_astDataConnections[]; + + static const SCFB_FBFannedOutConnectionData scm_astFannedOutDataConnections[]; + static const SCFB_FBNData scm_stFBNData; + +public: + COMPOSITE_FUNCTION_BLOCK_CTOR(FORTE_CFB_TEST){ + }; + + virtual ~FORTE_CFB_TEST(){}; + +}; + +#endif //close the ifdef sequence from the beginning of the file + diff --git a/tests/stdfblib/CFB_TEST_tester.cpp b/tests/stdfblib/CFB_TEST_tester.cpp new file mode 100644 index 000000000..449e42736 --- /dev/null +++ b/tests/stdfblib/CFB_TEST_tester.cpp @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "CFB_TEST_tester.h" +#include + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "CFB_TEST_tester_gen.cpp" +#endif + +DEFINE_FB_TESTER(CFB_TEST_tester, g_nStringIdCFB_TEST) + +CFB_TEST_tester::CFB_TEST_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + + SETUP_INPUTDATA(&m_oIn_QI); + SETUP_OUTPUTDATA(&m_oOut_SR); +} + +void CFB_TEST_tester::executeAllTests(){ + evaluateTestResult(inhibitTest(), "Inhibit Test"); + evaluateTestResult(setTest(), "set Test"); + evaluateTestResult(resetTest(), "reset Test"); + evaluateTestResult(toggleTest(), "toggle Test"); +} + +bool CFB_TEST_tester::inhibitTest(){ + bool bResult = true; + + m_oIn_QI = false; + + for(unsigned int i = 0; i < 100; ++i){ + triggerEvent(0); + + if(!eventChainEmpty()){ + bResult = false; + } + + if(false != m_oOut_SR){ + bResult = false; + } + + triggerEvent(1); + + if(!eventChainEmpty()){ + bResult = false; + } + + if(false != m_oOut_SR){ + bResult = false; + } + } + + return bResult; +} + +bool CFB_TEST_tester::setTest(){ + bool bResult = true; + + m_oIn_QI = true; + + triggerEvent(0); + + if(!checkBothOutputEvents()){ + return false; + } + + if(false == m_oOut_SR){ + return false; + } + + for(unsigned int i = 0; i < 100; ++i){ + triggerEvent(0); + if(!checkForSingleOutputEventOccurence(0)){ + bResult = false; + break; + } + + if(false == m_oOut_SR){ + bResult = false; + break; + } + } + + return bResult; +} + +bool CFB_TEST_tester::resetTest(){ + bool bResult = true; + + m_oIn_QI = true; + + triggerEvent(0); + clearEventChain(); + + triggerEvent(1); + if(!checkBothOutputEvents()){ + return false; + } + + if(true == m_oOut_SR){ + return false; + } + + for(unsigned int i = 0; i < 100; ++i){ + triggerEvent(1); + if(!checkForSingleOutputEventOccurence(0)){ + bResult = false; + break; + } + + if(true == m_oOut_SR){ + bResult = false; + break; + } + } + + return bResult; +} + +bool CFB_TEST_tester::toggleTest(){ + bool bResult = true; + + m_oIn_QI = true; + + for(int i = 0; i < 1000; ++i){ + triggerEvent(0); + if(!checkBothOutputEvents()){ + bResult = false; + break; + } + + if(true != m_oOut_SR){ + bResult = false; + break; + } + + triggerEvent(1); + if(!checkBothOutputEvents()){ + bResult = false; + break; + } + + if(false != m_oOut_SR){ + bResult = false; + break; + } + } + + return bResult; +} + +bool CFB_TEST_tester::checkBothOutputEvents(){ + bool bResult = true; + + if(0 != pullFirstChainEventID()){ + bResult = false; + } + + if(1 != pullFirstChainEventID()){ + bResult = false; + } + + if(!eventChainEmpty()){ + bResult = false; + } + + return bResult; +} diff --git a/tests/stdfblib/CFB_TEST_tester.h b/tests/stdfblib/CFB_TEST_tester.h new file mode 100644 index 000000000..8da7b60e0 --- /dev/null +++ b/tests/stdfblib/CFB_TEST_tester.h @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _CFB_TEST_TESTER_H_ +#define _CFB_TEST_TESTER_H_ + +#include "../core/fbtests/fbtester.h" +#include +#include "CFB_TEST.h" + + + +class CFB_TEST_tester : public CFBTester{ + DECLARE_FB_TESTER(CFB_TEST_tester); + public: + + private: + CFB_TEST_tester(CResource *m_poTestResource); + virtual void executeAllTests(); + + bool inhibitTest(); + bool setTest(); + bool resetTest(); + bool toggleTest(); + + bool checkBothOutputEvents(); + + CIEC_BOOL m_oIn_QI; + CIEC_BOOL m_oOut_SR; +}; + +/***********************************************************************************/ + +#endif /* _CFB_TEST_TESTER_H_ */ diff --git a/tests/stdfblib/CMakeLists.txt b/tests/stdfblib/CMakeLists.txt new file mode 100644 index 000000000..ae971e251 --- /dev/null +++ b/tests/stdfblib/CMakeLists.txt @@ -0,0 +1,20 @@ +#******************************************************************************* +# * Copyright (c) 2014 fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ +SET(SOURCE_GROUP ${SOURCE_GROUP}\\fblib) + +add_subdirectory(events) + + +forte_test_add_sourcefile_cpp(../../src/stdfblib/timedfb.cpp) + + +forte_test_add_sourcefile_cpp(CFB_TEST.cpp) +forte_test_add_sourcefile_cpp(CFB_TEST_tester.cpp) \ No newline at end of file diff --git a/tests/stdfblib/events/CMakeLists.txt b/tests/stdfblib/events/CMakeLists.txt new file mode 100644 index 000000000..8ddbf8e2c --- /dev/null +++ b/tests/stdfblib/events/CMakeLists.txt @@ -0,0 +1,34 @@ +#******************************************************************************* +# * Copyright (c) 2011, 2014 ACIN, fortiss GmbH +# * All rights reserved. This program and the accompanying materials +# * are made available under the terms of the Eclipse Public License v1.0 +# * which accompanies this distribution, and is available at +# * http://www.eclipse.org/legal/epl-v10.html +# * +# * Contributors: +# * Alois Zoitl - initial API and implementation and/or initial documentation +# *******************************************************************************/ + +############################################################################# +# Tests for the standard Event FBs +############################################################################# +forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +SET(SOURCE_GROUP ${SOURCE_GROUP}\\events) + +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/E_DELAY.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/E_F_TRIG.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/E_PERMIT.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/E_R_TRIG.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/E_SR.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/E_SWITCH.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/E_SELECT.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/GEN_E_DEMUX.cpp) +forte_test_add_sourcefile_cpp(../../../src/stdfblib/events/GEN_E_MUX.cpp) + +forte_test_add_sourcefile_cpp(E_DELAY_tester.cpp) +forte_test_add_sourcefile_cpp(E_F_TRIG_tester.cpp) +forte_test_add_sourcefile_cpp(E_PERMIT_tester.cpp) +forte_test_add_sourcefile_cpp(E_R_TRIG_tester.cpp) +forte_test_add_sourcefile_cpp(E_SR_tester.cpp) +forte_test_add_sourcefile_cpp(E_SELECT_tester.cpp) +forte_test_add_sourcefile_cpp(E_SWITCH_tester.cpp) diff --git a/tests/stdfblib/events/E_DELAY_tester.cpp b/tests/stdfblib/events/E_DELAY_tester.cpp new file mode 100644 index 000000000..497ff132f --- /dev/null +++ b/tests/stdfblib/events/E_DELAY_tester.cpp @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_DELAY_tester.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_DELAY_tester_gen.cpp" +#endif + +#ifdef WIN32 + #include + #define usleep(x) Sleep((x)/1000) +#else + #include +#endif + + +DEFINE_FB_TESTER(E_DELAY_tester, g_nStringIdE_DELAY) + +E_DELAY_tester::E_DELAY_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + + SETUP_INPUTDATA(&mDT); +} + +void E_DELAY_tester::executeAllTests(){ + evaluateTestResult(testCase_NormalDelay(), "Normal Delay"); + evaluateTestResult(testCase_AbortedDelay(), "Aborted Delay"); + evaluateTestResult(testCase_MultipleStarts(), "Multiple Starts"); +} + +bool E_DELAY_tester::testCase_NormalDelay(){ + mDT.setFromMiliSeconds(500); + triggerEvent(0); + usleep(500000); + return checkForSingleOutputEventOccurence(0); +} + +bool E_DELAY_tester::testCase_AbortedDelay(){ + bool retVal = true; + mDT.setFromMiliSeconds(1000); + triggerEvent(0); + if(!eventChainEmpty()){ + retVal = false; + } + triggerEvent(1); + if(!eventChainEmpty()){ + retVal = false; + } + usleep(1000000); + if(!eventChainEmpty()){ + retVal = false; + } + return retVal; +} + +bool E_DELAY_tester::testCase_MultipleStarts(){ + bool retVal = true; + mDT.setFromMiliSeconds(200); + triggerEvent(0); + + usleep(50000); + if(!eventChainEmpty()){ + retVal = false; + } + triggerEvent(0); + + usleep(150000); + if(!checkForSingleOutputEventOccurence(0)){ + retVal = false; + } + + usleep(50000); + if(!eventChainEmpty()){ + retVal = false; + } + + return retVal; +} diff --git a/tests/stdfblib/events/E_DELAY_tester.h b/tests/stdfblib/events/E_DELAY_tester.h new file mode 100644 index 000000000..d03f8e414 --- /dev/null +++ b/tests/stdfblib/events/E_DELAY_tester.h @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_DELAY_TESTER_H_ +#define _E_DELAY_TESTER_H_ + +#include "../../core/fbtests/fbtester.h" +#include +#include + +/***********************************************************************************/ +/***********************************************************************************/ + +class E_DELAY_tester : public CFBTester{ + DECLARE_FB_TESTER(E_DELAY_tester); + + public: + E_DELAY_tester(CResource *m_poTestResource); + + private: + virtual void executeAllTests(); + + bool testCase_NormalDelay(); + bool testCase_AbortedDelay(); + bool testCase_MultipleStarts(); + + + CIEC_TIME mDT; //DT data input +}; + +/***********************************************************************************/ +/***********************************************************************************/ + +#endif /* _E_DELAY_TESTER_H_ */ diff --git a/tests/stdfblib/events/E_F_TRIG_tester.cpp b/tests/stdfblib/events/E_F_TRIG_tester.cpp new file mode 100644 index 000000000..414a2f953 --- /dev/null +++ b/tests/stdfblib/events/E_F_TRIG_tester.cpp @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_F_TRIG_tester.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_F_TRIG_tester_gen.cpp" +#endif + +DEFINE_FB_TESTER(E_F_TRIG_tester, g_nStringIdE_F_TRIG) + +E_F_TRIG_tester::E_F_TRIG_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + + SETUP_INPUTDATA(&m_oIn_QI); +} + +void E_F_TRIG_tester::executeAllTests(){ + evaluateTestResult(testCase_RaisingEdge(), "Raising Edge"); + evaluateTestResult(testCase_FallingEdge(), "Falling Edge"); + evaluateTestResult(testCase_StableHigh(), "Stable High"); + evaluateTestResult(testCase_StableLow(), "Stable Low"); +} + +bool E_F_TRIG_tester::testCase_RaisingEdge(){ + bool bResult = true; + + m_oIn_QI = true; + triggerEvent(0); + + if(!eventChainEmpty()){ + bResult = false; + } + + return bResult; +} + +bool E_F_TRIG_tester::testCase_FallingEdge(){ + m_oIn_QI = true; + triggerEvent(0); + + m_oIn_QI = false; + triggerEvent(0); + + return checkForSingleOutputEventOccurence(0); +} + +bool E_F_TRIG_tester::testCase_StableHigh(){ + bool bResult = true; + + m_oIn_QI = true; + triggerEvent(0); + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(0); + if(!eventChainEmpty()){ + bResult = false; + break; + } + } + + return bResult; +} + +bool E_F_TRIG_tester::testCase_StableLow(){ + bool bResult = true; + + m_oIn_QI = false; + triggerEvent(0); //Just in case that the QI has been true first handle a potential falling edge + pullFirstChainEventID(); + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(0); + if(!eventChainEmpty()){ + bResult = false; + break; + } + } + + return bResult; +} + diff --git a/tests/stdfblib/events/E_F_TRIG_tester.h b/tests/stdfblib/events/E_F_TRIG_tester.h new file mode 100644 index 000000000..d1dfff5fc --- /dev/null +++ b/tests/stdfblib/events/E_F_TRIG_tester.h @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_F_TRIG_TESTER_H_ +#define _E_F_TRIG_TESTER_H_ + +#include "../../core/fbtests/fbtester.h" +#include + +/***********************************************************************************/ +/***********************************************************************************/ + +class E_F_TRIG_tester : public CFBTester{ + DECLARE_FB_TESTER(E_F_TRIG_tester); + + public: + E_F_TRIG_tester(CResource *m_poTestResource); + + private: + virtual void executeAllTests(); + + bool testCase_RaisingEdge(); + bool testCase_FallingEdge(); + bool testCase_StableHigh(); + bool testCase_StableLow(); + + CIEC_BOOL m_oIn_QI; //DATA INPUT +}; + +/***********************************************************************************/ +/***********************************************************************************/ + +#endif /* _E_SR_TESTER_H_ */ diff --git a/tests/stdfblib/events/E_PERMIT_tester.cpp b/tests/stdfblib/events/E_PERMIT_tester.cpp new file mode 100644 index 000000000..eeb2ed042 --- /dev/null +++ b/tests/stdfblib/events/E_PERMIT_tester.cpp @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_PERMIT_tester.h" + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_PERMIT_tester_gen.cpp" +#endif + +DEFINE_FB_TESTER(E_PERMIT_tester, g_nStringIdE_PERMIT) + +E_PERMIT_tester::E_PERMIT_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + + SETUP_INPUTDATA(&m_oIn_PERMIT); +} + +void E_PERMIT_tester::executeAllTests(){ + evaluateTestResult(testCase_Permit(), "Permit"); + evaluateTestResult(testCase_DontPermit(), "DontPermit"); +} + +/***********************************************************************************/ + +bool E_PERMIT_tester::testCase_Permit(){ + /* prepare inputparameters */ + m_oIn_PERMIT = true; + + /* trigger the inputevent */ + triggerEvent(0); + + return checkForSingleOutputEventOccurence(0); +} + +bool E_PERMIT_tester::testCase_DontPermit(){ + bool bTestResult = true; + + /* prepare inputparameters */ + m_oIn_PERMIT = false; + + /* trigger the inputevent */ + triggerEvent(0); + + /* verify if there is no output event (testspecification)*/ + if(!eventChainEmpty()) + bTestResult = false; + + return bTestResult; +} diff --git a/tests/stdfblib/events/E_PERMIT_tester.h b/tests/stdfblib/events/E_PERMIT_tester.h new file mode 100644 index 000000000..74e5cbe83 --- /dev/null +++ b/tests/stdfblib/events/E_PERMIT_tester.h @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_PERMIT_TESTER_H_ +#define _E_PERMIT_TESTER_H_ + +#include "../../core/fbtests/fbtester.h" +#include +#include + + + +class E_PERMIT_tester : public CFBTester{ + DECLARE_FB_TESTER(E_PERMIT_tester); + public: + + private: + E_PERMIT_tester(CResource *m_poTestResource); + virtual void executeAllTests(); + + bool testCase_Permit(); + bool testCase_DontPermit(); + + CIEC_BOOL m_oIn_PERMIT; //DATA INPUT +}; + +/***********************************************************************************/ + +#endif /* _E_PERMIT_TESTER_H_ */ diff --git a/tests/stdfblib/events/E_R_TRIG_tester.cpp b/tests/stdfblib/events/E_R_TRIG_tester.cpp new file mode 100644 index 000000000..e3a22caea --- /dev/null +++ b/tests/stdfblib/events/E_R_TRIG_tester.cpp @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_R_TRIG_tester.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_R_TRIG_tester_gen.cpp" +#endif + +DEFINE_FB_TESTER(E_R_TRIG_tester, g_nStringIdE_R_TRIG) + +E_R_TRIG_tester::E_R_TRIG_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + + SETUP_INPUTDATA(&m_oIn_QI); +} + +void E_R_TRIG_tester::executeAllTests(){ + evaluateTestResult(testCase_RaisingEdge(), "Raising Edge"); + evaluateTestResult(testCase_FallingEdge(), "Falling Edge"); + evaluateTestResult(testCase_StableHigh(), "Stable High"); + evaluateTestResult(testCase_StableLow(), "Stable Low"); +} + +bool E_R_TRIG_tester::testCase_RaisingEdge(){ + m_oIn_QI = true; + triggerEvent(0); + + return checkForSingleOutputEventOccurence(0); +} + +bool E_R_TRIG_tester::testCase_FallingEdge(){ + bool bResult = true; + + m_oIn_QI = true; + triggerEvent(0); + + m_oIn_QI = false; + triggerEvent(0); + if(!eventChainEmpty()){ + bResult = false; + } + return bResult; +} + +bool E_R_TRIG_tester::testCase_StableHigh(){ + bool bResult = true; + + m_oIn_QI = true; + triggerEvent(0); + pullFirstChainEventID(); + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(0); + if(!eventChainEmpty()){ + bResult = false; + break; + } + } + + return bResult; +} + +bool E_R_TRIG_tester::testCase_StableLow(){ + bool bResult = true; + + m_oIn_QI = false; + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(0); + if(!eventChainEmpty()){ + bResult = false; + break; + } + } + + return bResult; +} + diff --git a/tests/stdfblib/events/E_R_TRIG_tester.h b/tests/stdfblib/events/E_R_TRIG_tester.h new file mode 100644 index 000000000..bd58390f9 --- /dev/null +++ b/tests/stdfblib/events/E_R_TRIG_tester.h @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_R_TRIG_TESTER_H_ +#define _E_R_TRIG_TESTER_H_ + +#include "../../core/fbtests/fbtester.h" +#include + +/***********************************************************************************/ +/***********************************************************************************/ + +class E_R_TRIG_tester : public CFBTester{ + DECLARE_FB_TESTER(E_R_TRIG_tester); + + public: + E_R_TRIG_tester(CResource *m_poTestResource); + + private: + virtual void executeAllTests(); + + bool testCase_RaisingEdge(); + bool testCase_FallingEdge(); + bool testCase_StableHigh(); + bool testCase_StableLow(); + + CIEC_BOOL m_oIn_QI; //DATA INPUT +}; + +/***********************************************************************************/ +/***********************************************************************************/ + +#endif /* _E_SR_TESTER_H_ */ diff --git a/tests/stdfblib/events/E_SELECT_tester.cpp b/tests/stdfblib/events/E_SELECT_tester.cpp new file mode 100644 index 000000000..b0da80f62 --- /dev/null +++ b/tests/stdfblib/events/E_SELECT_tester.cpp @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_SELECT_tester.h" + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_SELECT_tester_gen.cpp" +#endif + +DEFINE_FB_TESTER(E_SELECT_tester, g_nStringIdE_SELECT) + +E_SELECT_tester::E_SELECT_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + SETUP_INPUTDATA(&m_oIn_G); +} + +void E_SELECT_tester::executeAllTests(){ + evaluateTestResult(testCase_SelectEI0(), "Single EI0"); + evaluateTestResult(testCase_SelectEI1(), "Single EI1"); + evaluateTestResult(testCase_MultipleSelectEI0(), "Multiple EI0"); + evaluateTestResult(testCase_MultipleSelectEI1(), "Multiple EI1"); + evaluateTestResult(testCase_Alternate(), "Alternate"); +} + +/***********************************************************************************/ +bool E_SELECT_tester::testCase_SelectEI0(){ + bool bRetVal = true; + m_oIn_G = false; + triggerEvent(0); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + } + triggerEvent(1); + if(!eventChainEmpty()) + bRetVal = false; + return bRetVal; +} + +bool E_SELECT_tester::testCase_SelectEI1(){ + bool bRetVal = true; + m_oIn_G = true; + triggerEvent(1); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + } + triggerEvent(0); + if(!eventChainEmpty()) + bRetVal = false; + return bRetVal; +} + +bool E_SELECT_tester::testCase_MultipleSelectEI0(){ + bool bRetVal = true; + m_oIn_G = false; + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(0); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + break; + } + } + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(0); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + break; + } + triggerEvent(1); + if(!eventChainEmpty()){ + bRetVal = false; + break; + } + } + return bRetVal; +} + +bool E_SELECT_tester::testCase_MultipleSelectEI1(){ + bool bRetVal = true; + m_oIn_G = true; + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(1); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + break; + } + } + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent(1); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + break; + } + triggerEvent(0); + if(!eventChainEmpty()){ + bRetVal = false; + break; + } + } + return bRetVal; +} + +bool E_SELECT_tester::testCase_Alternate(){ + bool bRetVal = true; + + for(unsigned int i = 0; i < 1000; ++i){ + m_oIn_G = !m_oIn_G; + triggerEvent((m_oIn_G) ? 1 : 0); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + break; + } + } + + for(unsigned int i = 0; i < 1000; i++){ + triggerEvent((m_oIn_G) ? 1 : 0); + if(!checkForSingleOutputEventOccurence(0)){ + bRetVal = false; + break; + } + triggerEvent((m_oIn_G) ? 0 : 1); + if(!eventChainEmpty()){ + bRetVal = false; + break; + } + } + + return bRetVal; +} diff --git a/tests/stdfblib/events/E_SELECT_tester.h b/tests/stdfblib/events/E_SELECT_tester.h new file mode 100644 index 000000000..35fb82517 --- /dev/null +++ b/tests/stdfblib/events/E_SELECT_tester.h @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SELECT_TESTER_H_ +#define _E_SELECT_TESTER_H_ + +#include "../../core/fbtests/fbtester.h" +#include +#include + + + +class E_SELECT_tester : public CFBTester{ + DECLARE_FB_TESTER(E_SELECT_tester); + public: + + private: + E_SELECT_tester(CResource *m_poTestResource); + virtual void executeAllTests(); + + bool testCase_SelectEI0(); + bool testCase_SelectEI1(); + bool testCase_MultipleSelectEI0(); + bool testCase_MultipleSelectEI1(); + bool testCase_Alternate(); + + CIEC_BOOL m_oIn_G; //DATA INPUT +}; + +/***********************************************************************************/ + +#endif /* _E_SELECT_TESTER_H_ */ diff --git a/tests/stdfblib/events/E_SR_tester.cpp b/tests/stdfblib/events/E_SR_tester.cpp new file mode 100644 index 000000000..8bc594803 --- /dev/null +++ b/tests/stdfblib/events/E_SR_tester.cpp @@ -0,0 +1,103 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_SR_tester.h" +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_SR_tester_gen.cpp" +#endif + +DEFINE_FB_TESTER(E_SR_tester, g_nStringIdE_SR) + +E_SR_tester::E_SR_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + SETUP_OUTPUTDATA(&m_oOut_Q); +} + +void E_SR_tester::executeAllTests(){ + evaluateTestResult(testCase_EventS(), "EventS"); + evaluateTestResult(testCase_EventR(), "EventR"); + evaluateTestResult(testCase_Toggle(), "Toggle"); +} + +bool E_SR_tester::testCase_EventS(){ + bool bResult = true; + + //Send event + triggerEvent(0); + + if(!checkStateChange(true)) + bResult = false; + + for(unsigned int i = 0; i < 100; ++i){ + triggerEvent(0); + if(!eventChainEmpty()){ + bResult = false; + break; + } + if(m_oOut_Q != true){ + bResult = false; + break; + } + } + + return bResult; +} + +bool E_SR_tester::testCase_EventR(){ + bool bResult = true; + + //Send event + triggerEvent(1); + + //Test correct order of outgoing events + if(!checkStateChange(false)) + bResult = false; + + for(unsigned int i = 0; i < 100; ++i){ + triggerEvent(1); + if(!eventChainEmpty()){ + bResult = false; + break; + } + if(m_oOut_Q != false){ + bResult = false; + break; + } + } + + return bResult; +} + +bool E_SR_tester::testCase_Toggle(){ + bool bResult = true; + + for(unsigned int i = 0; i < 100; ++i){ + triggerEvent(0); + if(!checkStateChange(true)){ + bResult = false; + break; + } + + triggerEvent(1); + checkStateChange(false); + } + + return bResult; +} + +bool E_SR_tester::checkStateChange(bool bTargetState){ + bool bResult = checkForSingleOutputEventOccurence(0); + + //verify data output + if(m_oOut_Q != bTargetState) + bResult = false; + + return bResult; +} diff --git a/tests/stdfblib/events/E_SR_tester.h b/tests/stdfblib/events/E_SR_tester.h new file mode 100644 index 000000000..381789b9b --- /dev/null +++ b/tests/stdfblib/events/E_SR_tester.h @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2011 - 2014 ACIN, fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SR_TESTER_H_ +#define _E_SR_TESTER_H_ + +#include "../../core/fbtests/fbtester.h" +#include +#include + +/***********************************************************************************/ +/***********************************************************************************/ + +class E_SR_tester : public CFBTester{ + DECLARE_FB_TESTER(E_SR_tester); + + public: + E_SR_tester(CResource *m_poTestResource); + + private: + virtual void executeAllTests(); + + bool testCase_EventS(); + bool testCase_EventR(); + bool testCase_Toggle(); + + /*\brief Check if the E_SR changed to the given target state + * + */ + bool checkStateChange(bool bTargetState); + + CIEC_BOOL m_oOut_Q; //DATA OUTPUT +}; + +/***********************************************************************************/ +/***********************************************************************************/ + +#endif /* _E_SR_TESTER_H_ */ diff --git a/tests/stdfblib/events/E_SWITCH_tester.cpp b/tests/stdfblib/events/E_SWITCH_tester.cpp new file mode 100644 index 000000000..5fdd20aad --- /dev/null +++ b/tests/stdfblib/events/E_SWITCH_tester.cpp @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#include "E_SWITCH_tester.h" + +#ifdef FORTE_ENABLE_GENERATED_SOURCE_CPP +#include "E_SWITCH_tester_gen.cpp" +#endif + +DEFINE_FB_TESTER(E_SWITCH_tester, g_nStringIdE_SWITCH) + +E_SWITCH_tester::E_SWITCH_tester(CResource *m_poTestResource) : + CFBTester(m_poTestResource){ + + SETUP_INPUTDATA(&m_oIn_G); +} + +void E_SWITCH_tester::executeAllTests(){ + evaluateTestResult(testCase_SingelE0(), "Single E0"); + evaluateTestResult(testCase_SingleE1(), "Single E1"); + evaluateTestResult(testCase_MultipleE0(), "Multiple E0"); + evaluateTestResult(testCase_MultipleE1(), "Multiple E1"); + evaluateTestResult(testCase_Alternate(), "Alternate"); +} + +/***********************************************************************************/ +bool E_SWITCH_tester::testCase_SingelE0(){ + m_oIn_G = false; + triggerEvent(0); + return checkForSingleOutputEventOccurence(0); +} + +bool E_SWITCH_tester::testCase_SingleE1(){ + m_oIn_G = true; + triggerEvent(0); + return checkForSingleOutputEventOccurence(1); +} + +bool E_SWITCH_tester::testCase_MultipleE0(){ + bool bRetval = true; + + m_oIn_G = false; + + for(unsigned int i = 0; i < 1000; ++i){ + triggerEvent(0); + if(!checkForSingleOutputEventOccurence(0)){ + bRetval = false; + break; + } + } + return bRetval; +} + +bool E_SWITCH_tester::testCase_MultipleE1(){ + bool bRetval = true; + + m_oIn_G = true; + + for(unsigned int i = 0; i < 1000; ++i){ + triggerEvent(0); + if(!checkForSingleOutputEventOccurence(1)){ + bRetval = false; + break; + } + } + return bRetval; +} + +bool E_SWITCH_tester::testCase_Alternate(){ + bool bRetval = true; + + for(unsigned int i = 0; i < 1000; ++i){ + m_oIn_G = !m_oIn_G; + triggerEvent(0); + if(!checkForSingleOutputEventOccurence((m_oIn_G) ? 1 : 0)){ + bRetval = false; + break; + } + } + return bRetval; +} diff --git a/tests/stdfblib/events/E_SWITCH_tester.h b/tests/stdfblib/events/E_SWITCH_tester.h new file mode 100644 index 000000000..b0e7542fc --- /dev/null +++ b/tests/stdfblib/events/E_SWITCH_tester.h @@ -0,0 +1,39 @@ +/******************************************************************************* + * Copyright (c) 2014 fortiss GmbH + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alois Zoitl - initial API and implementation and/or initial documentation + *******************************************************************************/ +#ifndef _E_SWITCH_TESTER_H_ +#define _E_SWITCH_TESTER_H_ + +#include "../../core/fbtests/fbtester.h" +#include +#include + + + +class E_SWITCH_tester : public CFBTester{ + DECLARE_FB_TESTER(E_SWITCH_tester); + public: + + private: + E_SWITCH_tester(CResource *m_poTestResource); + virtual void executeAllTests(); + + bool testCase_SingelE0(); + bool testCase_SingleE1(); + bool testCase_MultipleE0(); + bool testCase_MultipleE1(); + bool testCase_Alternate(); + + CIEC_BOOL m_oIn_G; //DATA INPUT +}; + +/***********************************************************************************/ + +#endif /* _E_SWITCH_TESTER_H_ */