bacnet/bacnet.py
author Edouard Tisserant
Fri, 09 Apr 2021 09:45:28 +0200
changeset 2725 2b00f90c6888
parent 2703 32ffdb32b14e
child 2736 a81b72ef156c
permissions -rw-r--r--
merge
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     3
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     4
# This file is part of Beremiz, a Integrated Development Environment for
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     5
# programming IEC 61131-3 automates supporting plcopen standard.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     6
# This files implements the bacnet plugin for Beremiz, adding BACnet server support.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     7
#
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     8
# Copyright (c) 2017 Mario de Sousa (msousa@fe.up.pt)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
     9
#
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    10
# This program is free software: you can redistribute it and/or modify
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    11
# it under the terms of the GNU General Public License as published by
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    12
# the Free Software Foundation, either version 2 of the License, or
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    13
# (at your option) any later version.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    14
#
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    15
# This program is distributed in the hope that it will be useful,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    18
# GNU General Public License for more details.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    19
#
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    20
# You should have received a copy of the GNU General Public License
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    21
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    22
#
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    23
# This code is made available on the understanding that it will not be
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    24
# used in safety-critical situations without a full and competent review.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    25
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    26
from __future__ import absolute_import
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    27
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    28
import os
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    29
from collections import Counter
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    30
from datetime import datetime
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    31
import pickle
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    32
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    33
import wx
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    34
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    35
from bacnet.BacnetSlaveEditor import *
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    36
from bacnet.BacnetSlaveEditor import ObjectProperties
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    37
from PLCControler import LOCATION_CONFNODE, LOCATION_VAR_MEMORY
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    38
from ConfigTreeNode import ConfigTreeNode
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
    39
