andrej@1511: #!/usr/bin/env python
andrej@1511: # -*- coding: utf-8 -*-
andrej@1511: 
andrej@1511: # This file is part of Beremiz, a Integrated Development Environment for
andrej@1511: # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
andrej@1511: #
andrej@1511: # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
andrej@1680: # Copyright (C) 2017: Andrey Skvortsov
andrej@1511: #
andrej@1511: # See COPYING file for copyrights details.
andrej@1511: #
andrej@1511: # This program is free software; you can redistribute it and/or
andrej@1511: # modify it under the terms of the GNU General Public License
andrej@1511: # as published by the Free Software Foundation; either version 2
andrej@1511: # of the License, or (at your option) any later version.
andrej@1511: #
andrej@1511: # This program is distributed in the hope that it will be useful,
andrej@1511: # but WITHOUT ANY WARRANTY; without even the implied warranty of
andrej@1511: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
andrej@1511: # GNU General Public License for more details.
andrej@1511: #
andrej@1511: # You should have received a copy of the GNU General Public License
andrej@1511: # along with this program; if not, write to the Free Software
andrej@1511: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
andrej@1511: 
andrej@1511: 
andrej@1881: from __future__ import absolute_import
andrej@1850: from os.path import join
andrej@1680: import util.paths as paths
andrej@1762: from util.TranslationCatalogs import NoTranslate
andrej@1680: sd = paths.AbsDir(__file__)
Edouard@1390: 
Edouard@1390: # Override gettext _ in this module
Edouard@1390: # since we just want string to be added to dictionnary
Edouard@1390: # but translation should happen here
andrej@1762: _ = NoTranslate
Edouard@1390: 
andrej@1740: LANGUAGES = ["IL", "ST", "FBD", "LD", "SFC"]
Edouard@1390: 
andrej@1739: LOCATIONDATATYPES = {"X": ["BOOL"],
andrej@1739:                      "B": ["SINT", "USINT", "BYTE", "STRING"],
andrej@1739:                      "W": ["INT", "UINT", "WORD", "WSTRING"],
andrej@1739:                      "D": ["DINT", "UDINT", "REAL", "DWORD"],
andrej@1739:                      "L": ["LINT", "ULINT", "LREAL", "LWORD"]}
Edouard@1390: 
andrej@1782: # -------------------------------------------------------------------------------
Edouard@1390: #                        Function Block Types definitions
andrej@1782: # -------------------------------------------------------------------------------
Edouard@1390: 
andrej@1740: StdTC6Libs = [(_("Standard function blocks"),   join(sd, "Standard_Function_Blocks.xml")),
andrej@1740:               (_("Additional function blocks"), join(sd, "Additional_Function_Blocks.xml"))]
Edouard@1390: 
andrej@1740: StdFuncsCSV = join(sd, "iec_std.csv")
Edouard@1390: 
andrej@1736: 
Edouard@1390: def GetBlockInfos(pou):
Edouard@1390:     infos = pou.getblockInfos()
Edouard@1390:     infos["inputs"] = [
Edouard@1390:         (var_name, var_type, "rising")
Edouard@1390:         if var_name in ["CU", "CD"]
Edouard@1390:         else (var_name, var_type, var_modifier)
Edouard@1390:         for var_name, var_type, var_modifier in infos["inputs"]]
Edouard@1390:     return infos
Edouard@1390: 
andrej@1782: # -------------------------------------------------------------------------------
Edouard@1390: #                           Data Types definitions
andrej@1782: # -------------------------------------------------------------------------------
Edouard@1390: 
andrej@1749: 
andrej@1837: #: Ordored list of common data types defined in the IEC 61131-3
andrej@1837: #: Each type is associated to his direct parent type. It defines then a hierarchy
andrej@1837: #: between type that permits to make a comparison of two types
andrej@1837: 
Edouard@1390: TypeHierarchy_list = [
Edouard@1390:     ("ANY", None),
Edouard@1390:     ("ANY_DERIVED", "ANY"),
Edouard@1390:     ("ANY_ELEMENTARY", "ANY"),
Edouard@1390:     ("ANY_MAGNITUDE", "ANY_ELEMENTARY"),
Edouard@1390:     ("ANY_BIT", "ANY_ELEMENTARY"),
Edouard@1390:     ("ANY_NBIT", "ANY_BIT"),
Edouard@1390:     ("ANY_STRING", "ANY_ELEMENTARY"),
Edouard@1390:     ("ANY_DATE", "ANY_ELEMENTARY"),
Edouard@1390:     ("ANY_NUM", "ANY_MAGNITUDE"),
Edouard@1390:     ("ANY_REAL", "ANY_NUM"),
Edouard@1390:     ("ANY_INT", "ANY_NUM"),
Edouard@1390:     ("ANY_SINT", "ANY_INT"),
Edouard@1390:     ("ANY_UINT", "ANY_INT"),
Edouard@1390:     ("BOOL", "ANY_BIT"),
Edouard@1390:     ("SINT", "ANY_SINT"),
Edouard@1390:     ("INT", "ANY_SINT"),
Edouard@1390:     ("DINT", "ANY_SINT"),
Edouard@1390:     ("LINT", "ANY_SINT"),
Edouard@1390:     ("USINT", "ANY_UINT"),
Edouard@1390:     ("UINT", "ANY_UINT"),
Edouard@1390:     ("UDINT", "ANY_UINT"),
Edouard@1390:     ("ULINT", "ANY_UINT"),
Edouard@1390:     ("REAL", "ANY_REAL"),
Edouard@1390:     ("LREAL", "ANY_REAL"),
Edouard@1390:     ("TIME", "ANY_MAGNITUDE"),
Edouard@1390:     ("DATE", "ANY_DATE"),
Edouard@1390:     ("TOD", "ANY_DATE"),
Edouard@1390:     ("DT", "ANY_DATE"),
Edouard@1390:     ("STRING", "ANY_STRING"),
Edouard@1390:     ("BYTE", "ANY_NBIT"),
Edouard@1390:     ("WORD", "ANY_NBIT"),
Edouard@1390:     ("DWORD", "ANY_NBIT"),
Edouard@1390:     ("LWORD", "ANY_NBIT")
andrej@1782:     # ("WSTRING", "ANY_STRING") # TODO
Edouard@1390: ]
Edouard@1390: 
Edouard@1412: DefaultType = "DINT"
Edouard@1412: 
Edouard@1390: DataTypeRange_list = [
andrej@1740:     ("SINT",  (-2**7,  2**7 - 1)),
andrej@1740:     ("INT",   (-2**15, 2**15 - 1)),
andrej@1740:     ("DINT",  (-2**31, 2**31 - 1)),
andrej@1802:     ("LINT",  (-2**63, 2**63 - 1)),
andrej@1740:     ("USINT", (0,      2**8 - 1)),
andrej@1740:     ("UINT",  (0,      2**16 - 1)),
andrej@1798:     ("UDINT", (0,      2**32 - 1)),
andrej@1802:     ("ULINT", (0,      2**64 - 1))
Edouard@1390: ]
Edouard@1390: 
Edouard@1390: ANY_TO_ANY_FILTERS = {
andrej@1740:     "ANY_TO_ANY": [
Edouard@1390:         # simple type conv are let as C cast
andrej@1740:         (("ANY_INT", "ANY_BIT"), ("ANY_NUM", "ANY_BIT")),
andrej@1740:         (("ANY_REAL",), ("ANY_REAL",)),
Edouard@1390:         # REAL_TO_INT
andrej@1740:         (("ANY_REAL",), ("ANY_SINT",)),
andrej@1740:         (("ANY_REAL",), ("ANY_UINT",)),
andrej@1740:         (("ANY_REAL",), ("ANY_BIT",)),
Edouard@1390:         # TO_TIME
andrej@1740:         (("ANY_INT", "ANY_BIT"), ("ANY_DATE", "TIME")),
andrej@1740:         (("ANY_REAL",),          ("ANY_DATE", "TIME")),
andrej@1740:         (("ANY_STRING",),        ("ANY_DATE", "TIME")),
Edouard@1390:         # FROM_TIME
andrej@1740:         (("ANY_DATE", "TIME"), ("ANY_REAL",)),
andrej@1740:         (("ANY_DATE", "TIME"), ("ANY_INT", "ANY_NBIT")),
Edouard@1390:         (("TIME",), ("ANY_STRING",)),
Edouard@1390:         (("DATE",), ("ANY_STRING",)),
andrej@1740:         (("TOD",),  ("ANY_STRING",)),
andrej@1740:         (("DT",),   ("ANY_STRING",)),
Edouard@1390:         # TO_STRING
andrej@1740:         (("BOOL",),     ("ANY_STRING",)),
andrej@1740:         (("ANY_BIT",),  ("ANY_STRING",)),
Edouard@1390:         (("ANY_REAL",), ("ANY_STRING",)),
Edouard@1390:         (("ANY_SINT",), ("ANY_STRING",)),
Edouard@1390:         (("ANY_UINT",), ("ANY_STRING",)),
Edouard@1390:         # FROM_STRING
Edouard@1390:         (("ANY_STRING",), ("BOOL",)),
Edouard@1390:         (("ANY_STRING",), ("ANY_BIT",)),
Edouard@1390:         (("ANY_STRING",), ("ANY_SINT",)),
Edouard@1390:         (("ANY_STRING",), ("ANY_UINT",)),
andrej@1740:         (("ANY_STRING",), ("ANY_REAL",))
andrej@1740:     ],
andrej@1740:     "BCD_TO_ANY": [
andrej@1740:         (("BYTE",),  ("USINT",)),
andrej@1740:         (("WORD",),  ("UINT",)),
andrej@1740:         (("DWORD",), ("UDINT",)),
andrej@1740:         (("LWORD",), ("ULINT",))
andrej@1740:     ],
andrej@1740:     "ANY_TO_BCD": [
andrej@1740:         (("USINT",), ("BYTE",)),
andrej@1740:         (("UINT",),  ("WORD",)),
andrej@1740:         (("UDINT",), ("DWORD",)),
andrej@1740:         (("ULINT",), ("LWORD",))
andrej@1740:     ]
Edouard@1390: }
Edouard@1390: 
Edouard@1390: # remove gettext override
Edouard@1390: del _