bacnet/web_settings.py
author usveticic
Wed, 05 Aug 2020 15:04:53 +0200
branchsvghmi
changeset 3009 7c6960f09881
parent 2993 b76f303ffce6
permissions -rw-r--r--
Reworked button widget so it uses classes.
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     1
#!/usr/bin/env python
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     3
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     4
# This file is part of Beremiz runtime.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     5
#
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     6
# Copyright (C) 2020: Mario de Sousa
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     7
#
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     8
# See COPYING.Runtime file for copyrights details.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
     9
#
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    10
# This library is free software; you can redistribute it and/or
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    11
# modify it under the terms of the GNU Lesser General Public
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    12
# License as published by the Free Software Foundation; either
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    13
# version 2.1 of the License, or (at your option) any later version.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    14
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    15
# This library is distributed in the hope that it will be useful,
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    18
# Lesser General Public License for more details.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    19
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    20
# You should have received a copy of the GNU Lesser General Public
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    21
# License along with this library; if not, write to the Free Software
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    22
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    23
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    24
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    25
import json
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    26
import os
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    27
import ctypes
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    28
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    29
from formless import annotate, webform
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    30
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
    31
import runtime.NevowServer as NS
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    32
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    33
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    34
# Will contain references to the C functions 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    35
# (implemented in beremiz/bacnet/runtime/server.c)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    36
# used to get/set the BACnet specific configuration paramters
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
    37
BacnetGetParamFuncs = {}
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
    38
BacnetSetParamFuncs = {}
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    39
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    40
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    41
# Upon PLC load, this Dictionary is initialised with the BACnet configuration
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    42
# hardcoded in the C file
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    43
# (i.e. the configuration inserted in Beremiz IDE when project was compiled)
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
    44
_BacnetDefaultConfiguration = None
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    45
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    46
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    47
# Dictionary that contains the BACnet configuration currently being shown
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    48
# on the web interface
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    49
# This configuration will almost always be identical to the current
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    50
# configuration in the PLC (i.e., the current state stored in the 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    51
# C variables in the .so file).
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    52
# The configuration viewed on the web will only be different to the current 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    53
# configuration when the user edits the configuration, and when
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    54
# the user asks to save the edited configuration but it contains an error.
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
    55
_BacnetWebviewConfiguration = None
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    56
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    57
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    58
# Dictionary that stores the BACnet configuration currently stored in a file
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    59
# Currently only used to decide whether or not to show the "Delete" button on the
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
    60
# web interface (only shown if _BacnetSavedConfiguration is not None)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
    61
_BacnetSavedConfiguration = None
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    62
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    63
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    64
# File to which the new BACnet configuration gets stored on the PLC
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    65
# Note that the stored configuration is likely different to the
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    66
# configuration hardcoded in C generated code (.so file), so
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    67
# this file should be persistent across PLC reboots so we can
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    68
# re-configure the PLC (change values of variables in .so file)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    69
# before it gets a chance to start running
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    70
#
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    71
#_BACnetConfFilename = None
2673
80e7eb44cab4 BACnet and Modbus : fix configuration storage directory
Edouard Tisserant
parents: 2672
diff changeset
    72
_BACnetConfFilename = os.path.join(WorkingDir, "bacnetconf.json")
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    73
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    74
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    75
2667
253110ba0fd7 Bacnet plugin web configuration: strip leading and trailing spaces for net. interface and port numb.
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
    76
class BN_StrippedString(annotate.String):
253110ba0fd7 Bacnet plugin web configuration: strip leading and trailing spaces for net. interface and port numb.
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
    77
    def __init__(self, *args, **kwargs):
253110ba0fd7 Bacnet plugin web configuration: strip leading and trailing spaces for net. interface and port numb.
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
    78
        annotate.String.__init__(self, strip = True, *args, **kwargs)
