bacnet/web_settings.py
author Edouard Tisserant
Tue, 16 Jun 2020 10:12:21 +0200
changeset 2675 3ca5611d6308
parent 2674 a8975ff44cd1
child 2676 b276d05bdb09
permissions -rw-r--r--
Modbus: Delete stored configuration when identical to default configuration.
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    37
GetParamFuncs = {}
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    38
SetParamFuncs = {}
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)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    44
_DefaultConfiguration = None
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.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    55
_WebviewConfiguration = None
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    60
# web interface (only shown if _SavedConfiguration is not None)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
    61
_SavedConfiguration = None
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   102
def _CheckPortnumber(port_number):
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   115
def _CheckDeviceID(device_id):
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   136
def _CheckConfiguration(BACnetConfig):
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   137
    res = True    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   138
    res = res and _CheckPortnumber(BACnetConfig["port_number"])
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   139
    res = res and _CheckDeviceID  (BACnetConfig["device_id"])
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   144
def _CheckWebConfiguration(BACnetConfig):
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   148
    if not _CheckPortnumber(BACnetConfig["port_number"]):
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
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   154
    if not _CheckDeviceID(BACnetConfig["device_id"]):
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   167
def _SetSavedConfiguration(BACnetConfig):
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 """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   169
    global _SavedConfiguration
2674
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   170
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   171
    if BACnetConfig == _DefaultConfiguration :
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   172
        _DelSavedConfiguration()
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   173
        _SavedConfiguration = None
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)
a8975ff44cd1 BACnet: prevent saving configuration that is same as default, delete it if so.
Edouard Tisserant
parents: 2673
diff changeset
   177
        _SavedConfiguration = BACnetConfig
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   178
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   179
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   180
def _DelSavedConfiguration():
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   186
def _GetSavedConfiguration():
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   197
    if _CheckConfiguration(saved_config):
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   203
def _GetPLCConfiguration():
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:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   210
        value = GetParamFuncs[par_name]()
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   217
def _SetPLCConfiguration(BACnetConfig):
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]
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   224
        #PLCObject.LogMessage("BACnet web server extension::_SetPLCConfiguration()  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:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   227
            SetParamFuncs[par_name](value)
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   229
    global _WebviewConfiguration 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   230
    _WebviewConfiguration = _GetPLCConfiguration()
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   231
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   232
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   233
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   234
def _GetWebviewConfigurationValue(ctx, argument):
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:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   240
        return _WebviewConfiguration[argument.name]
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   246
webFormInterface = [(name, web_dtype (label=web_label, default=_GetWebviewConfigurationValue)) 
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   250
def OnButtonSave(**kwargs):
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
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   257
    #PLCObject.LogMessage("BACnet web server extension::OnButtonSave()  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.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   267
    if not _CheckWebConfiguration(newConfig):
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)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   273
    _SetSavedConfiguration(newConfig)
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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   276
    _SetPLCConfiguration(newConfig)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   277
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
   278
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
   279
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
   280
def OnButtonReset(**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
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   288
    _DelSavedConfiguration()
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)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   290
    _SetPLCConfiguration(_DefaultConfiguration)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   291
    # Reset global variable
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   292
    global _SavedConfiguration
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   293
    _SavedConfiguration = 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
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   298
def _runtime_bacnet_websettings_%(location_str)s_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
        
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   318
        GetParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, GetParamFuncName)
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   319
        GetParamFuncs[name].restype  = c_dtype
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   320
        GetParamFuncs[name].argtypes = None
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   321
        
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   322
        SetParamFuncs[name]          = getattr(PLCObject.PLClibraryHandle, SetParamFuncName)
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   323
        SetParamFuncs[name].restype  = None
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   324
        SetParamFuncs[name].argtypes = [c_dtype]
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   325
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   326
    # 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
   327
    # 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
   328
    # 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
   329
    # get changed by the user using the web server, or by the call (further on)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   330
    # to _SetPLCConfiguration(SavedConfiguration)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   331
    global _DefaultConfiguration 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   332
    _DefaultConfiguration = _GetPLCConfiguration()
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   333
    
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   334
    # Show the current PLC configuration on the web interface        
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   335
    global _WebviewConfiguration
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   336
    _WebviewConfiguration = _GetPLCConfiguration()
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   337
 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   338
    # 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
   339
    # 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
   340
    # 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
   341
    # 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
   342
    # 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
   343
    # 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
   344
    #
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   345
    # Note that _SetPLCConfiguration() will also update 
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   346
    # _WebviewConfiguration , if necessary.
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   347
    global _SavedConfiguration
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   348
    _SavedConfiguration  = _GetSavedConfiguration()
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   349
    if _SavedConfiguration is not None:
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   350
        if _CheckConfiguration(_SavedConfiguration):
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   351
            _SetPLCConfiguration(_SavedConfiguration)
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   352
            
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
   353
    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
   354
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   355
    # 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
   356
    WebSettings.addSettings(
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   357
        "BACnetConfigParm",                # name
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   358
        _("BACnet Configuration"),         # description
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   359
        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
   360
        _("Apply"),  # button label
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   361
        OnButtonSave)                      # 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
   362
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
   363
    # 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
   364
    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
   365
        "BACnetConfigDelSaved",                   # name
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   366
        _("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
   367
        [ ("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
   368
           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
   369
                           immutable=True,
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
                           default=lambda *k:getConfigStatus())),
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
        ],                                       # 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
   372
        _("Reset"), # button label
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
        OnButtonReset) 
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
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
   375
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
   376
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
   377
def getConfigStatus():
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
   378
    if _WebviewConfiguration == _DefaultConfiguration :
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
   379
        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
   380
    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
   381
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
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
# location_str is replaced by extension's value in CTNGenerateC call
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   384
def _runtime_bacnet_websettings_%(location_str)s_cleanup():
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   385
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   386
    # 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
   387
    """
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   388
2669
be233279d179 BACnet and Modbus: Remove additional loading and unloading, use the one already in place for extensions.
Edouard Tisserant
parents: 2667
diff changeset
   389
    #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
   390
    
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
   391
    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
   392
    
2649
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   393
    GetParamFuncs = {}
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   394
    SetParamFuncs = {}
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   395
    _WebviewConfiguration = None
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   396
    _SavedConfiguration   = None
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   397
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   398
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   399
db68cb0e6bdc BACnet plugin: Add web interface for online parameter configuration
Mario de Sousa <msousa@fe.up.pt>
parents:
diff changeset
   400