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