253110ba0fd7 Bacnet plugin web configuration: strip leading and trailing spaces for net. interface and port numb.
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
    79
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    80
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    81
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    82
BACnet_parameters = [
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    83
    #    param. name             label                                            ctype type      annotate type
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    84
    # (C code var name)         (used on web interface)                          (C data type)    (web data type)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    85
    #                                                                                             (annotate.String,
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    86
    #                                                                                              annotate.Integer, ...)
2667
253110ba0fd7 Bacnet plugin web configuration: strip leading and trailing spaces for net. interface and port numb.
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
    87
    ("network_interface"      , _("Network Interface")                         , ctypes.c_char_p, BN_StrippedString),
253110ba0fd7 Bacnet plugin web configuration: strip leading and trailing spaces for net. interface and port numb.
Mario de Sousa <msousa@fe.up.pt>
parents: 2649
diff changeset
    88
    ("port_number"            , _("UDP Port Number")                           , ctypes.c_char_p, BN_StrippedString),
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    89
    ("comm_control_passwd"    , _("BACnet Communication Control Password")     , ctypes.c_char_p, annotate.String),
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    90
    ("device_id"              , _("BACnet Device ID")                          , ctypes.c_int,    annotate.Integer),
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    91
    ("device_name"            , _("BACnet Device Name")                        , ctypes.c_char_p, annotate.String),
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    92
    ("device_location"        , _("BACnet Device Location")                    , ctypes.c_char_p, annotate.String),
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    93
    ("device_description"     , _("BACnet Device Description")                 , ctypes.c_char_p, annotate.String),
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    94
    ("device_appsoftware_ver" , _("BACnet Device Application Software Version"), ctypes.c_char_p, annotate.String)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    95
    ]
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    96
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    97
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    98
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    99
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   100
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   101
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   102
def _CheckBacnetPortnumber(port_number):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   103
    """ check validity of the port number """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   104
    try:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   105
        portnum = int(port_number)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   106
        if (portnum < 0) or (portnum > 65535):
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   107
           raise Exception
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   108
    except Exception:    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   109
        return False
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   110
        
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   111
    return True    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   112
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   113
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   114
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   115
def _CheckBacnetDeviceID(device_id):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   116
    """ 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   117
    # check validity of the Device ID 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   118
    # NOTE: BACnet device (object) IDs are 22 bits long (not counting the 10 bits for the type ID)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   119
    #       so the Device instance ID is limited from 0 to 22^2-1 = 4194303
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   120
    #       However, 4194303 is reserved for special use (similar to NULL pointer), so last
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   121
    #       valid ID becomes 4194302
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   122
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   123
    try:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   124
        devid = int(device_id)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   125
        if (devid < 0) or (devid > 4194302):
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   126
            raise Exception
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   127
    except Exception:    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   128
        return False
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   129
        
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   130
    return True    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   131
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   132
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   133
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   134
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   135
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   136
def _CheckBacnetConfiguration(BACnetConfig):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   137
    res = True    
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   138
    res = res and _CheckBacnetPortnumber(BACnetConfig["port_number"])
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   139
    res = res and _CheckBacnetDeviceID  (BACnetConfig["device_id"])
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   140
    return res
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   141
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   142
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   143
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   144
def _CheckBacnetWebConfiguration(BACnetConfig):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   145
    res = True
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   146
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   147
    # check the port number
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   148
    if not _CheckBacnetPortnumber(BACnetConfig["port_number"]):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   149
        raise annotate.ValidateError(
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   150
            {"port_number": "Invalid port number: " + str(BACnetConfig["port_number"])},
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   151
            _("BACnet configuration error:"))
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   152
        res = False
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   153
    
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   154
    if not _CheckBacnetDeviceID(BACnetConfig["device_id"]):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   155
        raise annotate.ValidateError(
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   156
            {"device_id": "Invalid device ID: " + str(BACnetConfig["device_id"])},
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   157
            _("BACnet configuration error:"))
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   158
        res = False
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   159
        
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   160
    return res
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   161
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   162
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   163
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   164
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   165
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   166
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   167
def _SetBacnetSavedConfiguration(BACnetConfig):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   168
    """ Stores in a file a dictionary containing the BACnet parameter configuration """
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   169
    global _BacnetSavedConfiguration
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   170
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   171
    if BACnetConfig == _BacnetDefaultConfiguration :
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   172
        _DelBacnetSavedConfiguration()
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   173
        _BacnetSavedConfiguration = None
2674
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   174
    else :
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   175
        with open(os.path.realpath(_BACnetConfFilename), 'w') as f:
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   176
            json.dump(BACnetConfig, f, sort_keys=True, indent=4)
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   177
        _BacnetSavedConfiguration = BACnetConfig
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   178
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   179
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   180
def _DelBacnetSavedConfiguration():
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   181
    """ Deletes the file cotaining the persistent BACnet configuration """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   182
    if os.path.exists(_BACnetConfFilename):
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   183
        os.remove(_BACnetConfFilename)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   184
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   185
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   186
def _GetBacnetSavedConfiguration():
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   187
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   188
    # Returns a dictionary containing the BACnet parameter configuration
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   189
    # that was last saved to file. If no file exists, then return None
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   190
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   191
    try:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   192
        #if os.path.isfile(_BACnetConfFilename):
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   193
        saved_config = json.load(open(_BACnetConfFilename))
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   194
    except Exception:    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   195
        return None
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   196
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   197
    if _CheckBacnetConfiguration(saved_config):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   198
        return saved_config
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   199
    else:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   200
        return None
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   201
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   202
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   203
def _GetBacnetPLCConfiguration():
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   204
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   205
    # Returns a dictionary containing the current BACnet parameter configuration
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   206
    # stored in the C variables in the loaded PLC (.so file)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   207
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   208
    current_config = {}
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   209
    for par_name, x1, x2, x3 in BACnet_parameters:
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   210
        value = BacnetGetParamFuncs[par_name]()
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   211
        if value is not None:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   212
            current_config[par_name] = value
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   213
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   214
    return current_config
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   215
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   216
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   217
def _SetBacnetPLCConfiguration(BACnetConfig):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   218
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   219
    # Stores the BACnet parameter configuration into the
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   220
    # the C variables in the loaded PLC (.so file)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   221
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   222
    for par_name in BACnetConfig:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   223
        value = BACnetConfig[par_name]
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   224
        #PLCObject.LogMessage("BACnet web server extension::_SetBacnetPLCConfiguration()  Setting "
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   225
        #                       + par_name + " to " + str(value) )
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   226
        if value is not None:
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   227
            BacnetSetParamFuncs[par_name](value)
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   228
    # update the configuration shown on the web interface
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   229
    global _BacnetWebviewConfiguration 
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   230
    _BacnetWebviewConfiguration = _GetBacnetPLCConfiguration()
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   231
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   232
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   233
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   234
def _GetBacnetWebviewConfigurationValue(ctx, argument):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   235
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   236
    # Callback function, called by the web interface (NevowServer.py)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   237
    # to fill in the default value of each parameter
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   238
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   239
    try:
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   240
        return _BacnetWebviewConfiguration[argument.name]
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   241
    except Exception:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   242
        return ""
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   243
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   244
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   245
# The configuration of the web form used to see/edit the BACnet parameters
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   246
webFormInterface = [(name, web_dtype (label=web_label, default=_GetBacnetWebviewConfigurationValue)) 
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   247
                    for name, web_label, c_dtype, web_dtype in BACnet_parameters]
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   248
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   249
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   250
def OnBacnetButtonSave(**kwargs):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   251
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   252
    # Function called when user clicks 'Save' button in web interface
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   253
    # The function will configure the BACnet plugin in the PLC with the values
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   254
    # specified in the web interface. However, values must be validated first!
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   255
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   256
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   257
    #PLCObject.LogMessage("BACnet web server extension::OnBacnetButtonSave()  Called")
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   258
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   259
    newConfig = {}
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   260
    for par_name, x1, x2, x3 in BACnet_parameters:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   261
        value = kwargs.get(par_name, None)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   262
        if value is not None:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   263
            newConfig[par_name] = value
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   264
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   265
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   266
    # First check if configuration is OK.
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   267
    if not _CheckBacnetWebConfiguration(newConfig):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   268
        return
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   269
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   270
    # store to file the new configuration so that 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   271
    # we can recoup the configuration the next time the PLC
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   272
    # has a cold start (i.e. when Beremiz_service.py is retarted)
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   273
    _SetBacnetSavedConfiguration(newConfig)
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   274
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   275
    # Configure PLC with the current BACnet parameters
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   276
    _SetBacnetPLCConfiguration(newConfig)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   277
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   278
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   279
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   280
def OnBacnetButtonReset(**kwargs):
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   281
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   282
    # Function called when user clicks 'Delete' button in web interface
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   283
    # The function will delete the file containing the persistent
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   284
    # BACnet configution
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   285
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   286
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   287
    # Delete the file
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   288
    _DelBacnetSavedConfiguration()
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   289
    # Set the current configuration to the default (hardcoded in C)
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   290
    _SetBacnetPLCConfiguration(_BacnetDefaultConfiguration)
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   291
    # Reset global variable
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   292
    global _BacnetSavedConfiguration
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   293
    _BacnetSavedConfiguration = None
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   294
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   295
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   296
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   297
# location_str is replaced by extension's value in CTNGenerateC call
2993
b76f303ffce6 Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents: 2686
diff changeset
   298
def _runtime_%(location_str)s_bacnet_websettings_init():
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   299
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   300
    # Callback function, called (by PLCObject.py) when a new PLC program
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   301
    # (i.e. XXX.so file) is transfered to the PLC runtime
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   302
    # and oaded into memory
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   303
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   304
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   305
    #PLCObject.LogMessage("BACnet web server extension::OnLoadPLC() Called...")
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   306
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   307
    if PLCObject.PLClibraryHandle is None:
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   308
        # PLC was loaded but we don't have access to the library of compiled code (.so lib)?
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   309
        # Hmm... This shold never occur!! 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   310
        return  
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   311
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   312
    # Map the get/set functions (written in C code) we will be using to get/set the configuration parameters
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   313
    for name, web_label, c_dtype, web_dtype in BACnet_parameters:
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   314
        # location_str is replaced by extension's value in CTNGenerateC call
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   315
        GetParamFuncName = "__bacnet_%(location_str)s_get_ConfigParam_" + name
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   316
        SetParamFuncName = "__bacnet_%(location_str)s_set_ConfigParam_" + name
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   317
        
2676
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2674
diff changeset
   318
        # XXX TODO : stop reading from PLC .so file. This code is template code
b276d05bdb09 Modbus/BACnet : add some comments so that we don't forget some pending optimization.
Edouard Tisserant
parents: 2674
diff changeset
   319
        #            that can use modbus extension build data
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   320
        BacnetGetParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, GetParamFuncName)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   321
        BacnetGetParamFuncs[name].restype  = c_dtype
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   322
        BacnetGetParamFuncs[name].argtypes = None
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   323
        
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   324
        BacnetSetParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, SetParamFuncName)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   325
        BacnetSetParamFuncs[name].restype  = None
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   326
        BacnetSetParamFuncs[name].argtypes = [c_dtype]
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   327
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   328
    # Default configuration is the configuration done in Beremiz IDE
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   329
    # whose parameters get hardcoded into C, and compiled into the .so file
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   330
    # We read the default configuration from the .so file before the values
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   331
    # get changed by the user using the web server, or by the call (further on)
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   332
    # to _SetBacnetPLCConfiguration(BacnetSavedConfiguration)
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   333
    global _BacnetDefaultConfiguration 
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   334
    _BacnetDefaultConfiguration = _GetBacnetPLCConfiguration()
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   335
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   336
    # Show the current PLC configuration on the web interface        
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   337
    global _BacnetWebviewConfiguration
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   338
    _BacnetWebviewConfiguration = _GetBacnetPLCConfiguration()
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   339
 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   340
    # Read from file the last used configuration, which is likely
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   341
    # different to the hardcoded configuration.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   342
    # We Reset the current configuration (i.e., the config stored in the 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   343
    # variables of .so file) to this saved configuration
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   344
    # so the PLC will start off with this saved configuration instead
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   345
    # of the hardcoded (in Beremiz C generated code) configuration values.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   346
    #
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   347
    # Note that _SetBacnetPLCConfiguration() will also update 
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   348
    # _BacnetWebviewConfiguration , if necessary.
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   349
    global _BacnetSavedConfiguration
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   350
    _BacnetSavedConfiguration  = _GetBacnetSavedConfiguration()
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   351
    if _BacnetSavedConfiguration is not None:
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   352
        if _CheckBacnetConfiguration(_BacnetSavedConfiguration):
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   353
            _SetBacnetPLCConfiguration(_BacnetSavedConfiguration)
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   354
            
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   355
    WebSettings = NS.newExtensionSetting("BACnet extension", "bacnet_token")
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   356
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   357
    # Configure the web interface to include the BACnet config parameters
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   358
    WebSettings.addSettings(
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   359
        "BACnetConfigParm",                # name
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   360
        _("BACnet Configuration"),         # description
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   361
        webFormInterface,                  # fields
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   362
        _("Apply"),  # button label
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   363
        OnBacnetButtonSave)                      # callback    
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   364
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   365
    # Add the Delete button to the web interface
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   366
    WebSettings.addSettings(
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   367
        "BACnetConfigDelSaved",                   # name
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   368
        _("BACnet Configuration"),                # description
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   369
        [ ("status",
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   370
           annotate.String(label=_("Current state"),
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   371
                           immutable=True,
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   372
                           default=lambda *k:getBacnetConfigStatus())),
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   373
        ],                                       # fields  (empty, no parameters required!)
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   374
        _("Reset"), # button label
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   375
        OnBacnetButtonReset) 
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   376
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   377
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   378
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   379
def getBacnetConfigStatus():
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   380
    if _BacnetWebviewConfiguration == _BacnetDefaultConfiguration :
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   381
        return "Unchanged"
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   382
    return "Modified"
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   383
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   384
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   385
# location_str is replaced by extension's value in CTNGenerateC call
2993
b76f303ffce6 Python Runtime: order of execution of extension's init() and cleanup() now reflects order of appearance of extensions in configuration tree.
Edouard Tisserant
parents: 2686
diff changeset
   386
def _runtime_%(location_str)s_bacnet_websettings_cleanup():
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   387
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   388
    # Callback function, called (by PLCObject.py) when a PLC program is unloaded from memory
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   389
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   390
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   391
    #PLCObject.LogMessage("BACnet web server extension::OnUnLoadPLC() Called...")
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   392
    
2672
4bc60e426dd6 Runtime extrension web settings: distinguish display string and token when calling NS.newExtensionSetting, thus allowing meaningful name to be displayed instead of an id.
Edouard Tisserant
parents: 2670
diff changeset
   393
    NS.removeExtensionSetting("bacnet_token")
2670
fd348d79a1f3 BACnet and Modbus : Simpler configuration management. NevowServer.py now allows each extension to create and delete multiple configuration forms in the setting page, deprecating delSettings and addAfter.
Edouard Tisserant
parents: 2669
diff changeset
   394
    
2686
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   395
    BacnetGetParamFuncs = {}
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   396
    BacnetSetParamFuncs = {}
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   397
    _BacnetWebviewConfiguration = None
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   398
    _BacnetSavedConfiguration   = None
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   399
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   400
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   401
703ebf57508a Modbus and Bacnet websettings : Rename variables and functions to avoid name collisions.
Edouard Tisserant
parents: 2676
diff changeset
   402