LPCBeremiz.py
author Edouard Tisserant
Mon, 07 May 2012 19:19:08 +0200
changeset 718 5d4dc150b956
parent 717 1c23952dbde1
child 721 ecf4d203c4d4
permissions -rw-r--r--
refactoring
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     1
#!/usr/bin/env python
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
     3
import shutil
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
     4
import socket
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     5
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     6
__version__ = "$Revision$"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     7
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     8
import os, sys, getopt, wx, tempfile
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
     9
import __builtin__
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    10
from types import TupleType, StringType, UnicodeType
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    11
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    12
CWD = os.path.split(os.path.realpath(__file__))[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    13
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    14
def Bpath(*args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    15
    return os.path.join(CWD,*args)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    16
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    17
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    18
    def usage():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    19
        print "\nUsage of LPCBeremiz.py :"
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    20
        print "\n   %s Projectpath Buildpath port\n"%sys.argv[0]
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    21
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    22
    try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    23
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    24
    except getopt.GetoptError:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    25
        # print help information and exit:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    26
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    27
        sys.exit(2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    28
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    29
    for o, a in opts:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    30
        if o in ("-h", "--help"):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    31
            usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    32
            sys.exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    33
    
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    34
    if len(args) != 3:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    35
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    36
        sys.exit()
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    37
    else:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    38
        projectOpen = args[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    39
        buildpath = args[1]
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    40
        try:
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    41
            port = int(args[2])
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    42
        except:
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    43
            usage()
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    44
            sys.exit()
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
    45
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
    46
    if os.path.exists("LPC_DEBUG"):
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
    47
        __builtin__.__dict__["BMZ_DBG"] = True
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
    48
    else :
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
    49
        __builtin__.__dict__["BMZ_DBG"] = False
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
    50
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
    51
app = wx.PySimpleApp(redirect=BMZ_DBG)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
    52
app.SetAppName('beremiz')
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
    53
wx.InitAllImageHandlers()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    54
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    55
# Import module for internationalization
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    56
import gettext
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    57
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    58
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    59
    __builtin__.__dict__['_'] = wx.GetTranslation#unicode_translation
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    60
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    61
from Beremiz import *
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
    62
from ConfigTree import ConfigTreeRoot, ConfigTreeNode, opjimg, connectors
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    63
from plcopen.structures import LOCATIONDATATYPES
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
    64
from PLCControler import LOCATION_CONFNODE, LOCATION_MODULE, LOCATION_GROUP,\
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    65
                         LOCATION_VAR_INPUT, LOCATION_VAR_OUTPUT, LOCATION_VAR_MEMORY
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
    66
from PLCOpenEditor import IDEFrame, ProjectDialog
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    67
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
    68
havecanfestival = False
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
    69
try:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
    70
    from confnodes.canfestival import RootClass as CanOpenRootClass
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
    71
    from confnodes.canfestival.canfestival import _SlaveCTN, _NodeListCTN, NodeManager
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
    72
    havecanfestival = True
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
    73
except:
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
    74
    havecanfestival = False
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
    75
    
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
    76
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    77
#-------------------------------------------------------------------------------
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
    78
#                          CANFESTIVAL CONFNODE HACK
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    79
#-------------------------------------------------------------------------------
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
    80
# from confnodes.canfestival import canfestival
629
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    81
# class LPC_canfestival_config:
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    82
#     def getCFLAGS(self, *args):
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    83
#         return ""
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    84
# 
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    85
#     def getLDFLAGS(self, *args):
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    86
#         return ""
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    87
#         
61347cc521d1 fix unnecessary CanFestival plugin load in lpcberemiz
Edouard Tisserant
parents: 625
diff changeset
    88
# canfestival.local_canfestival_config = LPC_canfestival_config() 
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    89
#-------------------------------------------------------------------------------
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    90
#                              LPCModule Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    91
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    92
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    93
LOCATION_TYPES = {"I": LOCATION_VAR_INPUT,
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    94
                  "Q": LOCATION_VAR_OUTPUT,
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    95
                  "M": LOCATION_VAR_MEMORY}
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    96
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    97
LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()])
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    98
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    99
LOCATION_SIZES = {}
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   100
for size, types in LOCATIONDATATYPES.iteritems():
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   101
    for type in types:
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   102
        LOCATION_SIZES[type] = size
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   103
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   104
def _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   105
    children = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   106
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   107
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   108
            children.extend(child["children"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   109
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   110
            children.append(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   111
    return children
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   112
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   113
def _GetVariables(module):
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   114
    variables = []
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   115
    for child in module["children"]:
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   116
        if child["type"] in [LOCATION_GROUP, LOCATION_MODULE]:
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   117
            variables.extend(_GetVariables(child))
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   118
        else:
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   119
            variables.append(child)
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   120
    return variables
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   121
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   122
def _GetLastModuleGroup(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   123
    group = module
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   124
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   125
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   126
            group = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   127
    return group["children"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   128
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   129
def _GetModuleBySomething(module, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   130
    for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   131
        if child.get(something) == toks[0]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   132
            if len(toks) > 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   133
                return _GetModuleBySomething(child, something, toks[1:])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   134
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   135
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   136
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   137
def _GetModuleVariable(module, location, direction):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   138
    for child in _GetModuleChildren(module):
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   139
        if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   140
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   141
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   142
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   143
def _RemoveModuleChild(module, child):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   144
    if child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   145
        module["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   146
    else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   147
        for group in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   148
            if group["type"] == LOCATION_GROUP and child in group["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   149
                group["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   150
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   151
BUS_TEXT = """/* Code generated by LPCBus confnode */
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   152
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   153
/* LPCBus confnode includes */
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   154
#include "app_glue.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   155
#ifdef _WINDOWS_H
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   156
  #include "iec_types.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   157
#else
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   158
  #include "iec_std_lib.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   159
#endif
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   160
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   161
%(declare_code)s
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   162
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   163
/* LPCBus confnode user variables definition */
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   164
%(var_decl)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   165
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   166
/* LPCBus confnode functions */
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   167
int __init_%(location_str)s(int argc,char **argv)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   168
{
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   169
%(init_code)s
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   170
  return 0;
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   171
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   172
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   173
void __cleanup_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   174
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   175
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   176
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   177
void __retrieve_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   178
{
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   179
%(retrieve_code)s
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   180
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   181
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   182
void __publish_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   183
{
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   184
%(publish_code)s
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   185
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   186
"""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   187
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   188
class LPCBus(object):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   189
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   190
    def __init__(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   191
        self.VariableLocationTree = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   192
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   193
        self.Icon = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   194
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   195
    def __getitem__(self, key):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   196
        if key == "children":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   197
            return self.VariableLocationTree
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   198
        raise KeyError, "Only 'children' key is available"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   199
    
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   200
    def CTNEnabled(self):
682
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   201
        return None
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   202
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   203
    def SetIcon(self, icon):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   204
        self.Icon = icon
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   205
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   206
    def _GetChildBySomething(self, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   207
        return _GetModuleBySomething({"children" : self.VariableLocationTree}, something, toks)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   208
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   209
    def GetBaseTypes(self):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   210
        return self.GetCTRoot().GetBaseTypes()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   211
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   212
    def GetSizeOfType(self, type):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   213
        return LOCATION_SIZES[self.GetCTRoot().GetBaseType(type)]
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   214
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   215
    def _GetVariableLocationTree(self, current_location, infos):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   216
        if infos["type"] == LOCATION_MODULE:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   217
            location = current_location + (infos["IEC_Channel"],)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   218
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   219
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   220
                    "location": ".".join(map(str, location + ("x",))), 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   221
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   222
                    "children": [self._GetVariableLocationTree(location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   223
        elif infos["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   224
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   225
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   226
                    "location": "", 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   227
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   228
                    "children": [self._GetVariableLocationTree(current_location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   229
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   230
            size = self.GetSizeOfType(infos["IEC_type"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   231
            location = "%" + LOCATION_DIRS[infos["type"]] + size + ".".join(map(str, current_location + infos["location"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   232
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   233
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   234
                    "size": size,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   235
                    "IEC_type": infos["IEC_type"],
659
71a824446673 Adding support for drag'n dropping located variables from topology panel to configurations and resources variable panel for declaring global located variables
laurent
parents: 652
diff changeset
   236
                    "var_name": infos["name"],
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   237
                    "location": location,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   238
                    "description": infos["description"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   239
                    "children": []}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   240
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   241
    def GetVariableLocationTree(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   242
        return {"name": self.BaseParams.getName(),
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   243
                "type": LOCATION_CONFNODE,
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   244
                "location": self.GetFullIEC_Channel(),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   245
                "icon": self.Icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   246
                "children": [self._GetVariableLocationTree(self.GetCurrentLocation(), child) 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   247
                             for child in self.VariableLocationTree]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   248
    
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   249
    def CTNTestModified(self):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   250
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   251
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   252
    def CTNMakeDir(self):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   253
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   254
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   255
    def CTNRequestSave(self):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   256
        return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   257
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   258
    def ResetUsedLocations(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   259
        self.UsedLocations = {}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   260
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   261
    def _AddUsedLocation(self, parent, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   262
        num = location.pop(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   263
        if not parent.has_key(num):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   264
            parent[num] = {"used": False, "children": {}}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   265
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   266
            self._AddUsedLocation(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   267
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   268
            parent[num]["used"] = True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   269
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   270
    def AddUsedLocation(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   271
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   272
            self._AddUsedLocation(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   273
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   274
    def _CheckLocationConflicts(self, parent, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   275
        num = location.pop(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   276
        if not parent.has_key(num):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   277
            return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   278
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   279
            if parent[num]["used"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   280
                return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   281
            return self._CheckLocationConflicts(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   282
        elif len(parent[num]["children"]) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   283
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   284
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   285
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   286
    def CheckLocationConflicts(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   287
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   288
            return self._CheckLocationConflicts(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   289
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   290
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   291
    def CTNGenerate_C(self, buildpath, locations):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   292
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   293
        Generate C code
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   294
        @param current_location: Tupple containing confnode IEC location : %I0.0.4.5 => (0,0,4,5)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   295
        @param locations: List of complete variables locations \
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   296
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   297
            "NAME" : name of the variable (generally "__IW0_1_2" style)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   298
            "DIR" : direction "Q","I" or "M"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   299
            "SIZE" : size "X", "B", "W", "D", "L"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   300
            "LOC" : tuple of interger for IEC location (0,1,2,...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   301
            }, ...]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   302
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   303
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   304
        current_location = self.GetCurrentLocation()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   305
        # define a unique name for the generated C file
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   306
        location_str = "_".join(map(str, current_location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   307
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   308
        code_str = {"location_str": location_str,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   309
                    "var_decl": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   310
                    "declare_code": "",
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   311
                    "init_code": "",
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   312
                    "retrieve_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   313
                    "publish_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   314
                   }
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   315
        
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   316
        for module in _GetModuleChildren(self):
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   317
            if module["init"] != "":
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   318
                code_str["init_code"] += "  %s\n" % module["init"]
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   319
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   320
        # Adding variables
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   321
        vars = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   322
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   323
        for location in locations:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   324
            loc = location["LOC"][len(current_location):]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   325
            group = next = self
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   326
            i = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   327
            while next is not None and i < len(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   328
                next = self._GetChildBySomething("IEC_Channel", loc[:i + 1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   329
                if next is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   330
                    i += 1
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   331
                    group = next
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   332
            var_loc = loc[i:]
530
862d9adcd904 Bug when trying to generate LPCBus code fixed
laurent
parents: 526
diff changeset
   333
            for variable in _GetModuleChildren(group):
566
657900299557 Fix bug in LPCBeremiz that use input retrieve and publish code for ouput with the same location
laurent
parents: 561
diff changeset
   334
                if variable["location"] == var_loc and location["DIR"] == LOCATION_DIRS[variable["type"]]:
543
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   335
#                    if location["DIR"] != LOCATION_DIRS[variable["type"]]:
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   336
#                        raise Exception, "Direction conflict in variable definition"
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   337
#                    if location["IEC_TYPE"] != variable["IEC_type"]:
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   338
#                        raise Exception, "Type conflict in variable definition"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   339
                    if location["DIR"] == "Q":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   340
                        if self.CheckLocationConflicts(location["LOC"]):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   341
                            raise Exception, "BYTE and BIT from the same BYTE can't be used together"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   342
                        self.AddUsedLocation(location["LOC"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   343
                    vars.append({"location": location["NAME"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   344
                                 "Type": variable["IEC_type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   345
                                 "Retrieve": variable["retrieve"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   346
                                 "Publish": variable["publish"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   347
                                })
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   348
                    break
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   349
        base_types = self.GetCTRoot().GetBaseTypes()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   350
        for var in vars:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   351
            prefix = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   352
            if var["Type"] in base_types:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   353
                prefix = "IEC_"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   354
            code_str["var_decl"] += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   355
            code_str["var_decl"] += "%s%s *%s = &beremiz%s;\n"%(prefix, var["Type"], var["location"], var["location"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   356
            if var["Retrieve"] != "":
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   357
                code_str["retrieve_code"] += "  " + var["Retrieve"] % ("*" + var["location"]) + "\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   358
            if var["Publish"] != "":
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   359
                code_str["publish_code"] += "  " + var["Publish"] % ("*" + var["location"]) + "\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   360
        
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   361
        Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   362
        module = open(Gen_Module_path,'w')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   363
        module.write(BUS_TEXT % code_str)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   364
        module.close()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   365
        
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   366
        matiec_flags = '"-I%s"'%os.path.abspath(self.GetCTRoot().GetIECLibPath())
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   367
        return [(Gen_Module_path, matiec_flags)],"",True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   368
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   369
#-------------------------------------------------------------------------------
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   370
#                          LPC CanFestival ConfNode Class
682
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   371
#-------------------------------------------------------------------------------
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   372
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   373
if havecanfestival:
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   374
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   375
    DEFAULT_SETTINGS = {
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   376
        "CAN_Baudrate": "125K",
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   377
        "Slave_NodeId": 2,
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   378
        "Master_NodeId": 1,
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   379
    }
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   380
    
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   381
    class LPCCanOpenSlave(_SlaveCTN):
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   382
        XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   383
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   384
          <xsd:element name="CanFestivalSlaveNode">
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   385
            <xsd:complexType>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   386
              <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   387
              <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Slave_NodeId)d"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   388
              <xsd:attribute name="Sync_Align" type="xsd:integer" use="optional" default="0"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   389
              <xsd:attribute name="Sync_Align_Ratio" use="optional" default="50">
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   390
                <xsd:simpleType>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   391
                    <xsd:restriction base="xsd:integer">
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   392
                        <xsd:minInclusive value="1"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   393
                        <xsd:maxInclusive value="99"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   394
                    </xsd:restriction>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   395
                </xsd:simpleType>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   396
              </xsd:attribute>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   397
            </xsd:complexType>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   398
          </xsd:element>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   399
        </xsd:schema>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   400
        """ % DEFAULT_SETTINGS
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   401
        
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   402
        def __init__(self):
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   403
            # TODO change netname when name change
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   404
            NodeManager.__init__(self)
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   405
            odfilepath = self.GetSlaveODPath()
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   406
            if(os.path.isfile(odfilepath)):
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   407
                self.OpenFileInCurrent(odfilepath)
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   408
            else:
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   409
                self.CreateNewNode("SlaveNode",  # Name - will be changed at build time
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   410
                                   0x00,         # NodeID - will be changed at build time
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   411
                                   "slave",      # Type
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   412
                                   "",           # description 
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   413
                                   "None",       # profile
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   414
                                   "", # prfile filepath
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   415
                                   "heartbeat",  # NMT
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   416
                                   [])           # options
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   417
                self.OnCTNSave()
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   418
        
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   419
        def GetCanDevice(self):
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   420
            return str(self.BaseParams.getIEC_Channel())
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   421
        
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   422
    class LPCCanOpenMaster(_NodeListCTN):
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   423
        XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   424
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   425
          <xsd:element name="CanFestivalNode">
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   426
            <xsd:complexType>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   427
              <xsd:attribute name="CAN_Baudrate" type="xsd:string" use="optional" default="%(CAN_Baudrate)s"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   428
              <xsd:attribute name="NodeId" type="xsd:string" use="optional" default="%(Master_NodeId)d"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   429
              <xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="optional" default="true"/>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   430
            </xsd:complexType>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   431
          </xsd:element>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   432
        </xsd:schema>
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   433
        """ % DEFAULT_SETTINGS
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   434
    
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   435
        def GetCanDevice(self):
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   436
            return str(self.BaseParams.getIEC_Channel())
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   437
    
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   438
    class LPCCanOpen(CanOpenRootClass):
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   439
        XSD = None
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   440
        CTNChildrenTypes = [("CanOpenNode",LPCCanOpenMaster, "CanOpen Master"),
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   441
                           ("CanOpenSlave",LPCCanOpenSlave, "CanOpen Slave")]
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   442
        
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   443
        def GetCanDriver(self):
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   444
            return ""
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   445
        
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   446
        def LoadChildren(self):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   447
            ConfigTreeNode.LoadChildren(self)
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   448
            
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   449
            if self.GetChildByName("Master") is None:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   450
                master = self.CTNAddChild("Master", "CanOpenNode", 0)
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   451
                master.BaseParams.setEnabled(False)
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   452
            
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   453
            if self.GetChildByName("Slave") is None:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   454
                slave = self.CTNAddChild("Slave", "CanOpenSlave", 1)
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   455
                slave.BaseParams.setEnabled(False)
682
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   456
    
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   457
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   458
#-------------------------------------------------------------------------------
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   459
#                              LPCConfigTreeRoot Class
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   460
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   461
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   462
def mycopytree(src, dst):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   463
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   464
    Copy content of a directory to an other, omit hidden files
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   465
    @param src: source directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   466
    @param dst: destination directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   467
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   468
    for i in os.listdir(src):
652
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   469
        if not i.startswith('.') and i != "pous.xml":
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   470
            srcpath = os.path.join(src,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   471
            dstpath = os.path.join(dst,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   472
            if os.path.isdir(srcpath):
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   473
                if os.path.exists(dstpath):
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   474
                    shutil.rmtree(dstpath)
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   475
                os.makedirs(dstpath)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   476
                mycopytree(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   477
            elif os.path.isfile(srcpath):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   478
                shutil.copy2(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   479
572
c965548cb6f7 Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents: 571
diff changeset
   480
[SIMULATION_MODE, TRANSFER_MODE] = range(2)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   481
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   482
class LPCConfigTreeRoot(ConfigTreeRoot):
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   483
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   484
    ConfNodeMethods = [
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   485
        {"bitmap" : opjimg("Debug"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   486
         "name" : _("Simulate"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   487
         "tooltip" : _("Simulate PLC"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   488
         "method" : "_Simulate"},
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   489
        {"bitmap" : opjimg("Run"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   490
         "name" : _("Run"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   491
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   492
         "tooltip" : _("Start PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   493
         "method" : "_Run"},
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   494
        {"bitmap" : opjimg("Stop"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   495
         "name" : _("Stop"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   496
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   497
         "tooltip" : _("Stop Running PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   498
         "method" : "_Stop"},
541
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   499
        {"bitmap" : opjimg("Build"),
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   500
         "name" : _("Build"),
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   501
         "tooltip" : _("Build project into build folder"),
625
08d4cc1ceb9b Fixed LPCBeremiz to refect recent root plugin build method name to change
Edouard Tisserant
parents: 599
diff changeset
   502
         "method" : "_Build"},
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   503
        {"bitmap" : opjimg("Transfer"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   504
         "name" : _("Transfer"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   505
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   506
         "tooltip" : _("Transfer PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   507
         "method" : "_Transfer"},
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   508
    ]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   509
652
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   510
    def __init__(self, frame, logger, buildpath):
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   511
        self.OrigBuildPath = buildpath
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   512
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   513
        ConfigTreeRoot.__init__(self, frame, logger)
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   514
        
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   515
        if havecanfestival:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   516
            self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus"), ("CanOpen", LPCCanOpen, "CanOpen bus")]
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   517
        else:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   518
            self.CTNChildrenTypes += [("LPCBus", LPCBus, "LPC bus")]
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   519
        self.CTNType = "LPC"
652
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   520
        
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   521
        self.OnlineMode = "OFF"
561
4cc6eef4778f Fix bug on LPCConnector initial value
laurent
parents: 560
diff changeset
   522
        self.LPCConnector = None
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   523
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   524
        self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   525
        self.previous_mode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   526
        
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   527
        self.SimulationBuildPath = None
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   528
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   529
        self.AbortTransferTimer = None
652
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   530
    
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   531
    def ConfNodeLibraryFilePath(self):
652
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   532
        if self.OrigBuildPath is not None:
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   533
            return os.path.join(self.OrigBuildPath, "pous.xml")
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   534
        else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   535
            return ConfigTreeRoot.ConfNodeLibraryFilePath(self)
652
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   536
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   537
    def GetProjectName(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   538
        return self.Project.getname()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   539
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   540
    def GetDefaultTargetName(self):
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   541
        if self.CurrentMode == SIMULATION_MODE:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   542
            return ConfigTreeRoot.GetDefaultTargetName(self)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   543
        else:
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   544
            return "LPC"
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   545
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   546
    def GetTarget(self):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   547
        target = ConfigTreeRoot.GetTarget(self)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   548
        if self.CurrentMode != SIMULATION_MODE:
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   549
            target.getcontent()["value"].setBuildPath(self.BuildPath)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   550
        return target
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   551
    
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   552
    def _getBuildPath(self):
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   553
        if self.CurrentMode == SIMULATION_MODE:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   554
            if self.SimulationBuildPath is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   555
                self.SimulationBuildPath = os.path.join(tempfile.mkdtemp(), os.path.basename(self.ProjectPath), "build")
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   556
            return self.SimulationBuildPath
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   557
        else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   558
            return ConfigTreeRoot._getBuildPath(self)
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   559
625
08d4cc1ceb9b Fixed LPCBeremiz to refect recent root plugin build method name to change
Edouard Tisserant
parents: 599
diff changeset
   560
    def _Build(self):
599
c7be4d09c5f4 Adding save project before building on LPCBeremiz
laurent
parents: 598
diff changeset
   561
        save = self.ProjectTestModified()
c7be4d09c5f4 Adding save project before building on LPCBeremiz
laurent
parents: 598
diff changeset
   562
        if save:
c7be4d09c5f4 Adding save project before building on LPCBeremiz
laurent
parents: 598
diff changeset
   563
            self.SaveProject()
c7be4d09c5f4 Adding save project before building on LPCBeremiz
laurent
parents: 598
diff changeset
   564
            self.AppFrame._Refresh(TITLE, FILEMENU)
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   565
        if self.BuildPath is not None:
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   566
            mycopytree(self.OrigBuildPath, self.BuildPath)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   567
        ConfigTreeRoot._Build(self)
599
c7be4d09c5f4 Adding save project before building on LPCBeremiz
laurent
parents: 598
diff changeset
   568
        if save:
c7be4d09c5f4 Adding save project before building on LPCBeremiz
laurent
parents: 598
diff changeset
   569
            wx.CallAfter(self.AppFrame.RefreshAll)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   570
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   571
    def SetProjectName(self, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   572
        return self.Project.setname(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   573
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   574
    def SetOnlineMode(self, mode, path=None):
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   575
        if self.OnlineMode != mode.upper():
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   576
            self.OnlineMode = mode.upper()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   577
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   578
            if self.OnlineMode != "OFF":
543
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   579
                uri = "LPC://%s/%s" % (self.OnlineMode,path)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   580
                try:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   581
                    self.LPCConnector = connectors.ConnectorFactory(uri, self)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   582
                except Exception, msg:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   583
                    self.logger.write_error(_("Exception while connecting %s!\n")%uri)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   584
                    self.logger.write_error(traceback.format_exc())
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   585
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   586
                # Did connection success ?
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   587
                if self.LPCConnector is None:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   588
                    # Oups.
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   589
                    self.logger.write_error(_("Connection failed to %s!\n")%uri)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   590
                
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   591
            else:
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   592
                self.LPCConnector = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   593
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   594
            self.ApplyOnlineMode()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   595
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   596
    def ApplyOnlineMode(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   597
        if self.CurrentMode != SIMULATION_MODE:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   598
            self.KillDebugThread()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   599
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   600
            self._connector = self.LPCConnector
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   601
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   602
            # Init with actual PLC status and print it
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   603
            self.UpdateMethodsFromPLCStatus()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   604
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   605
            if self.LPCConnector is not None and self.OnlineMode == "APPLICATION":
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   606
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   607
                self.CompareLocalAndRemotePLC()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   608
                            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   609
                if self.previous_plcstate is not None:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   610
                    status = _(self.previous_plcstate)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   611
                else:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   612
                    status = ""
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   613
                self.logger.write(_("PLC is %s\n")%status)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   614
                
575
6765adf58711 Removed status polling for LPC, as status cannot change by itself, fixed MD5 comparison in app mode
edouard
parents: 574
diff changeset
   615
                #if self.StatusTimer and not self.StatusTimer.IsRunning():
6765adf58711 Removed status polling for LPC, as status cannot change by itself, fixed MD5 comparison in app mode
edouard
parents: 574
diff changeset
   616
                #    # Start the status Timer
6765adf58711 Removed status polling for LPC, as status cannot change by itself, fixed MD5 comparison in app mode
edouard
parents: 574
diff changeset
   617
                #    self.StatusTimer.Start(milliseconds=2000, oneShot=False)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   618
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   619
                if self.previous_plcstate=="Started":
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   620
                    if self.DebugAvailable() and self.GetIECProgramsAndVariables():
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   621
                        self.logger.write(_("Debug connect matching running PLC\n"))
576
7fcdc0d3d8d9 Some typo fixes to make debug related methods in LPCAppOject stop throwing exceptions, less agressive error message when unplugging LPC
edouard
parents: 575
diff changeset
   622
                        self._connect_debug()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   623
                    else:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   624
                        self.logger.write_warning(_("Debug do not match PLC - stop/transfert/start to re-enable\n"))
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   625
            
543
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   626
            elif self.StatusTimer and self.StatusTimer.IsRunning():
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   627
                self.StatusTimer.Stop()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   628
            
572
c965548cb6f7 Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents: 571
diff changeset
   629
            if self.CurrentMode == TRANSFER_MODE:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   630
                
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   631
                if self.OnlineMode == "BOOTLOADER":
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   632
                    self.BeginTransfer()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   633
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   634
                elif self.OnlineMode == "APPLICATION":
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   635
                    self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   636
                    self.AbortTransferTimer.Stop()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   637
                    self.AbortTransferTimer = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   638
                    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   639
                    self.logger.write(_("PLC transferred successfully\n"))
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   640
    
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   641
    # Update a PLCOpenEditor Pou variable name
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   642
    def UpdateProjectVariableName(self, old_name, new_name):
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   643
        self.Project.updateElementName(old_name, new_name)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   644
        self.BufferProject()
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   645
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   646
    def RemoveProjectVariableByAddress(self, address):
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   647
        self.Project.removeVariableByAddress(address)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   648
        self.BufferProject()
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   649
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   650
    def RemoveProjectVariableByFilter(self, leading):
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   651
        self.Project.removeVariableByFilter(leading)
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   652
        self.BufferProject()
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
   653
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   654
    def LoadProject(self, ProjectPath, BuildPath=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   655
        """
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   656
        Load a project contained in a folder
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   657
        @param ProjectPath: path of the project folder
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   658
        """
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   659
        if os.path.basename(ProjectPath) == "":
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   660
            ProjectPath = os.path.dirname(ProjectPath)
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   661
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   662
        # Verify that project contains a PLCOpen program
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   663
        plc_file = os.path.join(ProjectPath, "plc.xml")
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   664
        if os.path.isfile(plc_file):
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   665
            # Load PLCOpen file
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   666
            result = self.OpenXMLFile(plc_file)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   667
            if result:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   668
                return result
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   669
        else:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   670
            self.CreateNewProject({"companyName": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   671
                                   "productName": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   672
                                   "productVersion": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   673
                                   "projectName": "",
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   674
                                   "pageSize": (0, 0),
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   675
                                   "scaling": {}})
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   676
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   677
        # Change XSD into class members
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   678
        self._AddParamsMembers()
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   679
        self.Children = {}
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   680
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   681
        # Keep track of the root confnode (i.e. project path)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   682
        self.ProjectPath = ProjectPath
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   683
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   684
        self.BuildPath = self._getBuildPath()
652
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   685
        if self.OrigBuildPath is not None:
eb2d9f2b3567 Adding support for loading specific POUs library in LPCBeremiz
laurent
parents: 650
diff changeset
   686
            mycopytree(self.OrigBuildPath, self.BuildPath)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   687
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   688
        # If dir have already be made, and file exist
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   689
        if os.path.isdir(self.CTNPath()) and os.path.isfile(self.ConfNodeXmlFilePath()):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   690
            #Load the confnode.xml file into parameters members
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   691
            result = self.LoadXMLParams()
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   692
            if result:
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   693
                return result
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   694
            #Load and init all the children
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   695
            self.LoadChildren()
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   696
        
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   697
        if havecanfestival and self.GetChildByName("CanOpen") is None:
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   698
            canopen = self.CTNAddChild("CanOpen", "CanOpen", 0)
682
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
   699
            canopen.BaseParams.setEnabled(False)
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   700
            canopen.LoadChildren()
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   701
        
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   702
        if self.CTNTestModified():
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   703
            self.SaveProject()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
   704
        
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   705
        if wx.GetApp() is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   706
            self.RefreshConfNodesBlockLists()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   707
        else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   708
            wx.CallAfter(self.RefreshConfNodesBlockLists)
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   709
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   710
        return None
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   711
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   712
    ############# Real PLC object access #############
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   713
    def UpdateMethodsFromPLCStatus(self):
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   714
        # Get PLC state : Running or Stopped
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   715
        # TODO : use explicit status instead of boolean
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   716
        if self.OnlineMode == "OFF":
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   717
            status = "Disconnected"
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   718
        elif self.OnlineMode == "BOOTLOADER":
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   719
            status = "Connected"
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   720
        else:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   721
            if self._connector is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   722
                status = self._connector.GetPLCstatus()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   723
            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   724
                status = "Disconnected"
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   725
        if self.previous_plcstate != status or self.previous_mode != self.CurrentMode:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   726
            simulating = self.CurrentMode == SIMULATION_MODE
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   727
            for args in {
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   728
                     "Started" :     [("_Simulate", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   729
                                      ("_Run", False),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   730
                                      ("_Stop", True),
625
08d4cc1ceb9b Fixed LPCBeremiz to refect recent root plugin build method name to change
Edouard Tisserant
parents: 599
diff changeset
   731
                                      ("_Build", True),
559
0f5544587037 Fix buttons state according to online mode
laurent
parents: 555
diff changeset
   732
                                      ("_Transfer", True)],
0f5544587037 Fix buttons state according to online mode
laurent
parents: 555
diff changeset
   733
                     "Stopped" :     [("_Simulate", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   734
                                      ("_Run", True),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   735
                                      ("_Stop", False),
625
08d4cc1ceb9b Fixed LPCBeremiz to refect recent root plugin build method name to change
Edouard Tisserant
parents: 599
diff changeset
   736
                                      ("_Build", True),
559
0f5544587037 Fix buttons state according to online mode
laurent
parents: 555
diff changeset
   737
                                      ("_Transfer", True)],
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   738
                     "Connected" :   [("_Simulate", not simulating),
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   739
                                      ("_Run", True),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   740
                                      ("_Stop", simulating),
625
08d4cc1ceb9b Fixed LPCBeremiz to refect recent root plugin build method name to change
Edouard Tisserant
parents: 599
diff changeset
   741
                                      ("_Build", True),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   742
                                      ("_Transfer", True)],
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   743
                     "Disconnected" :[("_Simulate", not simulating),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   744
                                      ("_Run", False),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   745
                                      ("_Stop", simulating),
625
08d4cc1ceb9b Fixed LPCBeremiz to refect recent root plugin build method name to change
Edouard Tisserant
parents: 599
diff changeset
   746
                                      ("_Build", True),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   747
                                      ("_Transfer", False)],
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   748
                   }.get(status,[]):
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   749
                self.ShowMethod(*args)
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   750
            self.previous_plcstate = status
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   751
            self.previous_mode = self.CurrentMode
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   752
            return True
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   753
        return False
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   754
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   755
    def Generate_plc_declare_locations(self):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   756
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   757
        Declare used locations in order to simulatePLC in a black box
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   758
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   759
        return """#include "iec_types_all.h"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   760
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   761
#define __LOCATED_VAR(type, name, ...) \
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   762
type beremiz_##name;\
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   763
type *name = &beremiz_##name;
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   764
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   765
#include "LOCATED_VARIABLES.h"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   766
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   767
#undef __LOCATED_VAR
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   768
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   769
"""
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   770
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   771
    def Generate_lpc_retain_array_sim(self):
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   772
        """
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   773
        Support for retain array in Simulation
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   774
        """
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   775
        return """/* Support for retain array */
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   776
#define USER_RETAIN_ARRAY_SIZE 2000
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   777
#define NUM_OF_COLS    3
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   778
unsigned char readOK = 0;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   779
unsigned int foundIndex = USER_RETAIN_ARRAY_SIZE;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   780
unsigned int retainArray[USER_RETAIN_ARRAY_SIZE][NUM_OF_COLS];
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   781
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   782
unsigned int __GetRetainData(unsigned char READ, unsigned int INDEX, unsigned int COLUMN)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   783
{
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   784
    if(READ == 1)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   785
    {
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   786
        if((0<=INDEX) && (INDEX<USER_RETAIN_ARRAY_SIZE) && (0<=COLUMN) && (COLUMN<NUM_OF_COLS))
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   787
        {
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   788
            readOK = 1;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   789
            return retainArray[INDEX][COLUMN];
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   790
        }
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   791
    }
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   792
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   793
    readOK = 0;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   794
    return 0;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   795
}
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   796
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   797
unsigned char __SetRetainData(unsigned char WRITE, unsigned int INDEX, unsigned int WORD1, unsigned int WORD2, unsigned int WORD3)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   798
{
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   799
    if(WRITE == 1)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   800
    {
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   801
        if((0<=INDEX) && (INDEX<USER_RETAIN_ARRAY_SIZE))
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   802
        {
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   803
            retainArray[INDEX][0] = WORD1;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   804
            retainArray[INDEX][1] = WORD2;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   805
            retainArray[INDEX][2] = WORD3;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   806
            return 1;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   807
        }
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   808
    }
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   809
    
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   810
    return 0;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   811
}
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   812
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   813
unsigned char __FindRetainData(unsigned char SEARCH, unsigned int START_IDX, unsigned int END_IDX, unsigned int WORD1, unsigned int WORD2, unsigned int WORD3)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   814
{
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   815
    unsigned int i;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   816
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   817
    if((SEARCH==1) && (0<=START_IDX) && (START_IDX<USER_RETAIN_ARRAY_SIZE) && (START_IDX<=END_IDX) && (END_IDX<USER_RETAIN_ARRAY_SIZE))
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   818
    {
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   819
        for(i=START_IDX;i<=END_IDX;i++)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   820
        {
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   821
            if((retainArray[i][0] == WORD1) && (retainArray[i][1] == WORD2) && (retainArray[i][2] == WORD3))
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   822
            {
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   823
                foundIndex = i;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   824
                return 1;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   825
            }
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   826
        }
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   827
    }
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   828
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   829
    foundIndex = USER_RETAIN_ARRAY_SIZE;    /* Data not found => return index that is out of array bounds */
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   830
    return 0;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   831
}
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   832
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   833
/* Since Beremiz debugger doesn't like pointer-by-reference stuff or global varibles, separate function is a must */
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   834
unsigned char __GetReadStatus(unsigned char dummy)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   835
{
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   836
    return readOK;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   837
}
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   838
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   839
unsigned int __GetFoundIndex(unsigned char dummy)
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   840
{
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   841
    return foundIndex;
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   842
}
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   843
"""
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   844
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   845
    def _Simulate(self):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   846
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   847
        Method called by user to Simulate PLC
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   848
        """
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   849
        self.CurrentMode = SIMULATION_MODE
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   850
        
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   851
        uri = "LOCAL://"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   852
        try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   853
            self._connector = connectors.ConnectorFactory(uri, self)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   854
        except Exception, msg:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   855
            self.logger.write_error(_("Exception while connecting %s!\n")%uri)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   856
            self.logger.write_error(traceback.format_exc())
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   857
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   858
        # Did connection success ?
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   859
        if self._connector is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   860
            # Oups.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   861
            self.logger.write_error(_("Connection failed to %s!\n")%uri)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   862
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   863
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   864
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   865
        buildpath = self._getBuildPath()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   866
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   867
        # Eventually create build dir
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   868
        if not os.path.exists(buildpath):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   869
            os.makedirs(buildpath)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   870
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   871
        # Generate SoftPLC IEC code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   872
        IECGenRes = self._Generate_SoftPLC()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   873
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   874
         # If IEC code gen fail, bail out.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   875
        if not IECGenRes:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   876
            self.logger.write_error(_("IEC-61131-3 code generation failed !\n"))
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   877
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   878
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   879
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   880
        # Reset variable and program list that are parsed from
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   881
        # CSV file generated by IEC2C compiler.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   882
        self.ResetIECProgramsAndVariables()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   883
        
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   884
        gen_result = self.CTNGenerate_C(buildpath, self.PLCGeneratedLocatedVars)
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   885
        CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3]
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   886
        # if some files have been generated put them in the list with their location
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   887
        if CTNCFilesAndCFLAGS:
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   888
            self.LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), CTNCFilesAndCFLAGS, DoCalls)]
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   889
        else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   890
            self.LocationCFilesAndCFLAGS = []
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   891
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   892
        # confnode asks for some LDFLAGS
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   893
        if CTNLDFLAGS:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   894
            # LDFLAGS can be either string
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   895
            if type(CTNLDFLAGS)==type(str()):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   896
                self.LDFLAGS=[CTNLDFLAGS]
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   897
            #or list of strings
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   898
            elif type(CTNLDFLAGS)==type(list()):
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
   899
                self.LDFLAGS=CTNLDFLAGS[:]
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   900
        else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   901
            self.LDFLAGS=[]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   902
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   903
        # Template based part of C code generation
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   904
        # files are stacked at the beginning, as files of confnode tree root
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   905
        for generator, filename, name in [
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   906
           # debugger code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   907
           (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   908
           # init/cleanup/retrieve/publish, run and align code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   909
           (self.Generate_plc_common_main,"plc_common_main.c","Common runtime"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   910
           # declare located variables for simulate in a black box
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   911
           (self.Generate_plc_declare_locations,"plc_declare_locations.c","Declare Locations"),
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   912
           # declare located variables for simulate in a black box
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
   913
           (self.Generate_lpc_retain_array_sim,"lpc_retain_array_sim.c","Retain Array for Simulation")]:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   914
            try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   915
                # Do generate
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   916
                code = generator()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   917
                if code is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   918
                     raise
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   919
                code_path = os.path.join(buildpath,filename)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   920
                open(code_path, "w").write(code)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   921
                # Insert this file as first file to be compiled at root confnode
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   922
                self.LocationCFilesAndCFLAGS[0][1].insert(0,(code_path, self.plcCFLAGS))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   923
            except Exception, exc:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   924
                self.logger.write_error(name+_(" generation failed !\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   925
                self.logger.write_error(traceback.format_exc())
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   926
                self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   927
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   928
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   929
        # Get simulation builder
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   930
        builder = self.GetBuilder()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   931
        if builder is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   932
            self.logger.write_error(_("Fatal : cannot get builder.\n"))
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   933
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   934
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   935
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   936
        # Build
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   937
        try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   938
            if not builder.build() :
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   939
                self.logger.write_error(_("C Build failed.\n"))
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   940
                self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   941
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   942
        except Exception, exc:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   943
            self.logger.write_error(_("C Build crashed !\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   944
            self.logger.write_error(traceback.format_exc())
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   945
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   946
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   947
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   948
        data = builder.GetBinaryCode()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   949
        if data is not None :
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   950
            if self._connector.NewPLC(builder.GetBinaryCodeMD5(), data, []):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   951
                self.UnsubscribeAllDebugIECVariable()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   952
                self.ProgramTransferred()
697
3e83853081d4 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 691
diff changeset
   953
                if self.AppFrame is not None:
3e83853081d4 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 691
diff changeset
   954
                    self.AppFrame.RefreshInstancesTree()
3e83853081d4 Adding support for not closing debug tabs and remove variable in variable debug panel if instance still exist in newly transfered program
laurent
parents: 691
diff changeset
   955
                    self.AppFrame.CloseObsoleteDebugTabs()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   956
                self.logger.write(_("Transfer completed successfully.\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   957
            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   958
                self.logger.write_error(_("Transfer failed\n"))
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   959
                self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   960
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   961
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   962
        self._Run()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   963
                
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   964
        if not self.StatusTimer.IsRunning():
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   965
            # Start the status Timer
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   966
            self.StatusTimer.Start(milliseconds=500, oneShot=False)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   967
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   968
    def StopSimulation(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   969
        self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   970
        self.ApplyOnlineMode()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   971
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   972
    def _Stop(self):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
   973
        ConfigTreeRoot._Stop(self)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   974
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   975
        if self.CurrentMode == SIMULATION_MODE:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   976
            self.StopSimulation()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   977
560
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   978
    def CompareLocalAndRemotePLC(self):
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   979
        if self.LPCConnector is None:
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   980
            return
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   981
        # We are now connected. Update button status
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   982
        MD5 = self.GetLastBuildMD5()
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   983
        # Check remote target PLC correspondance to that md5
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   984
        if MD5 is not None and self.LPCConnector.MatchMD5(MD5):
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   985
            # warns controller that program match
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   986
            self.ProgramTransferred()
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   987
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
   988
    def ResetBuildMD5(self):
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
   989
        builder=self.GetBuilder()
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
   990
        if builder is not None:
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
   991
            builder.ResetBinaryCodeMD5(self.OnlineMode)
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
   992
        
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   993
    def GetLastBuildMD5(self):
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   994
        builder=self.GetBuilder()
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   995
        if builder is not None:
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   996
            return builder.GetBinaryCodeMD5(self.OnlineMode)
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   997
        else:
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   998
            return None
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
   999
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1000
    def _Transfer(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1001
        if self.CurrentMode is None and self.OnlineMode != "OFF":
572
c965548cb6f7 Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents: 571
diff changeset
  1002
            self.CurrentMode = TRANSFER_MODE
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1003
            
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1004
            if ConfigTreeRoot._Build(self):
677
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1005
            
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1006
                ID_ABORTTRANSFERTIMER = wx.NewId()
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1007
                self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER)
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1008
                self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer)  
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1009
                
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1010
                if self.OnlineMode == "BOOTLOADER":
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1011
                    self.BeginTransfer()
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1012
                
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1013
                else:
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1014
                    self.logger.write(_("Resetting PLC\n"))
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1015
                    #self.StatusTimer.Stop()
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1016
                    self.LPCConnector.ResetPLC()
607731b33026 Fix 'Transfer" button state according to last build result
laurent
parents: 659
diff changeset
  1017
                    self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
691
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
  1018
            
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
  1019
            else:
bb340874f09e Fix bug with "Transfer" button
smarteh-dev
parents: 684
diff changeset
  1020
                self.CurrentMode = None
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1021
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1022
    def BeginTransfer(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1023
        self.logger.write(_("Start PLC transfer\n"))
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1024
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1025
        self.AbortTransferTimer.Stop()
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1026
        ConfigTreeRoot._Transfer(self)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1027
        self.AbortTransferTimer.Start(milliseconds=5000, oneShot=True)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1028
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1029
    def AbortTransfer(self, event):
543
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
  1030
        self.logger.write_warning(_("Timeout waiting PLC to recover\n"))
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1031
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1032
        self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1033
        self.AbortTransferTimer.Stop()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1034
        self.AbortTransferTimer = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1035
        event.Skip()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1036
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1037
    def _Run(self):
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1038
        """
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1039
        Start PLC
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1040
        """
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1041
        if self.GetIECProgramsAndVariables():
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1042
            self._connector.StartPLC()
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1043
            self.logger.write(_("Starting PLC\n"))
576
7fcdc0d3d8d9 Some typo fixes to make debug related methods in LPCAppOject stop throwing exceptions, less agressive error message when unplugging LPC
edouard
parents: 575
diff changeset
  1044
            self._connect_debug()
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1045
        else:
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1046
            self.logger.write_error(_("Couldn't start PLC !\n"))
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1047
        self.UpdateMethodsFromPLCStatus()
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1048
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1049
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1050
#                              LPCBeremiz Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1051
#-------------------------------------------------------------------------------
549
5dd92bd6e6e5 Fixed bug on frame close.
Lolitech
parents: 547
diff changeset
  1052
lpcberemiz_cmd=None
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1053
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1054
class LPCBeremiz(Beremiz):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1055
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1056
    def _init_coll_FileMenu_Items(self, parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1057
        AppendMenu(parent, help='', id=wx.ID_SAVE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1058
              kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1059
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1060
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1061
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1062
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1063
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1064
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1065
              kind=wx.ITEM_NORMAL, text=_(u'Preview'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1066
        AppendMenu(parent, help='', id=wx.ID_PRINT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1067
              kind=wx.ITEM_NORMAL, text=_(u'Print'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1068
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1069
        AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1070
              kind=wx.ITEM_NORMAL, text=_(u'Properties'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1071
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1072
        AppendMenu(parent, help='', id=wx.ID_EXIT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1073
              kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1074
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1075
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1076
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1077
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1078
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1079
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1080
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1081
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1082
    
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
  1083
        self.AddToMenuToolBar([(wx.ID_SAVE, "save.png", _(u'Save'), None),
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
  1084
                               (wx.ID_PRINT, "print.png", _(u'Print'), None)])
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1085
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1086
    def _init_ctrls(self, prnt):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1087
        IDEFrame._init_ctrls(self, prnt)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1088
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1089
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1090
        accel = wx.AcceleratorTable([wx.AcceleratorEntry(wx.ACCEL_CTRL|wx.ACCEL_ALT, ord('I'), ID_BEREMIZINSPECTOR)])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1091
        self.SetAcceleratorTable(accel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1092
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1093
        self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1094
              name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1095
              size=wx.Size(-1, -1), style=wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER|wx.HSCROLL|wx.VSCROLL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1096
        self.PLCConfig.SetBackgroundColour(wx.WHITE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1097
        self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1098
        self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1099
        self.LeftNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1100
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1101
        self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1102
                  name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1103
                  size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1104
        self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1105
        self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console"))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1106
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1107
        self._init_beremiz_sizers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1108
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1109
    def OnCloseFrame(self, event):
519
3a5faff52e5c Adding message to standard output to signal when LPCBeremiz is closed
laurent
parents: 517
diff changeset
  1110
        global frame
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1111
        
596
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1112
        if self.CheckSaveBeforeClosing(_("Close Application")):
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1113
            
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1114
            frame.Hide()
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1115
            
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1116
            self.CTR.ResetAppFrame(lpcberemiz_cmd.Log)
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1117
            if self.CTR.OnlineMode == 0:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1118
                self.CTR._connector = None
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1119
            
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1120
            self.CTR.KillDebugThread()
596
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1121
            self.KillLocalRuntime()
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1122
            
715
135566ab0807 Adding support for automatically saving and restoring state of frame or project perspective
laurent
parents: 708
diff changeset
  1123
            self.SaveLastState()
598
6c919bc1551d Adding support for saving frame size while closing and restore it at next launch
laurent
parents: 597
diff changeset
  1124
            
596
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1125
            lpcberemiz_cmd.Log.write("Closed\n")
b36422acae13 Adding warning message on LPCBeremiz when closing frame and program not saved
laurent
parents: 578
diff changeset
  1126
            
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1127
        event.Veto()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1128
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1129
    def ShowProperties(self):
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1130
        old_values = self.Controler.GetProjectProperties()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1131
        dialog = ProjectDialog(self ,False)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1132
        dialog.SetValues(old_values)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1133
        if dialog.ShowModal() == wx.ID_OK:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1134
            new_values = dialog.GetValues()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1135
            new_values["creationDateTime"] = old_values["creationDateTime"]
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1136
            if new_values != old_values:
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1137
                self.Controler.SetProjectProperties(None, new_values)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1138
                self._Refresh(TITLE, EDITORTOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1139
                              TYPESTREE, INSTANCESTREE, SCALING)
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1140
        dialog.Destroy()
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1141
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1142
    def RefreshFileMenu(self):
708
6ec28dc375cf Fixing menu toolbar icons on Windows
laurent
parents: 706
diff changeset
  1143
        MenuToolBar = self.Panes["MenuToolBar"]
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1144
        if self.CTR is not None:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1145
            selected = self.TabsOpened.GetSelection()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1146
            if selected >= 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1147
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1148
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1149
                graphic_viewer = False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1150
            if self.TabsOpened.GetPageCount() > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1151
                self.FileMenu.Enable(wx.ID_CLOSE, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1152
                if graphic_viewer:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1153
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1154
                    self.FileMenu.Enable(wx.ID_PRINT, True)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1155
                    MenuToolBar.EnableTool(wx.ID_PRINT, True)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1156
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1157
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1158
                    self.FileMenu.Enable(wx.ID_PRINT, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1159
                    MenuToolBar.EnableTool(wx.ID_PRINT, False)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1160
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1161
                self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1162
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1163
                self.FileMenu.Enable(wx.ID_PRINT, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1164
                MenuToolBar.EnableTool(wx.ID_PRINT, False)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1165
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1166
            project_modified = self.CTR.ProjectTestModified()
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1167
            self.FileMenu.Enable(wx.ID_SAVE, project_modified)
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1168
            MenuToolBar.EnableTool(wx.ID_SAVE, project_modified)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1169
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1170
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1171
            self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1172
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1173
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1174
            self.FileMenu.Enable(wx.ID_PRINT, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1175
            MenuToolBar.EnableTool(wx.ID_PRINT, False)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1176
            self.FileMenu.Enable(wx.ID_SAVE, False)
706
64a9b509973b Adding ToolBar containing basic menu items
laurent
parents: 697
diff changeset
  1177
            MenuToolBar.EnableTool(wx.ID_SAVE, False)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1178
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1179
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1180
    def RefreshPLCParams(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1181
        self.Freeze()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1182
        self.ClearSizer(self.PLCParamsSizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1183
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1184
        if self.CTR is not None:    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1185
            plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1186
            if self.CTR.CTNTestModified():
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1187
                bkgdclr = CHANGED_TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1188
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1189
                bkgdclr = TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1190
                
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1191
            if self.CTR not in self.ConfNodeInfos:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1192
                self.ConfNodeInfos[self.CTR] = {"right_visible" : False}
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1193
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1194
            plcwindow.SetBackgroundColour(TITLE_COLOUR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1195
            plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1196
            self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1197
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1198
            plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1199
            plcwindow.SetSizer(plcwindowsizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1200
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1201
            st = wx.StaticText(plcwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1202
            st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1203
            st.SetLabel(self.CTR.GetProjectName())
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1204
            plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1205
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1206
            plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1207
            plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1208
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1209
            plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1210
            plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1211
            
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1212
            msizer = self.GenerateMethodButtonSizer(self.CTR, plcwindow, not self.ConfNodeInfos[self.CTR]["right_visible"])
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1213
            plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1214
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1215
        self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1216
        self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1217
        self.Thaw()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1218
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1219
    def GenerateTreeBranch(self, confnode):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1220
        leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1221
        if confnode.CTNTestModified():
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1222
            bkgdclr=CHANGED_WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1223
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1224
            bkgdclr=WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1225
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1226
        leftwindow.SetBackgroundColour(bkgdclr)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1227
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1228
        if confnode not in self.ConfNodeInfos:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1229
            self.ConfNodeInfos[confnode] = {"expanded" : False, "left_visible" : False, "right_visible" : False}
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1230
            
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1231
        self.ConfNodeInfos[confnode]["children"] = confnode.IECSortedChildren()
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1232
        confnode_infos = confnode.GetVariableLocationTree()
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1233
        confnode_locations = []
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1234
        if len(self.ConfNodeInfos[confnode]["children"]) == 0:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1235
            confnode_locations = confnode_infos["children"]
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1236
            if not self.ConfNodeInfos[confnode].has_key("locations_infos"):
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1237
                self.ConfNodeInfos[confnode]["locations_infos"] = {"root": {"expanded" : False}}
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1238
            
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1239
            self.ConfNodeInfos[confnode]["locations_infos"]["root"]["left"] = None
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1240
            self.ConfNodeInfos[confnode]["locations_infos"]["root"]["right"] = None
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1241
            self.ConfNodeInfos[confnode]["locations_infos"]["root"]["children"] = []
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1242
        
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1243
        self.ConfNodeTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1244
        
682
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
  1245
        leftwindowvsizer = wx.BoxSizer(wx.VERTICAL)
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
  1246
        leftwindow.SetSizer(leftwindowvsizer)
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
  1247
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1248
        leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
682
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
  1249
        leftwindowvsizer.AddSizer(leftwindowsizer, 0, border=0, flag=0)
9d20df7c144a Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
  1250
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1251
        self.GenerateEnableButton(leftwindow, leftwindowsizer, confnode)
680
61746934df41 Adding support for integrating CanFestival plugin panels in Beremiz main frame
smarteh-dev
parents: 678
diff changeset
  1252
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1253
        st = wx.StaticText(leftwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1254
        st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1255
        st.SetLabel(confnode.GetFullIEC_Channel())
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1256
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1257
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1258
        expandbutton_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1259
        expandbutton = wx.lib.buttons.GenBitmapToggleButton(id=expandbutton_id, bitmap=wx.Bitmap(Bpath( 'images', 'plus.png')),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1260
              name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1261
              size=wx.Size(13, 13), style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1262
        expandbutton.labelDelta = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1263
        expandbutton.SetBezelWidth(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1264
        expandbutton.SetUseFocusIndicator(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1265
        expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1266
            
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1267
        if len(self.ConfNodeInfos[confnode]["children"]) > 0:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1268
            expandbutton.SetToggle(self.ConfNodeInfos[confnode]["expanded"])
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1269
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1270
                if expandbutton.GetToggle():
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1271
                    self.ExpandConfNode(confnode)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1272
                else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1273
                    self.CollapseConfNode(confnode)
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1274
                self.ConfNodeInfos[confnode]["expanded"] = expandbutton.GetToggle()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1275
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1276
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1277
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1278
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1279
        elif len(confnode_locations) > 0:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1280
            locations_infos = self.ConfNodeInfos[confnode]["locations_infos"]
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1281
            expandbutton.SetToggle(locations_infos["root"]["expanded"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1282
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1283
                if expandbutton.GetToggle():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1284
                    self.ExpandLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1285
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1286
                    self.CollapseLocation(locations_infos, "root")
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1287
                self.ConfNodeInfos[confnode]["expanded"] = expandbutton.GetToggle()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1288
                locations_infos["root"]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1289
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1290
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1291
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1292
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1293
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1294
            expandbutton.Enable(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1295
        leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1296
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1297
        sb = wx.StaticBitmap(leftwindow, -1)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1298
        icon = confnode_infos.get("icon", None)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1299
        if icon is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1300
            icon_bitmap = self.LocationImageList.GetBitmap(self.LocationImageDict[confnode_infos["type"]])
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1301
        else: 
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1302
            icon_bitmap = wx.Bitmap(icon)
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1303
        sb.SetBitmap(icon_bitmap)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1304
        leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1305
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1306
        st_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1307
        st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1308
        st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1309
        st.SetLabel(confnode.MandatoryParams[1].getName())
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1310
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1311
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1312
        rightwindow = self.GenerateParamsPanel(confnode, bkgdclr)
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1313
        self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1314
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1315
        self.ConfNodeInfos[confnode]["left"] = leftwindow
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1316
        self.ConfNodeInfos[confnode]["right"] = rightwindow
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1317
        for child in self.ConfNodeInfos[confnode]["children"]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1318
            self.GenerateTreeBranch(child)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1319
            if not self.ConfNodeInfos[child]["expanded"]:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1320
                self.CollapseConfNode(child)
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1321
        
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1322
        if len(confnode_locations) > 0:
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1323
            locations_infos = self.ConfNodeInfos[confnode]["locations_infos"]
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1324
            treectrl = wx.TreeCtrl(self.PLCConfig, -1, size=wx.DefaultSize, 
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1325
                                   style=wx.TR_HAS_BUTTONS|wx.TR_SINGLE|wx.NO_BORDER|wx.TR_HIDE_ROOT|wx.TR_NO_LINES|wx.TR_LINES_AT_ROOT)
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1326
            treectrl.SetImageList(self.LocationImageList)
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1327
            treectrl.Bind(wx.EVT_TREE_BEGIN_DRAG, self.GenerateLocationBeginDragFunction(locations_infos))
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1328
            treectrl.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.GenerateLocationExpandCollapseFunction(locations_infos, True))
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1329
            treectrl.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.GenerateLocationExpandCollapseFunction(locations_infos, False))
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1330
            
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1331
            treectrl.AddRoot("")
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1332
            self.ConfNodeTreeSizer.AddWindow(treectrl, 0, border=0, flag=0)
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1333
            
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1334
            rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1335
            rightwindow.SetBackgroundColour(wx.WHITE)
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1336
            self.ConfNodeTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1337
            
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1338
            locations_infos["root"]["left"] = treectrl
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1339
            locations_infos["root"]["right"] = rightwindow
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1340
            for location in confnode_locations:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1341
                locations_infos["root"]["children"].append("root.%s" % location["name"])
650
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1342
                self.GenerateLocationTreeBranch(treectrl, treectrl.GetRootItem(), locations_infos, "root", location)
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1343
            if locations_infos["root"]["expanded"]:
26236e691330 Replacing sizers structure for locations tree by a treectrl in Topology panel in order to make refreshing of this panel faster
laurent
parents: 629
diff changeset
  1344
                self.ExpandLocation(locations_infos, "root")
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1345
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1346
class StdoutPseudoFile:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1347
    
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1348
    def __init__(self, port):
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1349
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1350
        self.socket.connect(('localhost', port))
552
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1351
        self.Buffer = ""
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1352
    
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1353
    def __del__(self):
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1354
        self.socket.close()
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1355
    
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1356
    def readline(self):
552
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1357
        idx = self.Buffer.find("\n")
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1358
        if idx == -1:
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1359
            self.Buffer += self.socket.recv(2048)
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1360
            idx = self.Buffer.find("\n")
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1361
        if idx != -1:
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1362
            line = self.Buffer[:idx+1]
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1363
            self.Buffer = self.Buffer[idx+1:]
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1364
            if BMZ_DBG:
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1365
                print "command >"+line
552
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1366
            return line
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1367
        return ""
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1368
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1369
    """ Base class for file like objects to facilitate StdOut for the Shell."""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1370
    def write(self, s, style = None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1371
        if s != '':
578
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
  1372
            self.socket.send(s.encode('utf8'))
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
  1373
        
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
  1374
    def writeyield(self, s):
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
  1375
        self.write(s)
6f5795bdee49 Making debugger more stable with LPC
edouard
parents: 576
diff changeset
  1376
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1377
    def write_warning(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1378
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1379
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1380
    def write_error(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1381
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1382
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1383
    def flush(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1384
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1385
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1386
    def isatty(self):
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1387
        return False
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1388
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1389
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1390
    
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1391
    from threading import Thread, Timer, Semaphore
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1392
    import cmd
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1393
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1394
    wx_eval_lock = Semaphore(0)
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1395
    eval_res = None
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1396
    def wx_evaluator(callable, *args, **kwargs):
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1397
        global eval_res
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1398
        eval_res = None
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1399
        try:
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1400
            eval_res=callable(*args,**kwargs)
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1401
        finally:
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1402
            wx_eval_lock.release()
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1403
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1404
    def evaluator(callable, *args, **kwargs):
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1405
        global eval_res
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1406
        wx.CallAfter(wx_evaluator,callable,*args,**kwargs)
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1407
        wx_eval_lock.acquire()
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1408
        return eval_res
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1409
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1410
    # Command log for debug, for viewing from wxInspector
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1411
    if BMZ_DBG:
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1412
        __builtins__.cmdlog = []
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1413
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1414
    class LPCBeremiz_Cmd(cmd.Cmd):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1415
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1416
        prompt = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1417
        RefreshTimer = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1418
        
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1419
        def __init__(self, CTR, Log):
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1420
            cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1421
            self.use_rawinput = False
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1422
            self.Log = Log
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1423
            self.CTR = CTR
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1424
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1425
        def RestartTimer(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1426
            if self.RefreshTimer is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1427
                self.RefreshTimer.cancel()
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1428
            self.RefreshTimer = Timer(0.1, wx.CallAfter, args = [self.Refresh])
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1429
            self.RefreshTimer.start()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1430
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1431
        def Exit(self):
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1432
            global frame, app
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1433
            self.Close()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1434
            app.ExitMainLoop()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1435
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1436
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1437
        def do_EOF(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1438
            return self.Exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1439
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1440
        def Show(self):
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1441
            global frame
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1442
            if frame is not None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1443
                self.CTR.SetAppFrame(frame, frame.Log)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1444
                frame.Show()
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1445
                frame.Raise()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1446
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1447
        def Refresh(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1448
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1449
            if frame is not None:
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1450
                frame._Refresh(TITLE, INSTANCESTREE, FILEMENU, EDITMENU)
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1451
                frame.RefreshEditor()
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1452
                frame.RefreshAll()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1453
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1454
        def Close(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1455
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1456
            
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1457
            self.CTR.ResetAppFrame(self.Log)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1458
            if frame is not None:
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1459
                frame.Hide()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1460
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1461
        def Compile(self):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1462
            self.CTR._Build()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1463
        
500
af7c28de4cc7 Adding support for defining mandatory parameters and creating blank xml file when there is nothing in the folder in LPCBeremiz
laurent
parents: 494
diff changeset
  1464
        def SetProjectProperties(self, projectname, productname, productversion, companyname):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1465
            properties = self.CTR.GetProjectProperties()
597
6fbfd3bf2927 Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents: 596
diff changeset
  1466
            new_properties = properties.copy()
6fbfd3bf2927 Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents: 596
diff changeset
  1467
            new_properties["projectName"] = projectname
6fbfd3bf2927 Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents: 596
diff changeset
  1468
            new_properties["productName"] = productname
6fbfd3bf2927 Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents: 596
diff changeset
  1469
            new_properties["productVersion"] = productversion
6fbfd3bf2927 Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents: 596
diff changeset
  1470
            new_properties["companyName"] = companyname
6fbfd3bf2927 Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents: 596
diff changeset
  1471
            if new_properties != properties:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1472
                self.CTR.SetProjectProperties(properties=new_properties, buffer=False)
597
6fbfd3bf2927 Fix bug in LPCBeremiz marking any newly opened project as modified
laurent
parents: 596
diff changeset
  1473
                self.RestartTimer()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1474
        
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1475
        def SetOnlineMode(self, mode, path=None):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1476
            self.CTR.SetOnlineMode(mode, path)
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1477
            self.RestartTimer()
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1478
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1479
        def AddBus(self, iec_channel, name, icon=None):
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1480
            for child in self.CTR.IterChildren():
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1481
                if child.BaseParams.getName() == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1482
                    return "Error: A bus named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1483
                elif child.BaseParams.getIEC_Channel() == iec_channel:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1484
                    return "Error: A bus with IEC_channel %d already exists\n" % iec_channel
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1485
            bus = self.CTR.CTNAddChild(name, "LPCBus", iec_channel)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1486
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1487
                return "Error: Unable to create bus\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1488
            bus.SetIcon(icon)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1489
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1490
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1491
        def RenameBus(self, iec_channel, name):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1492
            bus = self.CTR.GetChildByIECLocation((iec_channel,))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1493
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1494
                return "Error: No bus found\n"
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1495
            for child in self.CTR.IterChildren():
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1496
                if child != bus and child.BaseParams.getName() == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1497
                    return "Error: A bus named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1498
            bus.BaseParams.setName(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1499
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1500
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1501
        def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1502
            bus = self.CTR.GetChildByIECLocation((old_iec_channel,))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1503
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1504
                return "Error: No bus found\n"
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1505
            for child in self.CTR.IterChildren():
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1506
                if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1507
                    return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1508
            if wx.GetApp() is None:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1509
                self.CTR.UpdateProjectVariableLocation(str(old_iec_channel), 
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1510
                                                              str(new_iec_channel))
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1511
            else:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1512
                self.CTR.UpdateProjectVariableLocation(
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1513
                             str(old_iec_channel), 
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1514
                             str(new_iec_channel))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1515
            bus.BaseParams.setIEC_Channel(new_iec_channel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1516
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1517
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1518
        def RemoveBus(self, iec_channel):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1519
            bus = self.CTR.GetChildByIECLocation((iec_channel,))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1520
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1521
                return "Error: No bus found\n"
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1522
            self.CTR.RemoveProjectVariableByFilter(str(iec_channel))
718
5d4dc150b956 refactoring
Edouard Tisserant
parents: 717
diff changeset
  1523
            self.CTR.Children["LPCBus"].remove(bus)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1524
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1525
    
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1526
        def AddModule(self, parent, iec_channel, name, icode, icon=None):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1527
            module = self.CTR.GetChildByIECLocation(parent)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1528
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1529
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1530
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1531
                if child["name"] == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1532
                    return "Error: A module named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1533
                elif child["IEC_Channel"] == iec_channel:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1534
                    return "Error: A module with IEC_channel %d already exists\n" % iec_channel 
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1535
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1536
                                                "type": LOCATION_MODULE, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1537
                                                "IEC_Channel": iec_channel, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1538
                                                "icon": icon, 
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1539
                                                "init": icode, 
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1540
                                                "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1541
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1542
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1543
        def RenameModule(self, iec_location, name):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1544
            module = self.CTR.GetChildByIECLocation(iec_location)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1545
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1546
                return "Error: No module found\n"
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1547
            parent = self.CTR.GetChildByIECLocation(iec_location[:-1])
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1548
            if parent is self.CTR:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1549
                return "Error: No module found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1550
            if module["name"] != name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1551
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1552
                    if child["name"] == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1553
                        return "Error: A module named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1554
                module["name"] = name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1555
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1556
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1557
        def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1558
            module = self.CTR.GetChildByIECLocation(old_iec_location)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1559
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1560
                return "Error: No module found\n"
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1561
            parent = self.CTR.GetChildByIECLocation(old_iec_location[:-1])
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1562
            if parent is self.CTR:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1563
                return "Error: No module found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1564
            if module["IEC_Channel"] != new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1565
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1566
                    if child["IEC_Channel"] == new_iec_channel:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1567
                        return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1568
            self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1569
            module["IEC_Channel"] = new_iec_channel
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1570
            self.RestartTimer()
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1571
        
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1572
        def ChangeModuleInitCode(self, iec_location, icode):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1573
            module = self.CTR.GetChildByIECLocation(iec_location)
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1574
            if module is None:
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1575
                return "Error: No module found\n"
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1576
            module["init"] = icode
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1577
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1578
        def RemoveModule(self, parent, iec_channel):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1579
            module = self.CTR.GetChildByIECLocation(parent)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1580
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1581
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1582
            child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1583
            if child is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1584
                return "Error: No module found\n"
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1585
            self.CTR.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1586
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1587
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1588
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1589
        def StartGroup(self, parent, name, icon=None):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1590
            module = self.CTR.GetChildByIECLocation(parent)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1591
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1592
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1593
            for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1594
                if child["type"] == LOCATION_GROUP and child["name"] == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1595
                    return "Error: A group named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1596
            module["children"].append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1597
                                      "type": LOCATION_GROUP, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1598
                                      "icon": icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1599
                                      "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1600
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1601
    
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1602
        def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1603
            module = self.CTR.GetChildByIECLocation(parent)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1604
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1605
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1606
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1607
                if child["name"] == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1608
                    return "Error: A variable named %s already exists\n" % name
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1609
                if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1610
                    return "Error: A variable with location %s already exists\n" % ".".join(map(str, location))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1611
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1612
                                                "location": location, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1613
                                                "type": LOCATION_TYPES[direction], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1614
                                                "IEC_type": type, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1615
                                                "description": description, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1616
                                                "retrieve": rcode, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1617
                                                "publish": pcode})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1618
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1619
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1620
        def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode, new_description=None):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1621
            module = self.CTR.GetChildByIECLocation(parent)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1622
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1623
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1624
            variable = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1625
            for child in _GetModuleChildren(module):
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1626
                if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1627
                    variable = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1628
                elif child["name"] == new_name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1629
                    return "Error: A variable named %s already exists\n" % new_name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1630
            if variable is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1631
                return "Error: No variable found\n"
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1632
            if variable["name"] != new_name:
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1633
                self.CTR.UpdateProjectVariableName(variable["name"], new_name)
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1634
                variable["name"] = new_name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1635
            variable["type"] = LOCATION_TYPES[new_direction]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1636
            variable["IEC_type"] = new_type
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1637
            variable["retrieve"] = new_rcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1638
            variable["publish"] = new_pcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1639
            if new_description is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1640
                variable["description"] = new_description
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1641
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1642
    
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1643
        def RemoveVariable(self, parent, location, direction):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1644
            module = self.CTR.GetChildByIECLocation(parent)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1645
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1646
                return "Error: No parent found\n"
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1647
            child = _GetModuleVariable(module, location, direction)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1648
            if child is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1649
                return "Error: No variable found\n"
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1650
            size = LOCATION_SIZES[self.CTR.GetBaseType(child["IEC_type"])]
444
8eb1186fc9cf Adding support for updating or removing located variables by their address or leading address numbers when changing or removing VariableTree element
laurent
parents: 442
diff changeset
  1651
            address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1652
            self.CTR.RemoveProjectVariableByAddress(address)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1653
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1654
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1655
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1656
    def location(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1657
        return tuple(map(int, loc.split(".")))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1658
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1659
    def GetCmdFunction(function, arg_types, opt=0):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1660
        arg_number = len(arg_types)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1661
        def CmdFunction(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1662
            args_toks = line.split('"')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1663
            if len(args_toks) % 2 == 0:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1664
                self.Log.write("Error: Invalid command\n")
526
68375ccdf968 Added flush when printing to standard output.
tkragelj
parents: 521
diff changeset
  1665
                sys.stdout.flush()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1666
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1667
            args = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1668
            for num, arg in enumerate(args_toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1669
                if num % 2 == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1670
                    stripped = arg.strip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1671
                    if stripped:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1672
                        args.extend(stripped.split(" "))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1673
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1674
                    args.append(arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1675
            number = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1676
            extra = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1677
            if opt == 0 and len(args) != arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1678
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1679
            elif len(args) > arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1680
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1681
                extra = " at most"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1682
            elif len(args) < arg_number - opt:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1683
                number = arg_number - opt
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1684
                extra = " at least"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1685
            if number is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1686
                if number == 0:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1687
                    self.Log.write("Error: No argument%s expected\n" % extra)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1688
                elif number == 1:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1689
                    self.Log.write("Error: 1 argument%s expected\n" % extra)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1690
                else:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1691
                    self.Log.write("Error: %d arguments%s expected\n" % (number, extra))
526
68375ccdf968 Added flush when printing to standard output.
tkragelj
parents: 521
diff changeset
  1692
                sys.stdout.flush()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1693
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1694
            for num, arg in enumerate(args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1695
                try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1696
                    args[num] = arg_types[num](arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1697
                except:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1698
                    self.Log.write("Error: Invalid value for argument %d\n" % (num + 1))
526
68375ccdf968 Added flush when printing to standard output.
tkragelj
parents: 521
diff changeset
  1699
                    sys.stdout.flush()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1700
                    return
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1701
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1702
            func = getattr(self, function)
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1703
            res = evaluator(func,*args)
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1704
571
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1705
            if BMZ_DBG:
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1706
                cmdlog.append((function,line,res))
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1707
                if len(cmdlog) > 100: #prevent debug log to grow too much
427bf9130d12 Debug switch (file in CWD). LPC : better MD5 handling, Run button in boot mode, handling data feedback in boot protocol
edouard
parents: 566
diff changeset
  1708
                    cmdlog.pop(0) 
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1709
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1710
            if isinstance(res, (StringType, UnicodeType)):
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1711
                self.Log.write(res)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1712
                return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1713
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1714
                return res
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1715
        return CmdFunction
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1716
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1717
    def CmdThreadProc(CTR, Log):
549
5dd92bd6e6e5 Fixed bug on frame close.
Lolitech
parents: 547
diff changeset
  1718
        global lpcberemiz_cmd
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1719
        for function, (arg_types, opt) in {"Exit": ([], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1720
                                           "Show": ([], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1721
                                           "Refresh": ([], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1722
                                           "Close": ([], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1723
                                           "Compile": ([], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1724
                                           "SetProjectProperties": ([str, str, str, str], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1725
                                           "SetOnlineMode": ([str, str], 1),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1726
                                           "AddBus": ([int, str, str], 1),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1727
                                           "RenameBus": ([int, str], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1728
                                           "ChangeBusIECChannel": ([int, int], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1729
                                           "RemoveBus": ([int], 0),
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1730
                                           "AddModule": ([location, int, str, str, str], 1), 
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1731
                                           "RenameModule": ([location, str], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1732
                                           "ChangeModuleIECChannel": ([location, int], 0),
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1733
                                           "ChangeModuleInitCode": ([location, str], 0),
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1734
                                           "RemoveModule": ([location, int], 0),
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1735
                                           "StartGroup": ([location, str, str], 1),
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1736
                                           "AddVariable": ([location, location, str, str, str, str, str, str], 1),
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1737
                                           "ChangeVariableParams": ([location, location, str, str, str, str, str, str], 1),
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1738
                                           "RemoveVariable": ([location, location], 0)}.iteritems():
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1739
            
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1740
            setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1741
        lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1742
        lpcberemiz_cmd.cmdloop()
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1743
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1744
    Log = StdoutPseudoFile(port)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1745
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1746
    CTR = LPCConfigTreeRoot(None, Log, buildpath)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1747
    if projectOpen is not None and os.path.isdir(projectOpen):
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1748
        result = CTR.LoadProject(projectOpen)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1749
        if result:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1750
            Log.write("Error: Invalid project directory", result)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1751
    else:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1752
        Log.write("Error: No such file or directory")
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1753
    
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1754
    cmd_thread=Thread(target=CmdThreadProc, args=[CTR, Log])
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1755
    cmd_thread.start()
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1756
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1757
    # Install a exception handle for bug reports
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1758
    AddExceptHook(os.getcwd(),__version__)
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1759
    
717
1c23952dbde1 refactoring
Edouard Tisserant
parents: 715
diff changeset
  1760
    frame = LPCBeremiz(None, ctr=CTR, debug=True)
547
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1761
    
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1762
    app.MainLoop()
5748d695beee Reorganization of threading for command line and wx main loops. Commands are now cleanly serialized through calls to wx.CallAfter. wx mainloop now runs on main thread.
Lolitech
parents: 543
diff changeset
  1763