LPCBeremiz.py
author edouard
Thu, 17 Feb 2011 17:04:10 +0100
changeset 574 1b6bd9f590aa
parent 572 c965548cb6f7
child 575 6765adf58711
permissions -rw-r--r--
Prevent status polling to generate an error while PLC is being reset to bootloader mode
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
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
     9
from types import TupleType, StringType, UnicodeType
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    10
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    11
CWD = os.path.split(os.path.realpath(__file__))[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    12
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    13
def Bpath(*args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    14
    return os.path.join(CWD,*args)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    15
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    16
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    17
    def usage():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    18
        print "\nUsage of LPCBeremiz.py :"
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    19
        print "\n   %s Projectpath Buildpath port\n"%sys.argv[0]
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    20
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    21
    try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    22
        opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    23
    except getopt.GetoptError:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    24
        # print help information and exit:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    25
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    26
        sys.exit(2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    27
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    28
    for o, a in opts:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    29
        if o in ("-h", "--help"):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    30
            usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    31
            sys.exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    32
    
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    33
    if len(args) != 3:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    34
        usage()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    35
        sys.exit()
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    36
    else:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    37
        projectOpen = args[0]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    38
        buildpath = args[1]
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    39
        try:
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    40
            port = int(args[2])
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    41
        except:
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    42
            usage()
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
    43
            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
    44
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
    45
    if os.path.exists("LPC_DEBUG"):
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
        __builtins__.BMZ_DBG = True
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
    47
    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
    48
        __builtins__.BMZ_DBG = False
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
    49
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
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
    51
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
    52
wx.InitAllImageHandlers()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    53
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    54
# Import module for internationalization
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    55
import gettext
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    56
import __builtin__
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 *
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
    62
from plugger import PluginsRoot, PlugTemplate, opjimg, connectors
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    63
from plcopen.structures import LOCATIONDATATYPES
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    64
from PLCControler import LOCATION_PLUGIN, LOCATION_MODULE, LOCATION_GROUP,\
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
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    68
#-------------------------------------------------------------------------------
512
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    69
#                          CANFESTIVAL PLUGIN HACK
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    70
#-------------------------------------------------------------------------------
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    71
from plugins.canfestival import canfestival
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    72
class LPC_canfestival_config:
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    73
    def getCFLAGS(self, *args):
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    74
        return ""
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    75
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    76
    def getLDFLAGS(self, *args):
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    77
        return ""
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    78
        
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    79
canfestival.local_canfestival_config = LPC_canfestival_config() 
36aeab46f27d Improved CanFEstival support for LPC - now build and link plugin generated files
edouard
parents: 510
diff changeset
    80
#-------------------------------------------------------------------------------
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    81
#                              LPCModule Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    82
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    83
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    84
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
    85
                  "Q": LOCATION_VAR_OUTPUT,
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    86
                  "M": LOCATION_VAR_MEMORY}
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    87
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    88
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
    89
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    90
LOCATION_SIZES = {}
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    91
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
    92
    for type in types:
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    93
        LOCATION_SIZES[type] = size
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
    94
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    95
def _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    96
    children = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    97
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    98
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
    99
            children.extend(child["children"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   100
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   101
            children.append(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   102
    return children
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   103
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   104
def _GetVariables(module):
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   105
    variables = []
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   106
    for child in module["children"]:
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   107
        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
   108
            variables.extend(_GetVariables(child))
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   109
        else:
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   110
            variables.append(child)
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   111
    return variables
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   112
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   113
def _GetLastModuleGroup(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   114
    group = module
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   115
    for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   116
        if child["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   117
            group = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   118
    return group["children"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   119
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   120
def _GetModuleBySomething(module, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   121
    for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   122
        if child.get(something) == toks[0]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   123
            if len(toks) > 1:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   124
                return _GetModuleBySomething(child, something, toks[1:])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   125
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   126
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   127
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
   128
def _GetModuleVariable(module, location, direction):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   129
    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
   130
        if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   131
            return child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   132
    return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   133
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   134
def _RemoveModuleChild(module, child):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   135
    if child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   136
        module["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   137
    else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   138
        for group in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   139
            if group["type"] == LOCATION_GROUP and child in group["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   140
                group["children"].remove(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   141
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   142
BUS_TEXT = """/* Code generated by LPCBus plugin */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   143
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   144
/* LPCBus plugin includes */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   145
#include "app_glue.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   146
#ifdef _WINDOWS_H
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   147
  #include "iec_types.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   148
#else
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   149
  #include "iec_std_lib.h"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   150
#endif
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   151
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   152
%(declare_code)s
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   153
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   154
/* LPCBus plugin user variables definition */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   155
%(var_decl)s
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   156
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   157
/* LPCBus plugin functions */
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   158
int __init_%(location_str)s(int argc,char **argv)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   159
{
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   160
%(init_code)s
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   161
  return 0;
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   162
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   163
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   164
void __cleanup_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   165
{
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   166
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   167
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   168
void __retrieve_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   169
{
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   170
%(retrieve_code)s
442
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 __publish_%(location_str)s(void)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   174
{
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   175
%(publish_code)s
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   176
}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   177
"""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   178
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   179
class LPCBus(object):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   180
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   181
    def __init__(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   182
        self.VariableLocationTree = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   183
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   184
        self.Icon = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   185
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   186
    def __getitem__(self, key):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   187
        if key == "children":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   188
            return self.VariableLocationTree
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   189
        raise KeyError, "Only 'children' key is available"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   190
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   191
    def SetIcon(self, icon):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   192
        self.Icon = icon
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   193
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   194
    def _GetChildBySomething(self, something, toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   195
        return _GetModuleBySomething({"children" : self.VariableLocationTree}, something, toks)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   196
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   197
    def GetBaseTypes(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   198
        return self.GetPlugRoot().GetBaseTypes()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   199
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   200
    def GetSizeOfType(self, type):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   201
        return LOCATION_SIZES[self.GetPlugRoot().GetBaseType(type)]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   202
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   203
    def _GetVariableLocationTree(self, current_location, infos):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   204
        if infos["type"] == LOCATION_MODULE:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   205
            location = current_location + (infos["IEC_Channel"],)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   206
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   207
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   208
                    "location": ".".join(map(str, location + ("x",))), 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   209
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   210
                    "children": [self._GetVariableLocationTree(location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   211
        elif infos["type"] == LOCATION_GROUP:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   212
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   213
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   214
                    "location": "", 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   215
                    "icon": infos["icon"], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   216
                    "children": [self._GetVariableLocationTree(current_location, child) for child in infos["children"]]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   217
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   218
            size = self.GetSizeOfType(infos["IEC_type"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   219
            location = "%" + LOCATION_DIRS[infos["type"]] + size + ".".join(map(str, current_location + infos["location"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   220
            return {"name": infos["name"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   221
                    "type": infos["type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   222
                    "size": size,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   223
                    "IEC_type": infos["IEC_type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   224
                    "location": location,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   225
                    "description": infos["description"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   226
                    "children": []}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   227
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   228
    def GetVariableLocationTree(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   229
        return {"name": self.BaseParams.getName(),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   230
                "type": LOCATION_PLUGIN,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   231
                "location": self.GetFullIEC_Channel(),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   232
                "icon": self.Icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   233
                "children": [self._GetVariableLocationTree(self.GetCurrentLocation(), child) 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   234
                             for child in self.VariableLocationTree]}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   235
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   236
    def PlugTestModified(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   237
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   238
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   239
    def PlugMakeDir(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   240
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   241
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   242
    def PlugRequestSave(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   243
        return None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   244
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   245
    def ResetUsedLocations(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   246
        self.UsedLocations = {}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   247
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   248
    def _AddUsedLocation(self, parent, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   249
        num = location.pop(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   250
        if not parent.has_key(num):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   251
            parent[num] = {"used": False, "children": {}}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   252
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   253
            self._AddUsedLocation(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   254
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   255
            parent[num]["used"] = True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   256
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   257
    def AddUsedLocation(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   258
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   259
            self._AddUsedLocation(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   260
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   261
    def _CheckLocationConflicts(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
            return False
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
            if parent[num]["used"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   267
                return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   268
            return self._CheckLocationConflicts(parent[num]["children"], location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   269
        elif len(parent[num]["children"]) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   270
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   271
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   272
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   273
    def CheckLocationConflicts(self, location):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   274
        if len(location) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   275
            return self._CheckLocationConflicts(self.UsedLocations, list(location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   276
        return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   277
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   278
    def PlugGenerate_C(self, buildpath, locations):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   279
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   280
        Generate C code
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   281
        @param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   282
        @param locations: List of complete variables locations \
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   283
            [{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   284
            "NAME" : name of the variable (generally "__IW0_1_2" style)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   285
            "DIR" : direction "Q","I" or "M"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   286
            "SIZE" : size "X", "B", "W", "D", "L"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   287
            "LOC" : tuple of interger for IEC location (0,1,2,...)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   288
            }, ...]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   289
        @return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   290
        """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   291
        current_location = self.GetCurrentLocation()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   292
        # define a unique name for the generated C file
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   293
        location_str = "_".join(map(str, current_location))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   294
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   295
        code_str = {"location_str": location_str,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   296
                    "var_decl": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   297
                    "declare_code": "",
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   298
                    "init_code": "",
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   299
                    "retrieve_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   300
                    "publish_code": "",
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   301
                   }
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   302
        
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   303
        for module in _GetModuleChildren(self):
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   304
            if module["init"] != "":
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   305
                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
   306
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   307
        # Adding variables
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   308
        vars = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   309
        self.ResetUsedLocations()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   310
        for location in locations:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   311
            loc = location["LOC"][len(current_location):]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   312
            group = next = self
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   313
            i = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   314
            while next is not None and i < len(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   315
                next = self._GetChildBySomething("IEC_Channel", loc[:i + 1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   316
                if next is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   317
                    i += 1
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   318
                    group = next
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   319
            var_loc = loc[i:]
530
862d9adcd904 Bug when trying to generate LPCBus code fixed
laurent
parents: 526
diff changeset
   320
            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
   321
                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
   322
#                    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
   323
#                        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
   324
#                    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
   325
#                        raise Exception, "Type conflict in variable definition"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   326
                    if location["DIR"] == "Q":
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   327
                        if self.CheckLocationConflicts(location["LOC"]):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   328
                            raise Exception, "BYTE and BIT from the same BYTE can't be used together"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   329
                        self.AddUsedLocation(location["LOC"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   330
                    vars.append({"location": location["NAME"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   331
                                 "Type": variable["IEC_type"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   332
                                 "Retrieve": variable["retrieve"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   333
                                 "Publish": variable["publish"],
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   334
                                })
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   335
                    break
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   336
        base_types = self.GetPlugRoot().GetBaseTypes()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   337
        for var in vars:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   338
            prefix = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   339
            if var["Type"] in base_types:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   340
                prefix = "IEC_"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   341
            code_str["var_decl"] += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   342
            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
   343
            if var["Retrieve"] != "":
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   344
                code_str["retrieve_code"] += "  " + var["Retrieve"] % ("*" + var["location"]) + "\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   345
            if var["Publish"] != "":
550
b03f586547c9 Adding support for initialize all LPC module variables even if not used
laurent
parents: 549
diff changeset
   346
                code_str["publish_code"] += "  " + var["Publish"] % ("*" + var["location"]) + "\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   347
        
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
   348
        Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   349
        module = open(Gen_Module_path,'w')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   350
        module.write(BUS_TEXT % code_str)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   351
        module.close()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   352
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   353
        matiec_flags = '"-I%s"'%os.path.abspath(self.GetPlugRoot().GetIECLibPath())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   354
        return [(Gen_Module_path, matiec_flags)],"",True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   355
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   356
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   357
#                              LPCPluginsRoot Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   358
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   359
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   360
def mycopytree(src, dst):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   361
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   362
    Copy content of a directory to an other, omit hidden files
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   363
    @param src: source directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   364
    @param dst: destination directory
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   365
    """
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   366
    for i in os.listdir(src):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   367
        if not i.startswith('.'):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   368
            srcpath = os.path.join(src,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   369
            dstpath = os.path.join(dst,i)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   370
            if os.path.isdir(srcpath):
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   371
                if os.path.exists(dstpath):
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   372
                    shutil.rmtree(dstpath)
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   373
                os.makedirs(dstpath)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   374
                mycopytree(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   375
            elif os.path.isfile(srcpath):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   376
                shutil.copy2(srcpath, dstpath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   377
572
c965548cb6f7 Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents: 571
diff changeset
   378
[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
   379
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   380
class LPCPluginsRoot(PluginsRoot):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   381
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   382
    PluginMethods = [
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   383
        {"bitmap" : opjimg("Debug"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   384
         "name" : _("Simulate"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   385
         "tooltip" : _("Simulate PLC"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   386
         "method" : "_Simulate"},
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   387
        {"bitmap" : opjimg("Run"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   388
         "name" : _("Run"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   389
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   390
         "tooltip" : _("Start PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   391
         "method" : "_Run"},
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   392
        {"bitmap" : opjimg("Stop"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   393
         "name" : _("Stop"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   394
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   395
         "tooltip" : _("Stop Running PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   396
         "method" : "_Stop"},
541
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   397
        {"bitmap" : opjimg("Build"),
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   398
         "name" : _("Build"),
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   399
         "tooltip" : _("Build project into build folder"),
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   400
         "method" : "_build"},
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   401
        {"bitmap" : opjimg("Transfer"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   402
         "name" : _("Transfer"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   403
         "shown" : False,
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   404
         "tooltip" : _("Transfer PLC"),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   405
         "method" : "_Transfer"},
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   406
    ]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   407
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   408
    def __init__(self, frame, logger):
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   409
        PluginsRoot.__init__(self, frame, logger)
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   410
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   411
        self.PlugChildsTypes += [("LPCBus", LPCBus, "LPC bus")]
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   412
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   413
        self.OnlineMode = "OFF"
561
4cc6eef4778f Fix bug on LPCConnector initial value
laurent
parents: 560
diff changeset
   414
        self.LPCConnector = None
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   415
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   416
        self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   417
        self.previous_mode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   418
        
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   419
        self.SimulationBuildPath = None
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   420
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   421
        self.AbortTransferTimer = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   422
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   423
    def GetProjectName(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   424
        return self.Project.getname()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   425
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   426
    def GetDefaultTargetName(self):
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   427
        if self.CurrentMode == SIMULATION_MODE:
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   428
            return PluginsRoot.GetDefaultTargetName(self)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   429
        else:
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   430
            return "LPC"
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   431
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   432
    def GetTarget(self):
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   433
        target = PluginsRoot.GetTarget(self)
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   434
        if self.CurrentMode != SIMULATION_MODE:
510
8038c08b9874 Getting default target when no target defined fixed
laurent
parents: 503
diff changeset
   435
            target.getcontent()["value"].setBuildPath(self.BuildPath)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   436
        return target
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   437
    
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   438
    def _getBuildPath(self):
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   439
        if self.CurrentMode == SIMULATION_MODE:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   440
            if self.SimulationBuildPath is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   441
                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
   442
            return self.SimulationBuildPath
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   443
        else:
494
9e4263099427 Bug when opening with not empty buildpath parameter fixed
laurent
parents: 492
diff changeset
   444
            return PluginsRoot._getBuildPath(self)
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   445
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   446
    def _build(self):
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   447
        if self.BuildPath is not None:
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   448
            mycopytree(self.OrigBuildPath, self.BuildPath)
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   449
        PluginsRoot._build(self)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   450
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   451
    def SetProjectName(self, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   452
        return self.Project.setname(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   453
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   454
    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
   455
        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
   456
            self.OnlineMode = mode.upper()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   457
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   458
            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
   459
                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
   460
                try:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   461
                    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
   462
                except Exception, msg:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   463
                    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
   464
                    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
   465
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   466
                # Did connection success ?
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   467
                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
   468
                    # Oups.
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   469
                    self.logger.write_error(_("Connection failed to %s!\n")%uri)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   470
                
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   471
            else:
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   472
                self.LPCConnector = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   473
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   474
            self.ApplyOnlineMode()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   475
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   476
    def ApplyOnlineMode(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   477
        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
   478
            self.KillDebugThread()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   479
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   480
            self._connector = self.LPCConnector
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   481
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   482
            # 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
   483
            self.UpdateMethodsFromPLCStatus()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   484
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   485
            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
   486
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   487
                self.CompareLocalAndRemotePLC()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   488
                            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   489
                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
   490
                    status = _(self.previous_plcstate)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   491
                else:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   492
                    status = ""
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   493
                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
   494
                
543
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   495
                if self.StatusTimer and not self.StatusTimer.IsRunning():
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   496
                    # Start the status Timer
572
c965548cb6f7 Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents: 571
diff changeset
   497
                    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
   498
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   499
                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
   500
                    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
   501
                        self.logger.write(_("Debug connect matching running PLC\n"))
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
   502
                        #TODO re-enable
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
   503
                        #self._connect_debug()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   504
                    else:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   505
                        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
   506
            
543
3dec6ff88620 Disabled boring standard conformance checks, fixed possible race condition with StatusTimer, fixed warning message in AbortTransfer
Lolitech
parents: 541
diff changeset
   507
            elif self.StatusTimer and self.StatusTimer.IsRunning():
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   508
                self.StatusTimer.Stop()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   509
            
572
c965548cb6f7 Fixed MD5 computation for makefile based toolchain, helps avoiding unnecessary builds
edouard
parents: 571
diff changeset
   510
            if self.CurrentMode == TRANSFER_MODE:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   511
                
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   512
                if self.OnlineMode == "BOOTLOADER":
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   513
                    self.BeginTransfer()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   514
                
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   515
                elif self.OnlineMode == "APPLICATION":
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   516
                    self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   517
                    self.AbortTransferTimer.Stop()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   518
                    self.AbortTransferTimer = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   519
                    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   520
                    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
   521
    
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
   522
    # 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
   523
    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
   524
        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
   525
        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
   526
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
   527
    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
   528
        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
   529
        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
   530
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
   531
    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
   532
        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
   533
        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
   534
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   535
    def LoadProject(self, ProjectPath, BuildPath=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   536
        """
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   537
        Load a project contained in a folder
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   538
        @param ProjectPath: path of the project folder
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   539
        """
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   540
        if os.path.basename(ProjectPath) == "":
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   541
            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
   542
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   543
        # Verify that project contains a PLCOpen program
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   544
        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
   545
        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
   546
            # 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
   547
            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
   548
            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
   549
                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
   550
        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
   551
            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
   552
                                   "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
   553
                                   "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
   554
                                   "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
   555
                                   "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
   556
                                   "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
   557
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   558
        # Change XSD into class members
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   559
        self._AddParamsMembers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   560
        self.PluggedChilds = {}
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
   561
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   562
        # Keep track of the root plugin (i.e. project path)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   563
        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
   564
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   565
        self.BuildPath = self._getBuildPath()
503
4c0cd5e54e1b LPC build and protocol tweaks
edouard
parents: 501
diff changeset
   566
        self.OrigBuildPath = BuildPath
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   567
        if BuildPath is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   568
            mycopytree(BuildPath, self.BuildPath)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   569
        
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   570
        # If dir have already be made, and file exist
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   571
        if os.path.isdir(self.PlugPath()) and os.path.isfile(self.PluginXmlFilePath()):
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   572
            #Load the plugin.xml file into parameters members
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   573
            result = self.LoadXMLParams()
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   574
            if result:
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   575
                return result
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   576
            #Load and init all the childs
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   577
            self.LoadChilds()
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
   578
        
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
   579
        if self.PlugTestModified():
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
   580
            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
   581
        
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   582
        if wx.GetApp() is None:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   583
            self.RefreshPluginsBlockLists()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   584
        else:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   585
            wx.CallAfter(self.RefreshPluginsBlockLists)
478
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   586
029688dad14d Replacing target_Makefile by target_LPC
laurent
parents: 472
diff changeset
   587
        return None
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   588
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   589
    ############# Real PLC object access #############
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   590
    def UpdateMethodsFromPLCStatus(self):
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   591
        # Get PLC state : Running or Stopped
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   592
        # 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
   593
        if self.OnlineMode == "OFF":
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   594
            status = "Disconnected"
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   595
        elif self.OnlineMode == "BOOTLOADER":
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   596
            status = "Connected"
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   597
        else:
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   598
            if self._connector is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   599
                status = self._connector.GetPLCstatus()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   600
            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   601
                status = "Disconnected"
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   602
        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
   603
            simulating = self.CurrentMode == SIMULATION_MODE
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   604
            for args in {
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   605
                     "Started" :     [("_Simulate", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   606
                                      ("_Run", False),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   607
                                      ("_Stop", True),
560
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   608
                                      ("_build", True),
559
0f5544587037 Fix buttons state according to online mode
laurent
parents: 555
diff changeset
   609
                                      ("_Transfer", True)],
0f5544587037 Fix buttons state according to online mode
laurent
parents: 555
diff changeset
   610
                     "Stopped" :     [("_Simulate", False),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   611
                                      ("_Run", True),
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   612
                                      ("_Stop", False),
560
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   613
                                      ("_build", True),
559
0f5544587037 Fix buttons state according to online mode
laurent
parents: 555
diff changeset
   614
                                      ("_Transfer", True)],
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   615
                     "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
   616
                                      ("_Run", True),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   617
                                      ("_Stop", simulating),
560
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   618
                                      ("_build", True),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   619
                                      ("_Transfer", True)],
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   620
                     "Disconnected" :[("_Simulate", not simulating),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   621
                                      ("_Run", False),
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   622
                                      ("_Stop", simulating),
541
4d9ca788205e Adding compile button when unconnected
laurent
parents: 539
diff changeset
   623
                                      ("_build", True),
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   624
                                      ("_Transfer", False)],
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   625
                   }.get(status,[]):
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   626
                self.ShowMethod(*args)
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   627
            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
   628
            self.previous_mode = self.CurrentMode
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   629
            return True
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   630
        return False
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
   631
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   632
    def Generate_plc_declare_locations(self):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   633
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   634
        Declare used locations in order to simulatePLC in a black box
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   635
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   636
        return """#include "iec_types_all.h"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   637
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   638
#define __LOCATED_VAR(type, name, ...) \
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   639
type beremiz_##name;\
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   640
type *name = &beremiz_##name;
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   641
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   642
#include "LOCATED_VARIABLES.h"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   643
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   644
#undef __LOCATED_VAR
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   645
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   646
"""
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   647
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   648
    def _Simulate(self):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   649
        """
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   650
        Method called by user to Simulate PLC
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   651
        """
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   652
        self.CurrentMode = SIMULATION_MODE
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   653
        
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   654
        uri = "LOCAL://"
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   655
        try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   656
            self._connector = connectors.ConnectorFactory(uri, self)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   657
        except Exception, msg:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   658
            self.logger.write_error(_("Exception while connecting %s!\n")%uri)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   659
            self.logger.write_error(traceback.format_exc())
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   660
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   661
        # Did connection success ?
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   662
        if self._connector is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   663
            # Oups.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   664
            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
   665
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   666
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   667
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   668
        buildpath = self._getBuildPath()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   669
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   670
        # Eventually create build dir
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   671
        if not os.path.exists(buildpath):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   672
            os.makedirs(buildpath)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   673
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   674
        # Generate SoftPLC IEC code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   675
        IECGenRes = self._Generate_SoftPLC()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   676
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   677
         # If IEC code gen fail, bail out.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   678
        if not IECGenRes:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   679
            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
   680
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   681
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   682
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   683
        # Reset variable and program list that are parsed from
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   684
        # CSV file generated by IEC2C compiler.
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   685
        self.ResetIECProgramsAndVariables()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   686
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   687
        gen_result = self.PlugGenerate_C(buildpath, self.PLCGeneratedLocatedVars)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   688
        PlugCFilesAndCFLAGS, PlugLDFLAGS, DoCalls = gen_result[:3]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   689
        # if some files have been generated put them in the list with their location
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   690
        if PlugCFilesAndCFLAGS:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   691
            self.LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), PlugCFilesAndCFLAGS, DoCalls)]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   692
        else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   693
            self.LocationCFilesAndCFLAGS = []
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   694
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   695
        # plugin asks for some LDFLAGS
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   696
        if PlugLDFLAGS:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   697
            # LDFLAGS can be either string
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   698
            if type(PlugLDFLAGS)==type(str()):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   699
                self.LDFLAGS=[PlugLDFLAGS]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   700
            #or list of strings
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   701
            elif type(PlugLDFLAGS)==type(list()):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   702
                self.LDFLAGS=PlugLDFLAGS[:]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   703
        else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   704
            self.LDFLAGS=[]
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   705
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   706
        # Template based part of C code generation
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   707
        # files are stacked at the beginning, as files of plugin tree root
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   708
        for generator, filename, name in [
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   709
           # debugger code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   710
           (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   711
           # init/cleanup/retrieve/publish, run and align code
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   712
           (self.Generate_plc_common_main,"plc_common_main.c","Common runtime"),
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   713
           # declare located variables for simulate in a black box
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   714
           (self.Generate_plc_declare_locations,"plc_declare_locations.c","Declare Locations")]:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   715
            try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   716
                # Do generate
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   717
                code = generator()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   718
                if code is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   719
                     raise
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   720
                code_path = os.path.join(buildpath,filename)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   721
                open(code_path, "w").write(code)
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   722
                # Insert this file as first file to be compiled at root plugin
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   723
                self.LocationCFilesAndCFLAGS[0][1].insert(0,(code_path, self.plcCFLAGS))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   724
            except Exception, exc:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   725
                self.logger.write_error(name+_(" generation failed !\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   726
                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
   727
                self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   728
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   729
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   730
        # Get simulation builder
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   731
        builder = self.GetBuilder()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   732
        if builder is None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   733
            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
   734
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   735
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   736
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   737
        # Build
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   738
        try:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   739
            if not builder.build() :
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   740
                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
   741
                self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   742
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   743
        except Exception, exc:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   744
            self.logger.write_error(_("C Build crashed !\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   745
            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
   746
            self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   747
            return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   748
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   749
        data = builder.GetBinaryCode()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   750
        if data is not None :
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   751
            if self._connector.NewPLC(builder.GetBinaryCodeMD5(), data, []):
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   752
                if self.AppFrame is not None:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   753
                    self.AppFrame.CloseDebugTabs()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   754
                    self.AppFrame.RefreshInstancesTree()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   755
                self.UnsubscribeAllDebugIECVariable()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   756
                self.ProgramTransferred()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   757
                self.logger.write(_("Transfer completed successfully.\n"))
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   758
            else:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   759
                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
   760
                self.StopSimulation()
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   761
                return False
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   762
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   763
        self._Run()
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   764
                
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   765
        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
   766
            # Start the status Timer
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   767
            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
   768
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   769
    def StopSimulation(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   770
        self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   771
        self.ApplyOnlineMode()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   772
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   773
    def _Stop(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   774
        PluginsRoot._Stop(self)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   775
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   776
        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
   777
            self.StopSimulation()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   778
560
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   779
    def CompareLocalAndRemotePLC(self):
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   780
        if self.LPCConnector is None:
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   781
            return
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   782
        # We are now connected. Update button status
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   783
        MD5 = self.GetLastBuildMD5()
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   784
        # Check remote target PLC correspondance to that md5
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   785
        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
   786
            # warns controller that program match
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   787
            self.ProgramTransferred()
681fe60443fc Fix transfer button enable state and build button state
laurent
parents: 559
diff changeset
   788
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
   789
    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
   790
        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
   791
        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
   792
            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
   793
        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
   794
            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
   795
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   796
    def _Transfer(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   797
        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
   798
            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
   799
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   800
            PluginsRoot._build(self)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   801
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   802
            ID_ABORTTRANSFERTIMER = wx.NewId()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   803
            self.AbortTransferTimer = wx.Timer(self.AppFrame, ID_ABORTTRANSFERTIMER)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   804
            self.AppFrame.Bind(wx.EVT_TIMER, self.AbortTransfer, self.AbortTransferTimer)  
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   805
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   806
            if self.OnlineMode == "BOOTLOADER":
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   807
                self.BeginTransfer()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   808
            
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   809
            else:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   810
                self.logger.write(_("Resetting PLC\n"))
574
1b6bd9f590aa Prevent status polling to generate an error while PLC is being reset to bootloader mode
edouard
parents: 572
diff changeset
   811
                self.StatusTimer.Stop()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   812
                self.LPCConnector.ResetPLC()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   813
                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
   814
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   815
    def BeginTransfer(self):
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   816
        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
   817
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   818
        self.AbortTransferTimer.Stop()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   819
        PluginsRoot._Transfer(self)
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   820
        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
   821
    
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   822
    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
   823
        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
   824
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   825
        self.CurrentMode = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   826
        self.AbortTransferTimer.Stop()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   827
        self.AbortTransferTimer = None
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   828
        event.Skip()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   829
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
   830
    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
   831
        """
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
   832
        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
   833
        """
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
   834
        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
   835
            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
   836
            self.logger.write(_("Starting 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
   837
            #TODO re-enable
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
   838
            #self._connect_debug()
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
   839
        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
   840
            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
   841
        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
   842
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   843
#-------------------------------------------------------------------------------
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   844
#                              LPCBeremiz Class
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   845
#-------------------------------------------------------------------------------
549
5dd92bd6e6e5 Fixed bug on frame close.
Lolitech
parents: 547
diff changeset
   846
lpcberemiz_cmd=None
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   847
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   848
class LPCBeremiz(Beremiz):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   849
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   850
    def _init_coll_FileMenu_Items(self, parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   851
        AppendMenu(parent, help='', id=wx.ID_SAVE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   852
              kind=wx.ITEM_NORMAL, text=_(u'Save\tCTRL+S'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   853
        AppendMenu(parent, help='', id=wx.ID_CLOSE,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   854
              kind=wx.ITEM_NORMAL, text=_(u'Close Tab\tCTRL+W'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   855
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   856
        AppendMenu(parent, help='', id=wx.ID_PAGE_SETUP,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   857
              kind=wx.ITEM_NORMAL, text=_(u'Page Setup'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   858
        AppendMenu(parent, help='', id=wx.ID_PREVIEW,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   859
              kind=wx.ITEM_NORMAL, text=_(u'Preview'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   860
        AppendMenu(parent, help='', id=wx.ID_PRINT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   861
              kind=wx.ITEM_NORMAL, text=_(u'Print'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   862
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   863
        AppendMenu(parent, help='', id=wx.ID_PROPERTIES,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   864
              kind=wx.ITEM_NORMAL, text=_(u'Properties'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   865
        parent.AppendSeparator()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   866
        AppendMenu(parent, help='', id=wx.ID_EXIT,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   867
              kind=wx.ITEM_NORMAL, text=_(u'Quit\tCTRL+Q'))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   868
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   869
        self.Bind(wx.EVT_MENU, self.OnSaveProjectMenu, id=wx.ID_SAVE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   870
        self.Bind(wx.EVT_MENU, self.OnCloseTabMenu, id=wx.ID_CLOSE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   871
        self.Bind(wx.EVT_MENU, self.OnPageSetupMenu, id=wx.ID_PAGE_SETUP)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   872
        self.Bind(wx.EVT_MENU, self.OnPreviewMenu, id=wx.ID_PREVIEW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   873
        self.Bind(wx.EVT_MENU, self.OnPrintMenu, id=wx.ID_PRINT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   874
        self.Bind(wx.EVT_MENU, self.OnPropertiesMenu, id=wx.ID_PROPERTIES)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   875
        self.Bind(wx.EVT_MENU, self.OnQuitMenu, id=wx.ID_EXIT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   876
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   877
    def _init_ctrls(self, prnt):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   878
        IDEFrame._init_ctrls(self, prnt)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   879
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   880
        self.Bind(wx.EVT_MENU, self.OnOpenWidgetInspector, id=ID_BEREMIZINSPECTOR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   881
        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
   882
        self.SetAcceleratorTable(accel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   883
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   884
        self.PLCConfig = wx.ScrolledWindow(id=ID_BEREMIZPLCCONFIG,
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   885
              name='PLCConfig', parent=self.LeftNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   886
              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
   887
        self.PLCConfig.SetBackgroundColour(wx.WHITE)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   888
        self.PLCConfig.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   889
        self.PLCConfig.Bind(wx.EVT_SIZE, self.OnMoveWindow)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   890
        self.LeftNoteBook.InsertPage(0, self.PLCConfig, _("Topology"), True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   891
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   892
        self.LogConsole = wx.TextCtrl(id=ID_BEREMIZLOGCONSOLE, value='',
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   893
                  name='LogConsole', parent=self.BottomNoteBook, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   894
                  size=wx.Size(0, 0), style=wx.TE_MULTILINE|wx.TE_RICH2)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   895
        self.LogConsole.Bind(wx.EVT_LEFT_DCLICK, self.OnLogConsoleDClick)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   896
        self.BottomNoteBook.AddPage(self.LogConsole, _("Log Console"))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   897
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   898
        self._init_beremiz_sizers()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   899
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   900
    def OnCloseFrame(self, event):
519
3a5faff52e5c Adding message to standard output to signal when LPCBeremiz is closed
laurent
parents: 517
diff changeset
   901
        global frame
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   902
        
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   903
        frame.Hide()
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   904
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   905
        self.PluginRoot.ResetAppFrame(lpcberemiz_cmd.Log)
492
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   906
        if self.PluginRoot.OnlineMode == 0:
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   907
            self.PluginRoot._connector = None
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   908
        
0852c4682179 Adding support for simulation in LPCBeremiz
laurent
parents: 487
diff changeset
   909
        self.PluginRoot.KillDebugThread()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   910
        self.KillLocalRuntime()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   911
        
552
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
   912
        lpcberemiz_cmd.Log.write("Closed\n")
519
3a5faff52e5c Adding message to standard output to signal when LPCBeremiz is closed
laurent
parents: 517
diff changeset
   913
        
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
   914
        event.Veto()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   915
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
   916
    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
   917
        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
   918
        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
   919
        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
   920
        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
   921
            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
   922
            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
   923
            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
   924
                self.Controler.SetProjectProperties(None, new_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
   925
                self._Refresh(TITLE, TOOLBAR, FILEMENU, EDITMENU, DISPLAYMENU, 
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
   926
                              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
   927
        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
   928
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   929
    def RefreshFileMenu(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   930
        if self.PluginRoot is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   931
            selected = self.TabsOpened.GetSelection()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   932
            if selected >= 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   933
                graphic_viewer = isinstance(self.TabsOpened.GetPage(selected), Viewer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   934
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   935
                graphic_viewer = False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   936
            if self.TabsOpened.GetPageCount() > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   937
                self.FileMenu.Enable(wx.ID_CLOSE, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   938
                if graphic_viewer:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   939
                    self.FileMenu.Enable(wx.ID_PREVIEW, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   940
                    self.FileMenu.Enable(wx.ID_PRINT, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   941
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   942
                    self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   943
                    self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   944
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   945
                self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   946
                self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   947
                self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   948
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, True)
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
   949
            self.FileMenu.Enable(wx.ID_SAVE, self.PluginRoot.PlugTestModified())
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   950
            self.FileMenu.Enable(wx.ID_PROPERTIES, True)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   951
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   952
            self.FileMenu.Enable(wx.ID_CLOSE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   953
            self.FileMenu.Enable(wx.ID_PAGE_SETUP, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   954
            self.FileMenu.Enable(wx.ID_PREVIEW, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   955
            self.FileMenu.Enable(wx.ID_PRINT, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   956
            self.FileMenu.Enable(wx.ID_SAVE, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   957
            self.FileMenu.Enable(wx.ID_PROPERTIES, False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   958
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   959
    def RefreshPLCParams(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   960
        self.Freeze()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   961
        self.ClearSizer(self.PLCParamsSizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   962
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   963
        if self.PluginRoot is not None:    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   964
            plcwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   965
            if self.PluginRoot.PlugTestModified():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   966
                bkgdclr = CHANGED_TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   967
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   968
                bkgdclr = TITLE_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   969
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   970
            if self.PluginRoot not in self.PluginInfos:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   971
                self.PluginInfos[self.PluginRoot] = {"right_visible" : False}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   972
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   973
            plcwindow.SetBackgroundColour(TITLE_COLOUR)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   974
            plcwindow.Bind(wx.EVT_LEFT_DOWN, self.OnPanelLeftDown)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   975
            self.PLCParamsSizer.AddWindow(plcwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   976
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   977
            plcwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   978
            plcwindow.SetSizer(plcwindowsizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   979
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   980
            st = wx.StaticText(plcwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   981
            st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   982
            st.SetLabel(self.PluginRoot.GetProjectName())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   983
            plcwindowsizer.AddWindow(st, 0, border=5, flag=wx.ALL|wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   984
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   985
            plcwindowmainsizer = wx.BoxSizer(wx.VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   986
            plcwindowsizer.AddSizer(plcwindowmainsizer, 0, border=5, flag=wx.ALL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   987
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   988
            plcwindowbuttonsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   989
            plcwindowmainsizer.AddSizer(plcwindowbuttonsizer, 0, border=0, flag=wx.ALIGN_CENTER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   990
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   991
            msizer = self.GenerateMethodButtonSizer(self.PluginRoot, plcwindow, not self.PluginInfos[self.PluginRoot]["right_visible"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   992
            plcwindowbuttonsizer.AddSizer(msizer, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   993
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   994
        self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   995
        self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   996
        self.Thaw()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   997
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   998
    def GenerateTreeBranch(self, plugin):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
   999
        leftwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1000
        if plugin.PlugTestModified():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1001
            bkgdclr=CHANGED_WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1002
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1003
            bkgdclr=WINDOW_COLOUR
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1004
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1005
        leftwindow.SetBackgroundColour(bkgdclr)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1006
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1007
        if plugin not in self.PluginInfos:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1008
            self.PluginInfos[plugin] = {"expanded" : False, "left_visible" : False, "right_visible" : False}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1009
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1010
        self.PluginInfos[plugin]["children"] = plugin.IECSortedChilds()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1011
        plugin_infos = plugin.GetVariableLocationTree()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1012
        plugin_locations = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1013
        if len(self.PluginInfos[plugin]["children"]) == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1014
            plugin_locations = plugin_infos["children"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1015
            if not self.PluginInfos[plugin].has_key("locations_infos"):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1016
                self.PluginInfos[plugin]["locations_infos"] = {"root": {"expanded" : False}}
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1017
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1018
            self.PluginInfos[plugin]["locations_infos"]["root"]["children"] = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1019
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1020
        self.PluginTreeSizer.AddWindow(leftwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1021
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1022
        leftwindowsizer = wx.BoxSizer(wx.HORIZONTAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1023
        leftwindow.SetSizer(leftwindowsizer)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1024
                
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1025
        st = wx.StaticText(leftwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1026
        st.SetFont(wx.Font(faces["size"], wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1027
        st.SetLabel(plugin.GetFullIEC_Channel())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1028
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1029
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1030
        expandbutton_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1031
        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
  1032
              name='ExpandButton', parent=leftwindow, pos=wx.Point(0, 0),
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1033
              size=wx.Size(13, 13), style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1034
        expandbutton.labelDelta = 0
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1035
        expandbutton.SetBezelWidth(0)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1036
        expandbutton.SetUseFocusIndicator(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1037
        expandbutton.SetBitmapSelected(wx.Bitmap(Bpath( 'images', 'minus.png')))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1038
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1039
        if len(self.PluginInfos[plugin]["children"]) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1040
            expandbutton.SetToggle(self.PluginInfos[plugin]["expanded"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1041
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1042
                if expandbutton.GetToggle():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1043
                    self.ExpandPlugin(plugin)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1044
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1045
                    self.CollapsePlugin(plugin)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1046
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1047
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1048
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1049
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1050
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1051
        elif len(plugin_locations) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1052
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1053
            expandbutton.SetToggle(locations_infos["root"]["expanded"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1054
            def togglebutton(event):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1055
                if expandbutton.GetToggle():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1056
                    self.ExpandLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1057
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1058
                    self.CollapseLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1059
                self.PluginInfos[plugin]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1060
                locations_infos["root"]["expanded"] = expandbutton.GetToggle()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1061
                self.PLCConfigMainSizer.Layout()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1062
                self.RefreshScrollBars()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1063
                event.Skip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1064
            expandbutton.Bind(wx.EVT_BUTTON, togglebutton, id=expandbutton_id)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1065
        else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1066
            expandbutton.Enable(False)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1067
        leftwindowsizer.AddWindow(expandbutton, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1068
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1069
        sb = wx.StaticBitmap(leftwindow, -1)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1070
        icon = plugin_infos.get("icon", None)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1071
        if icon is None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1072
            icon = os.path.join(base_folder, "plcopeneditor", 'Images', '%s.png' % self.LOCATION_BITMAP[plugin_infos["type"]])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1073
        sb.SetBitmap(wx.Bitmap(icon))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1074
        leftwindowsizer.AddWindow(sb, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1075
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1076
        st_id = wx.NewId()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1077
        st = wx.StaticText(leftwindow, st_id, size=wx.DefaultSize, style=wx.NO_BORDER)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1078
        st.SetFont(wx.Font(faces["size"] * 0.75, wx.DEFAULT, wx.NORMAL, wx.BOLD, faceName = faces["helv"]))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1079
        st.SetLabel(plugin.MandatoryParams[1].getName())
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1080
        leftwindowsizer.AddWindow(st, 0, border=5, flag=wx.RIGHT|wx.ALIGN_CENTER_VERTICAL)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1081
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1082
        rightwindow = wx.Panel(self.PLCConfig, -1, size=wx.Size(-1, -1))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1083
        rightwindow.SetBackgroundColour(bkgdclr)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1084
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1085
        self.PluginTreeSizer.AddWindow(rightwindow, 0, border=0, flag=wx.GROW)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1086
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1087
        self.PluginInfos[plugin]["left"] = leftwindow
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1088
        self.PluginInfos[plugin]["right"] = rightwindow
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1089
        for child in self.PluginInfos[plugin]["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1090
            self.GenerateTreeBranch(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1091
            if not self.PluginInfos[child]["expanded"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1092
                self.CollapsePlugin(child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1093
        if len(plugin_locations) > 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1094
            locations_infos = self.PluginInfos[plugin]["locations_infos"]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1095
            for location in plugin_locations:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1096
                locations_infos["root"]["children"].append("root.%s" % location["name"])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1097
                self.GenerateLocationTreeBranch(locations_infos, "root", location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1098
            if not locations_infos["root"]["expanded"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1099
                self.CollapseLocation(locations_infos, "root")
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1100
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1101
class StdoutPseudoFile:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1102
    
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1103
    def __init__(self, port):
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1104
        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
  1105
        self.socket.connect(('localhost', port))
552
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1106
        self.Buffer = ""
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1107
    
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1108
    def __del__(self):
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1109
        self.socket.close()
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1110
    
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1111
    def readline(self):
552
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1112
        idx = self.Buffer.find("\n")
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1113
        if idx == -1:
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1114
            self.Buffer += self.socket.recv(2048)
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1115
            idx = self.Buffer.find("\n")
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1116
        if idx != -1:
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1117
            line = self.Buffer[:idx+1]
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1118
            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
  1119
            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
  1120
                print "command >"+line
552
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1121
            return line
ab7916df0de7 Bug with recv from socket fixed
laurent
parents: 551
diff changeset
  1122
        return ""
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1123
    
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1124
    """ Base class for file like objects to facilitate StdOut for the Shell."""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1125
    def write(self, s, style = None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1126
        if s != '':
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1127
            self.socket.send(s)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1128
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1129
    def write_warning(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1130
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1131
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1132
    def write_error(self, s):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1133
        self.write(s)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1134
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1135
    def flush(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1136
        pass
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1137
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1138
    def isatty(self):
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1139
        return False
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1140
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1141
if __name__ == '__main__':
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1142
    
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
  1143
    from threading import Thread, Timer, Semaphore
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1144
    import cmd
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1145
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
  1146
    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
  1147
    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
  1148
    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
  1149
        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
  1150
        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
  1151
        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
  1152
            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
  1153
        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
  1154
            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
  1155
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
  1156
    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
  1157
        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
  1158
        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
  1159
        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
  1160
        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
  1161
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
  1162
    # 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
  1163
    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
  1164
        __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
  1165
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1166
    class LPCBeremiz_Cmd(cmd.Cmd):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1167
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1168
        prompt = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1169
        RefreshTimer = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1170
        
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
  1171
        def __init__(self, PluginRoot, Log):
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1172
            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
  1173
            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
  1174
            self.Log = Log
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
  1175
            self.PluginRoot = PluginRoot
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1176
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1177
        def RestartTimer(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1178
            if self.RefreshTimer is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1179
                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
  1180
            self.RefreshTimer = Timer(0.1, wx.CallAfter, args = [self.Refresh])
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1181
            self.RefreshTimer.start()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1182
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1183
        def Exit(self):
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1184
            global frame, app
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1185
            self.Close()
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1186
            app.ExitMainLoop()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1187
            return True
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1188
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1189
        def do_EOF(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1190
            return self.Exit()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1191
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1192
        def Show(self):
445
1b1dc8ad2498 Bug when asking two consecutive times 'Show' fixed
berem
parents: 444
diff changeset
  1193
            global frame
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1194
            if frame is not None:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1195
                self.PluginRoot.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
  1196
                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
  1197
                frame.Raise()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1198
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1199
        def Refresh(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1200
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1201
            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
  1202
                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
  1203
                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
  1204
                frame.RefreshAll()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1205
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1206
        def Close(self):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1207
            global frame
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1208
            
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1209
            self.PluginRoot.ResetAppFrame(self.Log)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1210
            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
  1211
                frame.Hide()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1212
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1213
        def Compile(self):
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
  1214
            self.PluginRoot._build()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1215
        
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
  1216
        def SetProjectProperties(self, projectname, productname, productversion, 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
  1217
            properties = self.PluginRoot.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
  1218
            properties["projectName"] = 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
  1219
            properties["productName"] = 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
  1220
            properties["productVersion"] = 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
  1221
            properties["companyName"] = 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
  1222
            self.PluginRoot.SetProjectProperties(properties=properties)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1223
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1224
        
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1225
        def SetOnlineMode(self, mode, path=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
  1226
            self.PluginRoot.SetOnlineMode(mode, path)
487
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1227
            self.RestartTimer()
1df4a28d3586 Adding support for receiving PLC state from LPCComposer
laurent
parents: 478
diff changeset
  1228
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1229
        def AddBus(self, iec_channel, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1230
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1231
                if child.BaseParams.getName() == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1232
                    return "Error: A bus named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1233
                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
  1234
                    return "Error: A bus with IEC_channel %d already exists\n" % iec_channel
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1235
            bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1236
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1237
                return "Error: Unable to create bus\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1238
            bus.SetIcon(icon)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1239
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1240
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1241
        def RenameBus(self, iec_channel, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1242
            bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1243
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1244
                return "Error: No bus found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1245
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1246
                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
  1247
                    return "Error: A bus named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1248
            bus.BaseParams.setName(name)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1249
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1250
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1251
        def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1252
            bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1253
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1254
                return "Error: No bus found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1255
            for child in self.PluginRoot.IterChilds():
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1256
                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
  1257
                    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
  1258
            if wx.GetApp() is None:
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1259
                self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), 
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1260
                                                              str(new_iec_channel))
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1261
            else:
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
  1262
                self.PluginRoot.UpdateProjectVariableLocation(
539
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1263
                             str(old_iec_channel), 
6ff2c1d34640 Modifying LPCBeremiz to launch silently a frame and show or hide it on demand.
laurent
parents: 530
diff changeset
  1264
                             str(new_iec_channel))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1265
            bus.BaseParams.setIEC_Channel(new_iec_channel)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1266
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1267
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1268
        def RemoveBus(self, iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1269
            bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1270
            if bus is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1271
                return "Error: No bus 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
  1272
            self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1273
            self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1274
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1275
    
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1276
        def AddModule(self, parent, iec_channel, name, icode, icon=None):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1277
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1278
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1279
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1280
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1281
                if child["name"] == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1282
                    return "Error: A module named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1283
                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
  1284
                    return "Error: A module with IEC_channel %d already exists\n" % iec_channel 
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1285
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1286
                                                "type": LOCATION_MODULE, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1287
                                                "IEC_Channel": iec_channel, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1288
                                                "icon": icon, 
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1289
                                                "init": icode, 
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1290
                                                "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1291
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1292
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1293
        def RenameModule(self, iec_location, name):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1294
            module = self.PluginRoot.GetChildByIECLocation(iec_location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1295
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1296
                return "Error: No module found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1297
            parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1298
            if parent is self.PluginRoot:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1299
                return "Error: No module found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1300
            if module["name"] != name:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1301
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1302
                    if child["name"] == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1303
                        return "Error: A module named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1304
                module["name"] = name
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1305
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1306
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1307
        def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1308
            module = self.PluginRoot.GetChildByIECLocation(old_iec_location)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1309
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1310
                return "Error: No module found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1311
            parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1])
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1312
            if parent is self.PluginRoot:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1313
                return "Error: No module found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1314
            if module["IEC_Channel"] != new_iec_channel:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1315
                for child in _GetModuleChildren(parent):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1316
                    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
  1317
                        return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
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
  1318
            self.PluginRoot.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
  1319
            module["IEC_Channel"] = new_iec_channel
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1320
            self.RestartTimer()
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1321
        
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1322
        def ChangeModuleInitCode(self, iec_location, icode):
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1323
            module = self.PluginRoot.GetChildByIECLocation(iec_location)
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1324
            if module is None:
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1325
                return "Error: No module found\n"
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1326
            module["init"] = icode
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1327
        
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1328
        def RemoveModule(self, parent, iec_channel):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1329
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1330
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1331
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1332
            child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1333
            if child is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1334
                return "Error: No module 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
  1335
            self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1336
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1337
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1338
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1339
        def StartGroup(self, parent, name, icon=None):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1340
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1341
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1342
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1343
            for child in module["children"]:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1344
                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
  1345
                    return "Error: A group named %s already exists\n" % name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1346
            module["children"].append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1347
                                      "type": LOCATION_GROUP, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1348
                                      "icon": icon, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1349
                                      "children": []})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1350
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1351
    
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1352
        def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1353
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1354
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1355
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1356
            for child in _GetModuleChildren(module):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1357
                if child["name"] == name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1358
                    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
  1359
                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
  1360
                    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
  1361
            _GetLastModuleGroup(module).append({"name": name, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1362
                                                "location": location, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1363
                                                "type": LOCATION_TYPES[direction], 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1364
                                                "IEC_type": type, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1365
                                                "description": description, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1366
                                                "retrieve": rcode, 
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1367
                                                "publish": pcode})
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1368
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1369
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1370
        def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode, new_description=None):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1371
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1372
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1373
                return "Error: No parent found\n"
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1374
            variable = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1375
            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
  1376
                if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1377
                    variable = child
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1378
                elif child["name"] == new_name:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1379
                    return "Error: A variable named %s already exists\n" % new_name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1380
            if variable is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1381
                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
  1382
            if variable["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
  1383
                self.PluginRoot.UpdateProjectVariableName(variable["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
  1384
                variable["name"] = new_name
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1385
            variable["type"] = LOCATION_TYPES[new_direction]
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1386
            variable["IEC_type"] = new_type
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1387
            variable["retrieve"] = new_rcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1388
            variable["publish"] = new_pcode
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1389
            if new_description is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1390
                variable["description"] = new_description
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1391
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1392
    
472
80eb3bde98e3 Adding support for defining input and output with the same location in LPCBeremiz
laurent
parents: 445
diff changeset
  1393
        def RemoveVariable(self, parent, location, direction):
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1394
            module = self.PluginRoot.GetChildByIECLocation(parent)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1395
            if module is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1396
                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
  1397
            child = _GetModuleVariable(module, location, direction)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1398
            if child is None:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1399
                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
  1400
            size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])]
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
  1401
            address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
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
  1402
            self.PluginRoot.RemoveProjectVariableByAddress(address)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1403
            _RemoveModuleChild(module, child)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1404
            self.RestartTimer()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1405
        
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1406
    def location(loc):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1407
        return tuple(map(int, loc.split(".")))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1408
    
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1409
    def GetCmdFunction(function, arg_types, opt=0):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1410
        arg_number = len(arg_types)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1411
        def CmdFunction(self, line):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1412
            args_toks = line.split('"')
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1413
            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
  1414
                self.Log.write("Error: Invalid command\n")
526
68375ccdf968 Added flush when printing to standard output.
tkragelj
parents: 521
diff changeset
  1415
                sys.stdout.flush()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1416
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1417
            args = []
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1418
            for num, arg in enumerate(args_toks):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1419
                if num % 2 == 0:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1420
                    stripped = arg.strip()
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1421
                    if stripped:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1422
                        args.extend(stripped.split(" "))
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1423
                else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1424
                    args.append(arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1425
            number = None
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1426
            extra = ""
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1427
            if opt == 0 and len(args) != arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1428
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1429
            elif len(args) > arg_number:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1430
                number = arg_number
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1431
                extra = " at most"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1432
            elif len(args) < arg_number - opt:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1433
                number = arg_number - opt
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1434
                extra = " at least"
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1435
            if number is not None:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1436
                if number == 0:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1437
                    self.Log.write("Error: No argument%s expected\n" % extra)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1438
                elif number == 1:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1439
                    self.Log.write("Error: 1 argument%s expected\n" % extra)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1440
                else:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1441
                    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
  1442
                sys.stdout.flush()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1443
                return
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1444
            for num, arg in enumerate(args):
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1445
                try:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1446
                    args[num] = arg_types[num](arg)
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1447
                except:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1448
                    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
  1449
                    sys.stdout.flush()
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1450
                    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
  1451
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
            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
  1453
            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
  1454
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
  1455
            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
  1456
                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
  1457
                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
  1458
                    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
  1459
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1460
            if isinstance(res, (StringType, UnicodeType)):
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1461
                self.Log.write(res)
442
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1462
                return False
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1463
            else:
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1464
                return res
f971de6d274f Adding Beremiz LPCComposer specific file
laurent
parents:
diff changeset
  1465
        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
  1466
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
  1467
    def CmdThreadProc(PluginRoot, Log):
549
5dd92bd6e6e5 Fixed bug on frame close.
Lolitech
parents: 547
diff changeset
  1468
        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
  1469
        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
  1470
                                           "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
  1471
                                           "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
  1472
                                           "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
  1473
                                           "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
  1474
                                           "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
  1475
                                           "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
  1476
                                           "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
  1477
                                           "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
  1478
                                           "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
  1479
                                           "RemoveBus": ([int], 0),
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1480
                                           "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
  1481
                                           "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
  1482
                                           "ChangeModuleIECChannel": ([location, int], 0),
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1483
                                           "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
  1484
                                           "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
  1485
                                           "StartGroup": ([location, str, str], 1),
553
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1486
                                           "AddVariable": ([location, location, str, str, str, str, str, str], 1),
d071efd2a94b Move init code from variable to module
laurent
parents: 552
diff changeset
  1487
                                           "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
  1488
                                           "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
  1489
            
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
  1490
            setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
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
  1491
        lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log)
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
  1492
        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
  1493
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1494
    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
  1495
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
  1496
    PluginRoot = LPCPluginsRoot(None, Log)
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
  1497
    if projectOpen is not None and os.path.isdir(projectOpen):
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
  1498
        result = PluginRoot.LoadProject(projectOpen, buildpath)
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
  1499
        if result:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1500
            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
  1501
    else:
551
d18e86b603bc Adding support for command line communication by socket instead of stdin/stdout
laurent
parents: 550
diff changeset
  1502
        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
  1503
    
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
  1504
    cmd_thread=Thread(target=CmdThreadProc, args=[PluginRoot, Log])
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
  1505
    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
  1506
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
  1507
    # 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
  1508
    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
  1509
    
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
  1510
    frame = LPCBeremiz(None, plugin_root=PluginRoot, debug=True)
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
  1511
    
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
  1512
    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
  1513