author | etisserant |
Thu, 20 Sep 2007 17:32:52 +0200 | |
changeset 48 | 6b30cfee163e |
parent 47 | fd45c291fed0 |
child 49 | 45dc6a944ab6 |
permissions | -rw-r--r-- |
20 | 1 |
import os, sys |
2 |
base_folder = os.path.split(sys.path[0])[0] |
|
3 |
sys.path.append(os.path.join(base_folder, "CanFestival-3", "objdictgen")) |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
32
diff
changeset
|
4 |
CanfestivalIncludePath = os.path.join(base_folder, "CanFestival-3", "include") |
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
32
diff
changeset
|
5 |
CanfestivalLibPath = os.path.join(base_folder, "CanFestival-3", "src") |
20 | 6 |
|
11 | 7 |
from nodelist import NodeList |
8 |
from nodemanager import NodeManager |
|
9 |
import config_utils, gen_cfile |
|
12 | 10 |
from networkedit import networkedit |
11 | 11 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
12 |
class _NetworkEdit(networkedit): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
13 |
" Overload some of CanFestival Network Editor methods " |
12 | 14 |
def OnCloseFrame(self, event): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
15 |
" Do reset _NodeListPlug.View when closed" |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
16 |
self._onclose() |
12 | 17 |
event.Skip() |
18 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
19 |
class _NodeListPlug(NodeList): |
12 | 20 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
21 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
22 |
<xsd:element name="CanFestivalNode"> |
|
23 |
<xsd:complexType> |
|
24 |
<xsd:attribute name="CAN_Device" type="xsd:string" use="required" /> |
|
26 | 25 |
<xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="required" default="true"/> |
12 | 26 |
</xsd:complexType> |
27 |
</xsd:element> |
|
28 |
</xsd:schema> |
|
29 |
""" |
|
30 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
31 |
def __init__(self): |
11 | 32 |
manager = NodeManager() |
23 | 33 |
# TODO change netname when name change |
34 |
NodeList.__init__(self, manager, self.BaseParams.getName()) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
35 |
self.LoadProject(self.PlugPath()) |
11 | 36 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
37 |
_View = None |
18 | 38 |
def _OpenView(self, logger): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
39 |
if not self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
40 |
def _onclose(): |
30 | 41 |
self._View = None |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
42 |
def _onsave(): |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
43 |
self.GetPlugRoot().SaveProject() |
23 | 44 |
self._View = _NetworkEdit(self.GetPlugRoot().AppFrame, self) |
45 |
# TODO redefine BusId when IEC channel change |
|
46 |
self._View.SetBusId(self.GetCurrentLocation()) |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
47 |
self._View._onclose = _onclose |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
48 |
self._View._onsave = _onsave |
23 | 49 |
self._View.Show() |
50 |
||
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
51 |
PluginMethods = [("NetworkEdit",_OpenView)] |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
52 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
53 |
def OnPlugClose(self): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
54 |
if self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
55 |
self._View.Close() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
56 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
57 |
def PlugTestModified(self): |
12 | 58 |
return self.HasChanged() |
59 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
60 |
def OnPlugSave(self): |
32 | 61 |
self.SetRoot(self.PlugPath()) |
11 | 62 |
self.SaveProject() |
12 | 63 |
return True |
64 |
||
24 | 65 |
def PlugGenerate_C(self, buildpath, locations, logger): |
12 | 66 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
67 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
68 |
@param current_location: Tupple containing plugin IEC location : %I0.0.4.5 => (0,0,4,5) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
69 |
@param locations: List of complete variables locations \ |
22 | 70 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
71 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
72 |
"DIR" : direction "Q","I" or "M" |
|
73 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
74 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
75 |
}, ...] |
|
76 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
12 | 77 |
""" |
24 | 78 |
current_location = self.GetCurrentLocation() |
22 | 79 |
# define a unique name for the generated C file |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
80 |
prefix = "_".join(map(lambda x:str(x), current_location)) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
81 |
Gen_OD_path = os.path.join(buildpath, prefix + "_OD.c" ) |
22 | 82 |
# Create a new copy of the model with DCF loaded with PDO mappings for desired location |
26 | 83 |
master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs()) |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
84 |
res = gen_cfile.GenerateFile(Gen_OD_path, master) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
85 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
86 |
raise Exception, res |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
87 |
|
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
32
diff
changeset
|
88 |
return [(Gen_OD_path,"-I"+CanfestivalIncludePath)],"" |
12 | 89 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
90 |
class RootClass: |
12 | 91 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
92 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
93 |
<xsd:element name="CanFestivalInstance"> |
|
94 |
<xsd:complexType> |
|
95 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="required" /> |
|
96 |
</xsd:complexType> |
|
97 |
</xsd:element> |
|
98 |
</xsd:schema> |
|
99 |
""" |
|
11 | 100 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
101 |
PlugChildsTypes = [("CanOpenNode",_NodeListPlug)] |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
102 |
|
24 | 103 |
def PlugGenerate_C(self, buildpath, locations, logger): |
47
fd45c291fed0
PLC and plugins compilation with gcc now starts (and fail).
etisserant
parents:
32
diff
changeset
|
104 |
return [],"-L"+CanfestivalLibPath+" -lcanfestival" |
11 | 105 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
106 |