import util.paths as paths
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    40
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    41
base_folder = os.path.split(os.path.dirname(os.path.realpath(__file__)))[0]
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    42
base_folder = os.path.join(base_folder, "..")
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    43
BacnetPath  = os.path.join(base_folder, "BACnet")
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    44
BacnetLibraryPath = os.path.join(BacnetPath, "lib")
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    45
BacnetIncludePath = os.path.join(BacnetPath, "include")
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    46
BacnetIncludePortPath = os.path.join(BacnetPath, "ports")
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    47
BacnetIncludePortPath = os.path.join(BacnetIncludePortPath, "linux")
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    48
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    49
# Parameters to be monkey patched in beremiz customizations
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    50
BACNET_VENDOR_ID = 9999
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    51
BACNET_VENDOR_NAME = "Beremiz.org"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    52
BACNET_DEVICE_MODEL_NAME = "Beremiz PLC"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    53
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    54
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    55
# Max String Size of BACnet Paramaters
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    56
BACNET_PARAM_STRING_SIZE = 64
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
    57
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    58
#
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    59
#
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    60
#
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    61
# S L A V E    D E V I C E              #
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    62
#
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    63
#
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    64
#
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    65
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    66
# NOTE: Objects of class _BacnetSlavePlug are never instantiated directly.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    67
#       The objects are instead instantiated from class FinalCTNClass
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    68
#       FinalCTNClass inherits from: - ConfigTreeNode
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    69
#                                    - The tree node plug (in our case _BacnetSlavePlug)
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    70
# class _BacnetSlavePlug:
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    71
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    72
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    73
class RootClass(object):
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    74
    XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    75
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    76
      <xsd:element name="BACnetServerNode">
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    77
        <xsd:complexType>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    78
          <xsd:attribute name="Network_Interface"      type="xsd:string"  use="optional" default="eth0"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    79
          <xsd:attribute name="UDP_Port_Number"                           use="optional" default="47808">
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    80
            <xsd:simpleType>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    81
                <xsd:restriction base="xsd:integer">
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    82
                    <xsd:minInclusive value="0"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    83
                    <xsd:maxInclusive value="65535"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    84
                </xsd:restriction>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    85
            </xsd:simpleType>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    86
          </xsd:attribute>
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
    87
          <xsd:attribute name="BACnet_Communication_Control_Password"
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    88
                                                       type="xsd:string"  use="optional" default="Malba Tahan"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    89
          <xsd:attribute name="BACnet_Device_ID"                          use="optional" default="0">
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    90
            <xsd:simpleType>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    91
                <xsd:restriction base="xsd:integer">
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    92
                    <xsd:minInclusive value="0"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    93
                    <xsd:maxInclusive value="4194302"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    94
                </xsd:restriction>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    95
            </xsd:simpleType>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    96
          </xsd:attribute>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    97
          <xsd:attribute name="BACnet_Device_Name"        type="xsd:string"  use="optional" default="Beremiz device 0"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    98
          <xsd:attribute name="BACnet_Device_Location"    type="xsd:string"  use="optional" default=""/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
    99
          <xsd:attribute name="BACnet_Device_Description" type="xsd:string"  use="optional" default="Beremiz device 0"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   100
          <xsd:attribute name="BACnet_Device_Application_Software_Version" type="xsd:string"  use="optional" default="1.0"/>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   101
        </xsd:complexType>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   102
      </xsd:element>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   103
    </xsd:schema>
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   104
    """
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   105
    # NOTE; Add the following code/declaration to the aboce XSD in order to activate the
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   106
    #          Override_Parameters_Saved_on_PLC   flag (currenty not in use as it requires further
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   107
    #          analysis how the user would interpret this user interface option.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   108
    #        <--- snip --->
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   109
    #          <xsd:attribute name="Override_Parameters_Saved_on_PLC" 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   110
    #                                                   type="xsd:boolean" use="optional" default="true"/>
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   111
    #        <--- snip --->
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   112
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   113
    # NOTE: BACnet device (object) IDs are 22 bits long (not counting the 10 bits for the type ID)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   114
    #       so the Device instance ID is limited from 0 to 22^2-1 = 4194303
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   115
    #       However, 4194303 is reserved for special use (similar to NULL pointer), so last
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   116
    #       valid ID becomes 4194302
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   117
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   118
    # The class/object that will render the graphical interface to edit the
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   119
    #    BacnetSlavePlug's configuration parameters. The object of class BacnetSlaveEditorPlug
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   120
    #    will be instantiated by the ConfigTreeNode class.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   121
    #    This BacnetSlaveEditorPlug object can be accessed from _BacnetSlavePlug as
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   122
    #    'self._View'
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   123
    #    See the following note to understand how this is possible!
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   124
    #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   125
    # NOTE: Objects of class _BacnetSlavePlug are never instantiated directly.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   126
    #       The objects are instead instantiated from class FinalCTNClass
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   127
    #       FinalCTNClass inherits from: - ConfigTreeNode
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   128
    #                                    - The tree node plug (in our case _BacnetSlavePlug)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   129
    #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   130
    #       This means that objects of class _BacnetSlavePlug may safely access all the members
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   131
    #       of classes ConfigTreeNode as well as FinalCTNClass (since they are always instantiated
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   132
    #       as a FinalCTNClass)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   133
    EditorType = BacnetSlaveEditorPlug
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   134
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   135
    # The following classes follow the model/viewer design pattern
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   136
    #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   137
    # _BacnetSlavePlug       - contains the model (i.e. configuration parameters)
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   138
    # BacnetSlaveEditorPlug  - contains the viewer (and editor, so it includes the 'controller' part of the
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   139
    #                                    design pattern which in this case is not separated from the viewer)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   140
    #
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   141
    # The _BacnetSlavePlug      object is 'permanent', i.e. it exists as long as the beremiz project is open
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   142
    # The BacnetSlaveEditorPlug object is 'transient', i.e. it exists only while the editor is visible/open
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   143
    #                                                         in the editing panel. It is destoryed whenever
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   144
    #                                                         the user closes the corresponding tab in the
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   145
    #                                                         editing panel, and a new object is created when
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   146
    #                                                         the editor is re-opened.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   147
    #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   148
    # _BacnetSlavePlug contains:  AV_ObjTable, ...
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   149
    #                             (these are the objects that actually store the config parameters or 'model'
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   150
    #                              and are therefore stored to a file)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   151
    #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   152
    # _BacnetSlavePlug contains:  AV_VarEditor, ...
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   153
    #                             (these are the objects that implement a grid table to edit/view the
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   154
    #                              corresponding mode parameters)
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   155
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   156
    #  Logic:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   157
    #    - The xx_VarEditor classes inherit from wx.grid.Grid
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   158
    #    - The xx_ObjTable  classes inherit from wx.grid.PyGridTableBase
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   159
    #  To be more precise, the inheritance tree is actually:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   160
    #    xx_VarEditor -> ObjectGrid -> CustomGrid   -> wx.grid.Grid
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   161
    #    xx_ObjTable  -> ObjectTable -> CustomTable -> wx.grid.PyGridTableBase)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   162
    #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   163
    #  Note that wx.grid.Grid is prepared to work with wx.grid.PyGridTableBase as the container of
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   164
    #  data that is displayed and edited in the Grid.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   165
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   166
    ConfNodeMethods = [
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   167
        {"bitmap": "ExportSlave",
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   168
         "name": _("Export slave"),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   169
         "tooltip": _("Export BACnet slave to EDE file"),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   170
         "method": "_ExportBacnetSlave"},
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   171
    ]
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   172
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   173
    def __init__(self):
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   174
        # Initialize the dictionary that stores the current configuration for the Analog/Digital/MultiValued Variables
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   175
        #   in this BACnet server.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   176
        self.ObjTablesData = {}
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   177
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   178
        # Each list will contain an entry for each row in the xxxxVar grid!!
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   179
        #   Each entry/row will be a dictionary
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   180
        #     Each dictionary will contain all entries/data
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   181
        # for one row in the grid.
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   182
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   183
        self.ObjTablesData["AV_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   184
        self.ObjTablesData["AO_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   185
        self.ObjTablesData["AI_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   186
        self.ObjTablesData["BV_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   187
        self.ObjTablesData["BO_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   188
        self.ObjTablesData["BI_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   189
        self.ObjTablesData["MSV_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   190
        self.ObjTablesData["MSO_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   191
        self.ObjTablesData["MSI_Obj"] = []
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   192
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   193
        self.ObjTablesData["EDEfile_parm"] = {"next_EDE_file_version": 1}
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   194
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   195
        # EDE files inlcude extra parameters (ex. file version)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   196
        # We would like to save the parameters the user configures
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   197
        # so they are available the next time the user opens the project.
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   198
        # Since this plugin is only storing the ObjTablesData[] dict
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   199
        # to file, we add that info to this dictionary too.
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   200
        # Yes, I know this is kind of a
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   201
        # hack.
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   202
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   203
        filepath = self.GetFileName()
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   204
        if os.path.isfile(filepath):
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   205
            self.LoadFromFile(filepath)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   206
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   207
        self.ObjTables = {}
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   208
        self.ObjTables["AV_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   209
            self, self.ObjTablesData["AV_Obj"],  AVObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   210
        self.ObjTables["AO_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   211
            self, self.ObjTablesData["AO_Obj"],  AOObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   212
        self.ObjTables["AI_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   213
            self, self.ObjTablesData["AI_Obj"],  AIObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   214
        self.ObjTables["BV_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   215
            self, self.ObjTablesData["BV_Obj"],  BVObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   216
        self.ObjTables["BO_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   217
            self, self.ObjTablesData["BO_Obj"],  BOObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   218
        self.ObjTables["BI_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   219
            self, self.ObjTablesData["BI_Obj"],  BIObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   220
        self.ObjTables["MSV_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   221
            self, self.ObjTablesData["MSV_Obj"], MSVObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   222
        self.ObjTables["MSO_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   223
            self, self.ObjTablesData["MSO_Obj"], MSOObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   224
        self.ObjTables["MSI_Obj"] = ObjectTable(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   225
            self, self.ObjTablesData["MSI_Obj"], MSIObject)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   226
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   227
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   228
    # Functions to be called by CTNClass #
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   229
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   230
    # The following functions would be somewhat equvalent to virtual functions/methods in C++ classes
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   231
    # They will be called by the base class (CTNClass) from which this
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   232
    # _BacnetSlavePlug class derives.
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   233
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   234
    def GetCurrentNodeName(self):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   235
        return self.CTNName()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   236
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   237
    def GetFileName(self):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   238
        return os.path.join(self.CTNPath(), 'bacnet_slave')
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   239
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   240
    def OnCTNSave(self, from_project_path=None):
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   241
        return self.SaveToFile(self.GetFileName())
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   242
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   243
    def CTNTestModified(self):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   244
        # self.ChangesToSave: Check whether any of the parameters, defined in the XSD above, were changed.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   245
        #                     This is handled by the ConfigTreeNode class
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   246
        #                     (Remember that no objects are ever instantiated from _BacnetSlavePlug.
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   247
        #                      Objects are instead created from FinalCTNClass, which derives from
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   248
        #                      _BacnetSlavePlug and ConfigTreeNode. This means that we can exceptionally
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   249
        # consider that all objects of type _BacnetSlavePlug will also be a
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   250
        # ConfigTreeNode).
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   251
        result = self.ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   252
            or self.ObjTables["AV_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   253
            or self.ObjTables["AO_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   254
            or self.ObjTables["AI_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   255
            or self.ObjTables["BV_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   256
            or self.ObjTables["BO_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   257
            or self.ObjTables["BI_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   258
            or self.ObjTables["MSV_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   259
            or self.ObjTables["MSO_Obj"].ChangesToSave \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   260
            or self.ObjTables["MSI_Obj"].ChangesToSave
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   261
        return result
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   262
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   263
    # Currently not needed. Override _OpenView() in case we need to do some special stuff whenever the editor is opened!
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   264
    # def _OpenView(self, name=None, onlyopened=False):
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   265
        # print "_BacnetSlavePlug._OpenView() Called!!!"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   266
        # ConfigTreeNode._OpenView(self, name, onlyopened)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   267
        # print self._View
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   268
        # if self._View is not None:
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   269
        #     self._View.SetBusId(self.GetCurrentLocation())
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   270
        # return self._View
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   271
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   272
    def GetVariableLocationTree(self):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   273
        current_location = self.GetCurrentLocation()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   274
        # see comment in CTNGenerate_C regarding identical line of code!
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   275
        locstr = ".".join(map(str, current_location))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   276
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   277
        # IDs used by BACnet to identify object types/class.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   278
        #     OBJECT_ANALOG_INPUT       =  0,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   279
        #     OBJECT_ANALOG_OUTPUT      =  1,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   280
        #     OBJECT_ANALOG_VALUE       =  2,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   281
        #     OBJECT_BINARY_INPUT       =  3,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   282
        #     OBJECT_BINARY_OUTPUT      =  4,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   283
        #     OBJECT_BINARY_VALUE       =  5,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   284
        #     OBJECT_MULTI_STATE_INPUT  = 13,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   285
        #     OBJECT_MULTI_STATE_OUTPUT = 14,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   286
        #     OBJECT_MULTI_STATE_VALUE  = 19,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   287
        #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   288
        #  Since Binary Value, Analog Value, etc. objects may use the same
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   289
        # object ID (since they have distinct class IDs), we must also distinguish them in some way in
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   290
        # the %MX0.3.4 IEC 61131-3 syntax.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   291
        #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   292
        # For this reason we add the BACnet class identifier to the %MX0.5.3 location.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   293
        # For example, for a BACnet plugin in location '0' of the Beremiz configuration tree,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   294
        #  all      Binary Values will be mapped onto: %MX0.5.xxx    (xxx is object ID)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   295
        #  all Multi State Values will be mapped onto: %MB0.19.xxx   (xxx is object ID)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   296
        #  all      Analog Values will be mapped onto: %MD0.2.xxx    (xxx is object ID)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   297
        #  etc..
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   298
        #
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   299
        #   Value objects will be mapped onto %M
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   300
        #   Input objects will be mapped onto %I
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   301
        #  Output objects will be mapped onto %Q
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   302
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   303
        BACnetEntries = []
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   304
        BACnetEntries.append(self.GetSlaveLocationTree(
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   305
            self.ObjTablesData["AV_Obj"], 32, 'REAL', 'D', locstr + '.2', 'Analog Values'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   306
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   307
            self.ObjTablesData["AO_Obj"], 32, 'REAL', 'D', locstr + '.1', 'Analog Outputs'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   308
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   309
            self.ObjTablesData["AI_Obj"], 32, 'REAL', 'D', locstr + '.0', 'Analog Inputs'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   310
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   311
            self.ObjTablesData["BV_Obj"],  1, 'BOOL', 'X', locstr + '.5', 'Binary Values'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   312
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   313
            self.ObjTablesData["BO_Obj"],  1, 'BOOL', 'X', locstr + '.4', 'Binary Outputs'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   314
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   315
            self.ObjTablesData["BI_Obj"],  1, 'BOOL', 'X', locstr + '.3', 'Binary Inputs'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   316
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   317
            self.ObjTablesData["MSV_Obj"],  8, 'BYTE', 'B', locstr + '.19', 'Multi State Values'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   318
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   319
            self.ObjTablesData["MSO_Obj"],  8, 'BYTE', 'B', locstr + '.14', 'Multi State Outputs'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   320
        BACnetEntries.append(self.GetSlaveLocationTree(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   321
            self.ObjTablesData["MSI_Obj"],  8, 'BYTE', 'B', locstr + '.13', 'Multi State Inputs'))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   322
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   323
        return {"name": self.BaseParams.getName(),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   324
                "type": LOCATION_CONFNODE,
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   325
                "location": locstr + ".x",
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   326
                "children": BACnetEntries}
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   327
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   328
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   329
    # Helper functions/methods #
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   330
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   331
    # a helper function to GetVariableLocationTree()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   332
    def GetSlaveLocationTree(self, ObjTablesData, size_in_bits, IECdatatype, location_size, location_str, name):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   333
        BACnetObjectEntries = []
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   334
        for xx_ObjProp in ObjTablesData:
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   335
            BACnetObjectEntries.append({
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   336
                "name": str(xx_ObjProp["Object Identifier"]) + ': ' + xx_ObjProp["Object Name"],
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   337
                "type": LOCATION_VAR_MEMORY,  # LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, or LOCATION_VAR_MEMORY
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   338
                "size": size_in_bits,  # 1 or 16
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   339
                "IEC_type": IECdatatype,  # 'BOOL', 'WORD', ...
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   340
                "var_name": "var_name",  # seems to be ignored??
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   341
                "location": location_size + location_str + "." + str(xx_ObjProp["Object Identifier"]),
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   342
                "description": "description",  # seems to be ignored?
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   343
                "children": []})
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   344
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   345
        return {"name": name,
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   346
                "type": LOCATION_CONFNODE,
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   347
                "location": location_str + ".x",
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   348
                "children": BACnetObjectEntries}
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   349
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   350
    # Returns a dictionary with:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   351
    #      keys: names  of BACnet objects
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   352
    #     value: number of BACnet objects using this same name
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   353
    #            (values larger than 1 indicates an error as BACnet requires unique names)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   354
    def GetObjectNamesCount(self):
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   355
        # The dictionary is built by first creating a list containing the names of _ALL_
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   356
        # BACnet objects currently configured by the user (using the GUI)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   357
        ObjectNames = []
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   358
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   359
            self.ObjTables["AV_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   360
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   361
            self.ObjTables["AO_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   362
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   363
            self.ObjTables["AI_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   364
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   365
            self.ObjTables["BV_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   366
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   367
            self.ObjTables["BO_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   368
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   369
            self.ObjTables["BI_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   370
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   371
            self.ObjTables["MSV_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   372
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   373
            self.ObjTables["MSO_Obj"].GetAllValuesByName("Object Name"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   374
        ObjectNames.extend(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   375
            self.ObjTables["MSI_Obj"].GetAllValuesByName("Object Name"))
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   376
        # This list is then transformed into a collections.Counter class
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   377
        # Which is then transformed into a dictionary using dict()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   378
        return dict(Counter(ObjectNames))
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   379
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   380
    # Check whether the current configuration contains BACnet objects configured
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   381
    # with the same identical object name  (returns True or False)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   382
    def HasDuplicateObjectNames(self):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   383
        ObjectNamesCount = self.GetObjectNamesCount()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   384
        for ObjName in ObjectNamesCount:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   385
            if ObjectNamesCount[ObjName] > 1:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   386
                return True
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   387
        return False
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   388
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   389
    # Check whether any object ID is used more than once (not valid in BACnet)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   390
    # (returns True or False)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   391
    def HasDuplicateObjectIDs(self):
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   392
        res = self.ObjTables["AV_Obj"].HasDuplicateObjectIDs()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   393
        res = res or self.ObjTables["AO_Obj"].HasDuplicateObjectIDs()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   394
        res = res or self.ObjTables["AI_Obj"].HasDuplicateObjectIDs()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   395
        res = res or self.ObjTables["BV_Obj"].HasDuplicateObjectIDs()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   396
        res = res or self.ObjTables["BO_Obj"].HasDuplicateObjectIDs()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   397
        res = res or self.ObjTables["BI_Obj"].HasDuplicateObjectIDs()
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   398
        res = res or self.ObjTables["MSV_Obj"].HasDuplicateObjectIDs()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   399
        res = res or self.ObjTables["MSO_Obj"].HasDuplicateObjectIDs()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   400
        res = res or self.ObjTables["MSI_Obj"].HasDuplicateObjectIDs()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   401
        return res
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   402
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   403
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   404
    # Methods related to files (saving/loading/exporting) #
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   405
    #
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   406
    def SaveToFile(self, filepath):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   407
        # Save node data in file
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   408
        # The configuration data declared in the XSD string will be saved by the ConfigTreeNode class,
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   409
        # so we only need to save the data that is stored in ObjTablesData objects
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   410
        # Note that we do not store the ObjTables objects. ObjTables is of a class that
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   411
        # contains more stuff we do not need to store. Actually it is a bad idea to store
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   412
        # this extra stuff (as we would make the files we generate dependent on the actual
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   413
        # version of the wx library we are using!!! Remember that ObjTables evetually
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   414
        # derives/inherits from wx.grid.PyGridTableBase). Another reason not to store the whole
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   415
        # object is because it is not pickable (i.e. pickle.dump() cannot handle it)!!
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   416
        try:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   417
            fd = open(filepath,   "w")
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   418
            pickle.dump(self.ObjTablesData, fd)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   419
            fd.close()
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   420
            # On successfull save, reset flags to indicate no more changes that
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   421
            # need saving
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   422
            self.ObjTables["AV_Obj"].ChangesToSave = False
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   423
            self.ObjTables["AO_Obj"].ChangesToSave = False
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   424
            self.ObjTables["AI_Obj"].ChangesToSave = False
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   425
            self.ObjTables["BV_Obj"].ChangesToSave = False
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   426
            self.ObjTables["BO_Obj"].ChangesToSave = False
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   427
            self.ObjTables["BI_Obj"].ChangesToSave = False
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   428
            self.ObjTables["MSV_Obj"].ChangesToSave = False
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   429
            self.ObjTables["MSO_Obj"].ChangesToSave = False
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   430
            self.ObjTables["MSI_Obj"].ChangesToSave = False
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   431
            return True
2309
d8fb90a2e11f Please pylint and pep8
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2250
diff changeset
   432
        except Exception:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   433
            return _("Unable to save to file \"%s\"!") % filepath
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   434
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   435
    def LoadFromFile(self, filepath):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   436
        # Load the data that is saved in SaveToFile()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   437
        try:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   438
            fd = open(filepath,   "r")
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   439
            self.ObjTablesData = pickle.load(fd)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   440
            fd.close()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   441
            return True
2309
d8fb90a2e11f Please pylint and pep8
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2250
diff changeset
   442
        except Exception:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   443
            return _("Unable to load file \"%s\"!") % filepath
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   444
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   445
    def _ExportBacnetSlave(self):
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   446
        dialog = wx.FileDialog(self.GetCTRoot().AppFrame,
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   447
                               _("Choose a file"),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   448
                               os.path.expanduser("~"),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   449
                               "%s_EDE.csv" % self.CTNName(),
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   450
                               _("EDE files (*_EDE.csv)|*_EDE.csv|All files|*.*"),
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   451
                               wx.SAVE | wx.OVERWRITE_PROMPT)
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   452
        if dialog.ShowModal() == wx.ID_OK:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   453
            result = self.GenerateEDEFile(dialog.GetPath())
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   454
            result = False
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   455
            if result:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   456
                self.GetCTRoot().logger.write_error(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   457
                    _("Error: Export slave failed\n"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   458
        dialog.Destroy()
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   459
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   460
    def GenerateEDEFile(self, filename):
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   461
        template_file_dir = os.path.join(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   462
            os.path.split(__file__)[0], "ede_files")
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   463
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   464
        # The BACnetServerNode attribute is added dynamically by ConfigTreeNode._AddParamsMembers()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   465
        # It will be an XML parser object created by
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   466
        # GenerateParserFromXSDstring(self.XSD).CreateRoot()
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   467
        BACnet_Device_ID = self.BACnetServerNode.getBACnet_Device_ID()
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   468
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   469
        # The EDE file contains a header that includes general project data (name, author, ...)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   470
        # Instead of asking the user for this data, we get it from the configuration
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   471
        # of the Beremiz project itself.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   472
        # We ask the root Config Tree Node for the data...
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   473
        ProjProp = {}
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   474
        FileProp = {}
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   475
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   476
        # this should be an object of class ProjectController
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   477
        CTN_Root = self.GetCTRoot()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   478
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   479
        # this should be an object capable of parsing
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   480
        # PLCopen XML files. The parser is created automatically
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   481
        # (i.e. using GenerateParserFromXSD() from xmlclass module)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   482
        # using the PLCopen XSD file defining the format of the XML.
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   483
        # See the file plcopen/plcopen.py
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   484
        Project = CTN_Root.Project
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   485
        if Project is not None:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   486
            # getcontentHeader() and getfileHeader() are functions that are conditionally defined in
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   487
            # plcopn/plcopen.py    We cannot rely on their existance
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   488
            if getattr(Project, "getcontentHeader", None) is not None:
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   489
                ProjProp = Project.getcontentHeader()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   490
                # getcontentHeader() returns a dictionary. Available keys are:
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   491
                # "projectName", "projectVersion", "modificationDateTime",
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   492
                # "organization", "authorName", "language", "pageSize", "scaling"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   493
            if getattr(Project, "getfileHeader", None) is not None:
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   494
                FileProp = Project.getfileHeader()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   495
                # getfileHeader() returns a dictionary. Available keys are:
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   496
                # "companyName", "companyURL", "productName", "productVersion",
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   497
                # "productRelease", "creationDateTime", "contentDescription"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   498
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   499
        ProjName = ""
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   500
        if "projectName" in ProjProp:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   501
            ProjName = ProjProp["projectName"]
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   502
        ProjAuthor = ""
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   503
        if "companyName" in FileProp:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   504
            ProjAuthor += "(" + FileProp["companyName"] + ")"
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   505
        if "authorName" in ProjProp:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   506
            ProjAuthor = ProjProp["authorName"] + " " + ProjAuthor
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   507
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   508
        projdata_dict = {}
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   509
        projdata_dict["Project Name"] = ProjName
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   510
        projdata_dict["Project Author"] = ProjAuthor
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   511
        projdata_dict["Current Time"] = datetime.now().strftime(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   512
            '%Y-%m-%d %H:%M:%S')
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   513
        projdata_dict["EDE file version"] = self.ObjTablesData[
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   514
            "EDEfile_parm"]["next_EDE_file_version"]
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   515
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   516
        # Next time we generate an EDE file, use another version!
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   517
        self.ObjTablesData["EDEfile_parm"]["next_EDE_file_version"] += 1
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   518
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   519
        AX_params_format = "%(Object Name)s;" + str(BACnet_Device_ID) + \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   520
            ";%(Object Name)s;%(BACnetObjTypeID)s;%(Object Identifier)s;%(Description)s;0;;;%(Settable)s;N;;;;%(Unit ID)s;"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   521
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   522
        BX_params_format = "%(Object Name)s;" + str(BACnet_Device_ID) + \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   523
            ";%(Object Name)s;%(BACnetObjTypeID)s;%(Object Identifier)s;%(Description)s;0;0;1;%(Settable)s;N;;;;;"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   524
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   525
        MSX_params_format = "%(Object Name)s;" + str(BACnet_Device_ID) + \
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   526
            ";%(Object Name)s;%(BACnetObjTypeID)s;%(Object Identifier)s;%(Description)s;1;1;%(Number of States)s;%(Settable)s;N;;;;;"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   527
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   528
        Objects_List = []
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   529
        for ObjType, params_format in [("AV",  AX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   530
                                       ("AO",  AX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   531
                                       ("AI",  AX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   532
                                       ("BV",  BX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   533
                                       ("BO",  BX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   534
                                       ("BI",  BX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   535
                                       ("MSV", MSX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   536
                                       ("MSO", MSX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   537
                                       ("MSI", MSX_params_format)]:
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   538
            self.ObjTables[ObjType + "_Obj"].UpdateAllVirtualProperties()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   539
            for ObjProp in self.ObjTablesData[ObjType + "_Obj"]:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   540
                Objects_List.append(params_format % ObjProp)
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   541
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   542
        # Normalize filename
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   543
        for extension in ["_EDE.csv", "_ObjTypes.csv", "_StateTexts.csv", "_Units.csv"]:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   544
            if filename.lower().endswith(extension.lower()):
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   545
                filename = filename[:-len(extension)]
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   546
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   547
        # EDE_header
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   548
        generate_file_name = filename + "_EDE.csv"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   549
        template_file_name = os.path.join(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   550
            template_file_dir, "template_EDE.csv")
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   551
        generate_file_content = open(template_file_name).read() % projdata_dict
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   552
        generate_file_handle = open(generate_file_name, 'w')
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   553
        generate_file_handle  .write(generate_file_content)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   554
        generate_file_handle  .write("\n".join(Objects_List))
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   555
        generate_file_handle  .close()
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   556
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   557
        # templates of remaining files do not need changes. They are simply
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   558
        # copied unchanged!
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   559
        for extension in ["_ObjTypes.csv", "_StateTexts.csv", "_Units.csv"]:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   560
            generate_file_name = filename + extension
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   561
            template_file_name = os.path.join(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   562
                template_file_dir, "template" + extension)
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   563
            generate_file_content = open(template_file_name).read()
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   564
            generate_file_handle = open(generate_file_name, 'w')
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   565
            generate_file_handle  .write(generate_file_content)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   566
            generate_file_handle  .close()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   567
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   568
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   569
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   570
    #
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   571
    # Generate the C source code files
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   572
    #
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   573
    def CTNGenerate_C(self, buildpath, locations):
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   574
        # Determine the current location in Beremiz's project configuration
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   575
        # tree
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   576
        current_location = self.GetCurrentLocation()
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   577
        # The current location of this plugin in Beremiz's configuration tree, separated by underscores
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   578
        #  NOTE: Since BACnet plugin currently does not use sub-branches in the tree (in other words, this
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   579
        #        _BacnetSlavePlug class was actually renamed as the RootClass), the current_location_dots
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   580
        #        will actually be a single number (e.g.: 0 or 3 or 6, corresponding to the location
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   581
        #        in which the plugin was inserted in the Beremiz configuration tree on Beremiz's left panel).
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   582
        locstr = "_".join(map(str, current_location))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   583
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   584
        # First check whether all the current parameters (inserted by user in
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   585
        # the GUI) are valid...
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   586
        if self.HasDuplicateObjectNames():
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   587
            self.GetCTRoot().logger.write_warning(
2425
68e7da937162 Fix 'msgid' format string with unnamed arguments cannot be properly localized
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2309
diff changeset
   588
                _("Error: BACnet server '{a1}.x:{a2}' contains objects with duplicate object names.\n").
68e7da937162 Fix 'msgid' format string with unnamed arguments cannot be properly localized
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2309
diff changeset
   589
                format(a1=locstr, a2=self.CTNName()))
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   590
            raise Exception(False)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   591
            # TODO: return an error code instead of raising an exception
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   592
            # (currently unsupported by Beremiz)
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   593
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   594
        if self.HasDuplicateObjectIDs():
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   595
            self.GetCTRoot().logger.write_warning(
2425
68e7da937162 Fix 'msgid' format string with unnamed arguments cannot be properly localized
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2309
diff changeset
   596
                _("Error: BACnet server '{a1}.x: {a2}' contains objects with duplicate object identifiers.\n").
68e7da937162 Fix 'msgid' format string with unnamed arguments cannot be properly localized
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2309
diff changeset
   597
                format(a1=locstr, a2=self.CTNName()))
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   598
            raise Exception(False)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   599
            # TODO: return an error code instead of raising an exception
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   600
            # (currently unsupported by Beremiz)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   601
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   602
        # -------------------------------------------------------------------------------
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   603
        # Create and populate the loc_dict dictionary with all parameters needed to configure
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   604
        #  the generated source code (.c and .h files)
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   605
        # ----------------------------------------------------------------------
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   606
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   607
        # 1) Create the dictionary (loc_dict = {})
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   608
        loc_dict = {}
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   609
        loc_dict["locstr"] = locstr
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   610
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   611
        # The BACnetServerNode attribute is added dynamically by ConfigTreeNode._AddParamsMembers()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   612
        # It will be an XML parser object created by
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   613
        # GenerateParserFromXSDstring(self.XSD).CreateRoot()
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   614
        #
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   615
        # Note: Override_Parameters_Saved_on_PLC is converted to an integer by int()
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   616
        #       The above flag is not currently in use. It requires further thinking on how the 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   617
        #       user will interpret and interact with this user interface...
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   618
        #loc_dict["Override_Parameters_Saved_on_PLC"] = int(self.BACnetServerNode.getOverride_Parameters_Saved_on_PLC())
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   619
        loc_dict["network_interface"] = self.BACnetServerNode.getNetwork_Interface()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   620
        loc_dict["port_number"] = self.BACnetServerNode.getUDP_Port_Number()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   621
        loc_dict["BACnet_Device_ID"] = self.BACnetServerNode.getBACnet_Device_ID()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   622
        loc_dict["BACnet_Device_Name"] = self.BACnetServerNode.getBACnet_Device_Name()
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   623
        loc_dict["BACnet_Comm_Control_Password"] = self.BACnetServerNode.getBACnet_Communication_Control_Password()
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   624
        loc_dict["BACnet_Device_Location"] = self.BACnetServerNode.getBACnet_Device_Location()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   625
        loc_dict["BACnet_Device_Description"] = self.BACnetServerNode.getBACnet_Device_Description()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   626
        loc_dict["BACnet_Device_AppSoft_Version"] = self.BACnetServerNode.getBACnet_Device_Application_Software_Version()
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   627
        loc_dict["BACnet_Vendor_ID"] = BACNET_VENDOR_ID
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   628
        loc_dict["BACnet_Vendor_Name"] = BACNET_VENDOR_NAME
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   629
        loc_dict["BACnet_Model_Name"] = BACNET_DEVICE_MODEL_NAME
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   630
        loc_dict["BACnet_Param_String_Size"] = BACNET_PARAM_STRING_SIZE
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   631
        
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   632
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   633
        # 2) Add the data specific to each BACnet object type
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   634
        # For each BACnet object type, start off by creating some intermediate helpful lists
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   635
        #  a) parameters_list containing the strings that will
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   636
        #     be included in the C source code, and which will initialize the struct with the
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   637
        #     object (Analog Value, Binary Value, or Multi State Value) parameters
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   638
        #  b) locatedvar_list containing the strings that will
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   639
        #     declare the memory to store the located variables, as well as the
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   640
        #     pointers (required by matiec) that point to that memory.
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   641
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   642
        # format for delaring IEC 61131-3 variable (and pointer) onto which
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   643
        # BACnet object is mapped
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   644
        locvar_format = '%(Ctype)s ___%(loc)s_%(Object Identifier)s; ' + \
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   645
                        '%(Ctype)s *__%(loc)s_%(Object Identifier)s = &___%(loc)s_%(Object Identifier)s;'
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   646
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   647
        # format for initializing a ANALOG_VALUE_DESCR struct in C code
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   648
        #    also valid for ANALOG_INPUT and ANALOG_OUTPUT
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   649
        AX_params_format = '{&___%(loc)s_%(Object Identifier)s, ' + \
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   650
            '%(Object Identifier)s, "%(Object Name)s", "%(Description)s", %(Unit ID)d}'
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   651
        # format for initializing a BINARY_VALUE_DESCR struct in C code
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   652
        #    also valid for BINARY_INPUT and BINARY_OUTPUT
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   653
        BX_params_format = '{&___%(loc)s_%(Object Identifier)s, ' + \
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   654
            '%(Object Identifier)s, "%(Object Name)s", "%(Description)s"}'
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   655
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   656
        # format for initializing a MULTISTATE_VALUE_DESCR struct in C code
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   657
        #    also valid for MULTISTATE_INPUT and MULTISTATE_OUTPUT
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   658
        MSX_params_format = '{&___%(loc)s_%(Object Identifier)s, ' + \
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   659
            '%(Object Identifier)s, "%(Object Name)s", "%(Description)s", %(Number of States)s}'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   660
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   661
        # see the comment in GetVariableLocationTree()
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   662
        AV_locstr = 'MD' + locstr + '_2'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   663
        AO_locstr = 'QD' + locstr + '_1'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   664
        AI_locstr = 'ID' + locstr + '_0'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   665
        BV_locstr = 'MX' + locstr + '_5'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   666
        BO_locstr = 'QX' + locstr + '_4'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   667
        BI_locstr = 'IX' + locstr + '_3'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   668
        MSV_locstr = 'MB' + locstr + '_19'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   669
        MSO_locstr = 'QB' + locstr + '_14'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   670
        MSI_locstr = 'IB' + locstr + '_13'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   671
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   672
        for ObjType,  ObjLocStr,     params_format in [
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   673
                ("AV",  AV_locstr,  AX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   674
                ("AO",  AO_locstr,  AX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   675
                ("AI",  AI_locstr,  AX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   676
                ("BV",  BV_locstr,  BX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   677
                ("BO",  BO_locstr,  BX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   678
                ("BI",  BI_locstr,  BX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   679
                ("MSV", MSV_locstr, MSX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   680
                ("MSO", MSO_locstr, MSX_params_format),
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   681
                ("MSI", MSI_locstr, MSX_params_format)]:
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   682
            parameters_list = []
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   683
            locatedvar_list = []
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   684
            self.ObjTables[ObjType + "_Obj"].UpdateAllVirtualProperties()
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   685
            for ObjProp in self.ObjTablesData[ObjType + "_Obj"]:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   686
                ObjProp["loc"] = ObjLocStr
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   687
                parameters_list.append(params_format % ObjProp)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   688
                locatedvar_list.append(locvar_format % ObjProp)
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   689
            loc_dict[ObjType + "_count"] = len(parameters_list)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   690
            loc_dict[ObjType + "_param"] = ",\n".join(parameters_list)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   691
            loc_dict[ObjType + "_lvars"] = "\n".join(locatedvar_list)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   692
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   693
        # ----------------------------------------------------------------------
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   694
        # Create the C source files that implement the BACnet server
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   695
        # ----------------------------------------------------------------------
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   696
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   697
        # Names of the .c files that will be generated, based on a template file with same name
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   698
        #   (names without '.c'  --> this will be added later)
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   699
        #   main server.c file is handled separately
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   700
        Generated_BACnet_c_mainfile = "server"
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   701
        Generated_BACnet_c_files = [
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   702
            "ai", "ao", "av", "bi", "bo", "bv", "msi", "mso", "msv", "device"]
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   703
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   704
        # Names of the .h files that will be generated, based on a template file with same name
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   705
        #   (names without '.h'  --> this will be added later)
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   706
        Generated_BACnet_h_files = [
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   707
            "server", "device", "config_bacnet_for_beremiz",
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   708
            "ai", "ao", "av", "bi", "bo", "bv", "msi", "mso", "msv"
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   709
        ]
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   710
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   711
        # Generate the files with the source code
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   712
        postfix = "_".join(map(str, current_location))
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   713
        template_file_dir = os.path.join(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   714
            os.path.split(__file__)[0], "runtime")
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   715
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   716
        def generate_file(file_name, extension):
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   717
            generate_file_name = os.path.join(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   718
                buildpath, "%s_%s.%s" % (file_name, postfix, extension))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   719
            template_file_name = os.path.join(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   720
                template_file_dir, "%s.%s" % (file_name, extension))
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   721
            generate_file_content = open(template_file_name).read() % loc_dict
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   722
            generate_file_handle = open(generate_file_name, 'w')
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   723
            generate_file_handle.write(generate_file_content)
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   724
            generate_file_handle.close()
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   725
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   726
        for file_name in Generated_BACnet_c_files:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   727
            generate_file(file_name, "c")
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   728
        for file_name in Generated_BACnet_h_files:
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   729
            generate_file(file_name, "h")
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   730
        generate_file(Generated_BACnet_c_mainfile, "c")
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   731
        Generated_BACnet_c_mainfile_name = \
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   732
            os.path.join(buildpath, "%s_%s.%s" %
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   733
                         (Generated_BACnet_c_mainfile, postfix, "c"))
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   734
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   735
        # ----------------------------------------------------------------------
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   736
        # Finally, define the compilation and linking commands and flags
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   737
        # ----------------------------------------------------------------------
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   738
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   739
        LDFLAGS = []
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   740
        # when using dynamically linked library...
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   741
        # LDFLAGS.append(' -lbacnet')
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   742
        # LDFLAGS.append(' -L"'+BacnetLibraryPath+'"')
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   743
        # LDFLAGS.append(' "-Wl,-rpath,' + BacnetLibraryPath + '"')
2020
6dddf3070806 Add BACnet extension from Mario de Sousa <msousa@fe.up.pt>
Edouard Tisserant
parents:
diff changeset
   744
        # when using static library:
2250
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   745
        LDFLAGS.append(
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   746
            ' "' + os.path.join(BacnetLibraryPath, "libbacnet.a") + '"')
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   747
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   748
        CFLAGS = ' -I"' + BacnetIncludePath + '"'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   749
        CFLAGS += ' -I"' + BacnetIncludePortPath + '"'
86f61c4dfe76 Passed bacnet*.py through autopep8, and attemped to fix manually what went wrong + fixed pylint complains
Edouard Tisserant
parents: 2020
diff changeset
   750
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   751
        # ----------------------------------------------------------------------
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   752
        # Create a file containing the default configuration paramters.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   753
        # Beremiz will then transfer this file to the PLC, where the web server 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   754
        # will read it to obtain the default configuration parameters.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   755
        # ----------------------------------------------------------------------
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   756
        # NOTE: This is no loner needed! The web interface will read these 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   757
        # parameters directly from the compiled C code (.so file)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   758
        #
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   759
        ### extra_file_name   = os.path.join(buildpath, "%s_%s.%s" % ('bacnet_extrafile', postfix, 'txt'))
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   760
        ### extra_file_handle = open(extra_file_name, 'w')
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   761
        ### 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   762
        ### proplist = ["network_interface", "port_number", "BACnet_Device_ID", "BACnet_Device_Name", 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   763
        ###             "BACnet_Comm_Control_Password", "BACnet_Device_Location", 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   764
        ###             "BACnet_Device_Description", "BACnet_Device_AppSoft_Version"]
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   765
        ### for propname in proplist:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   766
        ###     extra_file_handle.write("%s:%s\n" % (propname, loc_dict[propname]))
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   767
        ### 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   768
        ### extra_file_handle.close()
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   769
        ### extra_file_handle = open(extra_file_name, 'r')
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   770
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   771
        # Format of data to return:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   772
        #   [(Cfiles, CFLAGS), ...], LDFLAGS, DoCalls, extra_files
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   773
        # LDFLAGS     = ['flag1', 'flag2', ...]
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   774
        # DoCalls     = true  or  false
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   775
        # extra_files = (fname,fobject), ...
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   776
        # fobject     = file object, already open'ed for read() !!
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   777
        #
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   778
        # extra_files -> files that will be downloaded to the PLC!
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   779
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   780
        websettingfile = open(paths.AbsNeighbourFile(__file__, "web_settings.py"), 'r')
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   781
        websettingcode = websettingfile.read()
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   782
        websettingfile.close()
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   783
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   784
        location_str = "_".join(map(str, self.GetCurrentLocation()))
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   785
        websettingcode = websettingcode % locals()
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   786
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   787
        runtimefile_path = os.path.join(buildpath, "runtime_bacnet_websettings.py")
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   788
        runtimefile = open(runtimefile_path, 'w')
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   789
        runtimefile.write(websettingcode)
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   790
        runtimefile.close()
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   791
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   792
        return ([(Generated_BACnet_c_mainfile_name, CFLAGS)], LDFLAGS, True,
2703
32ffdb32b14e Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents: 2669
diff changeset
   793
                ("runtime_%s_bacnet_websettings.py" % location_str, open(runtimefile_path, "rb")),
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2649
diff changeset
   794
        )
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents: 2425
diff changeset
   795
        #return [(Generated_BACnet_c_mainfile_name, CFLAGS)], LDFLAGS, True, ('extrafile1.txt', extra_file_handle)