author | lbessard |
Sun, 09 Dec 2007 19:01:21 +0100 | |
changeset 76 | 2ee45a612c6f |
parent 65 | e55d6faee9d1 |
child 77 | 7de69369373e |
permissions | -rw-r--r-- |
20 | 1 |
import os, sys |
2 |
base_folder = os.path.split(sys.path[0])[0] |
|
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
3 |
CanFestivalPath = os.path.join(base_folder, "CanFestival-3") |
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
4 |
sys.path.append(os.path.join(CanFestivalPath, "objdictgen")) |
20 | 5 |
|
11 | 6 |
from nodelist import NodeList |
7 |
from nodemanager import NodeManager |
|
8 |
import config_utils, gen_cfile |
|
12 | 9 |
from networkedit import networkedit |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
10 |
import canfestival_config |
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" /> |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
25 |
<xsd:attribute name="CAN_Baudrate" type="xsd:string" use="required" /> |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
26 |
<xsd:attribute name="NodeId" type="xsd:string" use="required" /> |
26 | 27 |
<xsd:attribute name="Sync_TPDOs" type="xsd:boolean" use="required" default="true"/> |
12 | 28 |
</xsd:complexType> |
29 |
</xsd:element> |
|
30 |
</xsd:schema> |
|
31 |
""" |
|
32 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
33 |
def __init__(self): |
11 | 34 |
manager = NodeManager() |
23 | 35 |
# TODO change netname when name change |
36 |
NodeList.__init__(self, manager, self.BaseParams.getName()) |
|
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
37 |
self.LoadProject(self.PlugPath()) |
11 | 38 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
39 |
_View = None |
18 | 40 |
def _OpenView(self, logger): |
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
41 |
if not self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
42 |
def _onclose(): |
30 | 43 |
self._View = None |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
44 |
def _onsave(): |
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
45 |
self.GetPlugRoot().SaveProject() |
23 | 46 |
self._View = _NetworkEdit(self.GetPlugRoot().AppFrame, self) |
47 |
# TODO redefine BusId when IEC channel change |
|
48 |
self._View.SetBusId(self.GetCurrentLocation()) |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
49 |
self._View._onclose = _onclose |
25
fa7503684c28
Adding support for using Networkedit et PLCOpenEditor in Beremiz
lbessard
parents:
24
diff
changeset
|
50 |
self._View._onsave = _onsave |
23 | 51 |
self._View.Show() |
52 |
||
65 | 53 |
PluginMethods = [ |
54 |
{"bitmap" : os.path.join("images", "NetworkEdit.png"), |
|
55 |
"name" : "Edit network", |
|
56 |
"tooltip" : "Edit CanOpen Network with NetworkEdit", |
|
57 |
"method" : _OpenView} |
|
58 |
] |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
59 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
60 |
def OnPlugClose(self): |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
61 |
if self._View: |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
62 |
self._View.Close() |
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
63 |
|
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
64 |
def PlugTestModified(self): |
12 | 65 |
return self.HasChanged() |
66 |
||
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
67 |
def OnPlugSave(self): |
32 | 68 |
self.SetRoot(self.PlugPath()) |
11 | 69 |
self.SaveProject() |
12 | 70 |
return True |
71 |
||
24 | 72 |
def PlugGenerate_C(self, buildpath, locations, logger): |
12 | 73 |
""" |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
74 |
Generate C code |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
75 |
@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
|
76 |
@param locations: List of complete variables locations \ |
22 | 77 |
[{"IEC_TYPE" : the IEC type (i.e. "INT", "STRING", ...) |
78 |
"NAME" : name of the variable (generally "__IW0_1_2" style) |
|
79 |
"DIR" : direction "Q","I" or "M" |
|
80 |
"SIZE" : size "X", "B", "W", "D", "L" |
|
81 |
"LOC" : tuple of interger for IEC location (0,1,2,...) |
|
82 |
}, ...] |
|
83 |
@return: [(C_file_name, CFLAGS),...] , LDFLAGS_TO_APPEND |
|
12 | 84 |
""" |
24 | 85 |
current_location = self.GetCurrentLocation() |
22 | 86 |
# define a unique name for the generated C file |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
87 |
prefix = "_".join(map(lambda x:str(x), current_location)) |
49
45dc6a944ab6
On the long wat towards generated code comilation...
etisserant
parents:
47
diff
changeset
|
88 |
Gen_OD_path = os.path.join(buildpath, "OD_%s.c"%prefix ) |
22 | 89 |
# Create a new copy of the model with DCF loaded with PDO mappings for desired location |
57 | 90 |
master = config_utils.GenerateConciseDCF(locations, current_location, self, self.CanFestivalNode.getSync_TPDOs(),"OD_%s"%prefix) |
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
91 |
res = gen_cfile.GenerateFile(Gen_OD_path, master) |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
92 |
if res : |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
93 |
raise Exception, res |
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
94 |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
95 |
return [(Gen_OD_path,canfestival_config.getCFLAGS(CanFestivalPath))],"",False |
12 | 96 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
97 |
class RootClass: |
12 | 98 |
XSD = """<?xml version="1.0" encoding="ISO-8859-1" ?> |
99 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> |
|
100 |
<xsd:element name="CanFestivalInstance"> |
|
101 |
<xsd:complexType> |
|
102 |
<xsd:attribute name="CAN_Driver" type="xsd:string" use="required" /> |
|
103 |
</xsd:complexType> |
|
104 |
</xsd:element> |
|
105 |
</xsd:schema> |
|
106 |
""" |
|
11 | 107 |
|
13
f1f0edbeb313
More precise design for plugins.... to be continued...
etisserant
parents:
12
diff
changeset
|
108 |
PlugChildsTypes = [("CanOpenNode",_NodeListPlug)] |
17
ee8cb104dbe0
First commit of Beremiz new version with plugin support
lbessard
parents:
15
diff
changeset
|
109 |
|
24 | 110 |
def PlugGenerate_C(self, buildpath, locations, logger): |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
111 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
112 |
format_dict = {"locstr" : "_".join(map(str,self.GetCurrentLocation())), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
113 |
"candriver" : self.CanFestivalInstance.getCAN_Driver(), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
114 |
"nodes_includes" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
115 |
"board_decls" : "", |
59
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
116 |
"nodes_declare" : "", |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
117 |
"nodes_init" : "", |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
118 |
"nodes_open" : "", |
57 | 119 |
"nodes_close" : "", |
120 |
"nodes_send_sync" : "", |
|
121 |
"nodes_proceed_sync" : ""} |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
122 |
for child in self.IECSortedChilds(): |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
123 |
childlocstr = "_".join(map(str,child.GetCurrentLocation())) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
124 |
nodename = "OD_%s" % childlocstr |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
125 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
126 |
format_dict["nodes_includes"] += '#include "%s.h"\n'%(nodename) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
127 |
format_dict["board_decls"] += 'BOARD_DECL(%s, "%s", "%s")\n'%( |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
128 |
nodename, |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
129 |
child.CanFestivalNode.getCAN_Device(), |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
130 |
child.CanFestivalNode.getCAN_Baudrate()) |
59
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
131 |
format_dict["nodes_declare"] += 'NODE_DECLARE(%s, %s)\n '%( |
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
132 |
nodename, |
b6ff896ff58b
Enhancements in CanFestival plugin. Now PLC with CanFestival plugin compiles and run, exchanging CanOpen PDOs
etisserant
parents:
57
diff
changeset
|
133 |
child.CanFestivalNode.getNodeId()) |
57 | 134 |
format_dict["nodes_init"] += 'NODE_INIT(%s, %s)\n '%( |
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
135 |
nodename, |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
136 |
child.CanFestivalNode.getNodeId()) |
57 | 137 |
format_dict["nodes_open"] += 'NODE_OPEN(%s)\n '%(nodename) |
138 |
format_dict["nodes_close"] += 'NODE_CLOSE(%s)\n '%(nodename) |
|
139 |
format_dict["nodes_send_sync"] += 'NODE_SEND_SYNC(%s)\n '%(nodename) |
|
140 |
format_dict["nodes_proceed_sync"] += 'NODE_PROCEED_SYNC(%s)\n '%(nodename) |
|
52
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
141 |
filename = os.path.join(os.path.split(__file__)[0],"cf_runtime.c") |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
142 |
cf_main = open(filename).read() % format_dict |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
143 |
cf_main_path = os.path.join(buildpath, "CF_%(locstr)s.c"%format_dict) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
144 |
f = open(cf_main_path,'w') |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
145 |
f.write(cf_main) |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
146 |
f.close() |
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
147 |
|
eaffcd0a2f03
Added CanFestival "main" runtime part, initialize, all nodes, and start CF timer loop
etisserant
parents:
49
diff
changeset
|
148 |
return [(cf_main_path, canfestival_config.getCFLAGS(CanFestivalPath))],canfestival_config.getLDFLAGS(CanFestivalPath), True |
11 | 149 |
|
15
7a473efc4530
More precise design for plugins.... to be continued...
etisserant
parents:
13
diff
changeset
|
150 |