author | Andrey Skvortsov <andrej.skvortzov@gmail.com> |
Tue, 02 Oct 2018 17:18:09 +0300 | |
changeset 2417 | 316ee9fff395 |
parent 2407 | 5f2b1bb464a0 |
child 2425 | 68e7da937162 |
permissions | -rw-r--r-- |
2165
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
1 |
#!/usr/bin/env python |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
3 |
|
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
4 |
# This file is part of Beremiz |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
5 |
# |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
6 |
# Copyright (C) 2011-2014: Laurent BESSARD, Edouard TISSERANT |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
7 |
# RTES Lab : CRKim, JBLee, youcu |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
8 |
# Higen Motor : Donggu Kang |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
9 |
# |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
10 |
# See COPYING file for copyrights details. |
02a2b5dee5e3
Merged GPL + LGPL v2 or later EtherCAT extension. Fixed headers and copyright notice.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
2144
diff
changeset
|
11 |
|
2405
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2397
diff
changeset
|
12 |
from __future__ import absolute_import |
2111 | 13 |
import os |
14 |
||
2405
af050469fc5c
clean etherlab: pylint, W1618 # (no-absolute-import) import missing `from __future__ import absolute_import`
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2397
diff
changeset
|
15 |
from etherlab.EthercatSlave import ExtractHexDecValue, DATATYPECONVERSION, ExtractName |
2111 | 16 |
|
17 |
SLAVE_PDOS_CONFIGURATION_DECLARATION = """ |
|
18 |
/* Slave %(slave)d, "%(device_type)s" |
|
19 |
* Vendor ID: 0x%(vendor).8x |
|
20 |
* Product code: 0x%(product_code).8x |
|
21 |
* Revision number: 0x%(revision_number).8x |
|
22 |
*/ |
|
23 |
||
24 |
ec_pdo_entry_info_t slave_%(slave)d_pdo_entries[] = { |
|
25 |
%(pdos_entries_infos)s |
|
26 |
}; |
|
27 |
||
28 |
ec_pdo_info_t slave_%(slave)d_pdos[] = { |
|
29 |
%(pdos_infos)s |
|
30 |
}; |
|
31 |
||
32 |
ec_sync_info_t slave_%(slave)d_syncs[] = { |
|
33 |
%(pdos_sync_infos)s |
|
34 |
{0xff} |
|
35 |
}; |
|
36 |
""" |
|
37 |
||
38 |
SLAVE_CONFIGURATION_TEMPLATE = """ |
|
39 |
if (!(slave%(slave)d = ecrt_master_slave_config(master, %(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x))) { |
|
2116
2b1980a038b1
Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents:
2111
diff
changeset
|
40 |
SLOGF(LOG_CRITICAL, "EtherCAT failed to get slave %(device_type)s configuration at alias %(alias)d and position %(position)d."); |
2121
11102245e1d4
Fixed (again) some non-clean exit in case of SDO failure at init
Edouard Tisserant
parents:
2117
diff
changeset
|
41 |
goto ecat_failed; |
2111 | 42 |
} |
43 |
||
44 |
if (ecrt_slave_config_pdos(slave%(slave)d, EC_END, slave_%(slave)d_syncs)) { |
|
2116
2b1980a038b1
Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents:
2111
diff
changeset
|
45 |
SLOGF(LOG_CRITICAL, "EtherCAT failed to configure PDOs for slave %(device_type)s at alias %(alias)d and position %(position)d."); |
2117
accc4cbca8d3
Now failure in template based part of C code also release the master for later use...
Edouard Tisserant
parents:
2116
diff
changeset
|
46 |
goto ecat_failed; |
2111 | 47 |
} |
48 |
""" |
|
49 |
||
50 |
SLAVE_INITIALIZATION_TEMPLATE = """ |
|
51 |
{ |
|
52 |
uint8_t value[%(data_size)d]; |
|
53 |
EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s); |
|
54 |
if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) { |
|
2116
2b1980a038b1
Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents:
2111
diff
changeset
|
55 |
SLOGF(LOG_CRITICAL, "EtherCAT Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%d", abort_code); |
2117
accc4cbca8d3
Now failure in template based part of C code also release the master for later use...
Edouard Tisserant
parents:
2116
diff
changeset
|
56 |
goto ecat_failed; |
2111 | 57 |
} |
58 |
} |
|
59 |
""" |
|
60 |
||
61 |
SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """ |
|
62 |
{ |
|
63 |
uint8_t value[%(data_size)d]; |
|
64 |
if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) { |
|
2116
2b1980a038b1
Better logging, saffer failure at init (allows restart)
Edouard Tisserant
parents:
2111
diff
changeset
|
65 |
SLOGF(LOG_CRITICAL, "EtherCAT failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%ud", abort_code); |
2117
accc4cbca8d3
Now failure in template based part of C code also release the master for later use...
Edouard Tisserant
parents:
2116
diff
changeset
|
66 |
goto ecat_failed; |
2111 | 67 |
} |
68 |
%(real_var)s = EC_READ_%(data_type)s((uint8_t *)value); |
|
69 |
} |
|
70 |
""" |
|
71 |
||
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
72 |
|
2111 | 73 |
def ConfigureVariable(entry_infos, str_completion): |
74 |
entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None) |
|
75 |
if entry_infos["data_type"] is None: |
|
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
76 |
msg = _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"] |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
77 |
raise ValueError(msg) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
78 |
|
2111 | 79 |
if not entry_infos.get("no_decl", False): |
2377
88a9d64560d3
clean etherlab: pep8, W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2374
diff
changeset
|
80 |
if "real_var" in entry_infos: |
2111 | 81 |
str_completion["located_variables_declaration"].append( |
82 |
"IEC_%(var_type)s %(real_var)s;" % entry_infos) |
|
83 |
else: |
|
84 |
entry_infos["real_var"] = "beremiz" + entry_infos["var_name"] |
|
85 |
str_completion["located_variables_declaration"].extend( |
|
86 |
["IEC_%(var_type)s %(real_var)s;" % entry_infos, |
|
87 |
"IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos]) |
|
88 |
for declaration in entry_infos.get("extra_declarations", []): |
|
89 |
entry_infos["extra_decl"] = declaration |
|
90 |
str_completion["located_variables_declaration"].append( |
|
2407
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
91 |
"IEC_%(var_type)s *%(extra_decl)s = &%(real_var)s;" % entry_infos) |
2377
88a9d64560d3
clean etherlab: pep8, W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2374
diff
changeset
|
92 |
elif "real_var" not in entry_infos: |
2111 | 93 |
entry_infos["real_var"] = "beremiz" + entry_infos["var_name"] |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
94 |
|
2111 | 95 |
str_completion["used_pdo_entry_offset_variables_declaration"].append( |
96 |
"unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
97 |
|
2111 | 98 |
if entry_infos["data_type"] == "BIT": |
99 |
str_completion["used_pdo_entry_offset_variables_declaration"].append( |
|
100 |
"unsigned int slave%(slave)d_%(index).4x_%(subindex).2x_bit;" % entry_infos) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
101 |
|
2111 | 102 |
str_completion["used_pdo_entry_configuration"].append( |
2407
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
103 |
(" {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, " + |
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
104 |
"0x%(index).4x, %(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x, " + |
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
105 |
"&slave%(slave)d_%(index).4x_%(subindex).2x_bit},") % entry_infos) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
106 |
|
2111 | 107 |
if entry_infos["dir"] == "I": |
108 |
str_completion["retrieve_variables"].append( |
|
2407
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
109 |
(" %(real_var)s = EC_READ_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
110 |
"slave%(slave)d_%(index).4x_%(subindex).2x_bit);") % entry_infos) |
2111 | 111 |
elif entry_infos["dir"] == "Q": |
112 |
str_completion["publish_variables"].append( |
|
2407
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
113 |
(" EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
114 |
"slave%(slave)d_%(index).4x_%(subindex).2x_bit, %(real_var)s);") % entry_infos) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
115 |
|
2111 | 116 |
else: |
117 |
str_completion["used_pdo_entry_configuration"].append( |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
118 |
(" {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " + |
2111 | 119 |
"%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
120 |
|
2111 | 121 |
if entry_infos["dir"] == "I": |
122 |
str_completion["retrieve_variables"].append( |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
123 |
(" %(real_var)s = EC_READ_%(data_type)s(domain1_pd + " + |
2111 | 124 |
"slave%(slave)d_%(index).4x_%(subindex).2x);") % entry_infos) |
125 |
elif entry_infos["dir"] == "Q": |
|
126 |
str_completion["publish_variables"].append( |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
127 |
(" EC_WRITE_%(data_type)s(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
2111 | 128 |
"%(real_var)s);") % entry_infos) |
129 |
||
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
130 |
|
2111 | 131 |
def ExclusionSortFunction(x, y): |
132 |
if x["matching"] == y["matching"]: |
|
133 |
if x["assigned"] and not y["assigned"]: |
|
134 |
return -1 |
|
135 |
elif not x["assigned"] and y["assigned"]: |
|
136 |
return 1 |
|
137 |
return cmp(x["count"], y["count"]) |
|
138 |
return -cmp(x["matching"], y["matching"]) |
|
139 |
||
2360
2a3d022a7dac
cleanup etherlab: pep8, E302 expected 2 blank lines, found 1
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2355
diff
changeset
|
140 |
|
2397
25f16349644b
clean etherlab: pylint, C1001 # (old-style-class) Old-style class defined.
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2381
diff
changeset
|
141 |
class _EthercatCFileGenerator(object): |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
142 |
|
2111 | 143 |
def __init__(self, controler): |
144 |
self.Controler = controler |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
145 |
|
2111 | 146 |
self.Slaves = [] |
147 |
self.UsedVariables = {} |
|
148 |
||
149 |
def __del__(self): |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
150 |
self.Controler = None |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
151 |
|
2111 | 152 |
def DeclareSlave(self, slave_index, slave): |
153 |
self.Slaves.append((slave_index, slave.getInfo().getAutoIncAddr(), slave)) |
|
154 |
||
155 |
def DeclareVariable(self, slave_index, index, subindex, iec_type, dir, name, no_decl=False): |
|
156 |
slave_variables = self.UsedVariables.setdefault(slave_index, {}) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
157 |
|
2111 | 158 |
entry_infos = slave_variables.get((index, subindex), None) |
159 |
if entry_infos is None: |
|
160 |
slave_variables[(index, subindex)] = { |
|
161 |
"infos": (iec_type, dir, name, no_decl, []), |
|
162 |
"mapped": False} |
|
163 |
return name |
|
164 |
elif entry_infos["infos"][:2] == (iec_type, dir): |
|
165 |
if name != entry_infos["infos"][2]: |
|
166 |
if dir == "I": |
|
167 |
entry_infos["infos"][4].append(name) |
|
168 |
return entry_infos["infos"][2] |
|
169 |
else: |
|
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
170 |
msg = _("Output variables can't be defined with different locations (%s and %s)") \ |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
171 |
% (entry_infos["infos"][2], name) |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
172 |
raise ValueError(msg) |
2111 | 173 |
else: |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
174 |
raise ValueError(_("Definition conflict for location \"%s\"") % name) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
175 |
|
2111 | 176 |
def GenerateCFile(self, filepath, location_str, master_number): |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
177 |
|
2111 | 178 |
# Extract etherlab master code template |
179 |
plc_etherlab_filepath = os.path.join(os.path.split(__file__)[0], "plc_etherlab.c") |
|
180 |
plc_etherlab_file = open(plc_etherlab_filepath, 'r') |
|
181 |
plc_etherlab_code = plc_etherlab_file.read() |
|
182 |
plc_etherlab_file.close() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
183 |
|
2111 | 184 |
# Initialize strings for formatting master code template |
185 |
str_completion = { |
|
186 |
"location": location_str, |
|
187 |
"master_number": master_number, |
|
188 |
"located_variables_declaration": [], |
|
189 |
"used_pdo_entry_offset_variables_declaration": [], |
|
190 |
"used_pdo_entry_configuration": [], |
|
191 |
"pdos_configuration_declaration": "", |
|
192 |
"slaves_declaration": "", |
|
193 |
"slaves_configuration": "", |
|
194 |
"slaves_output_pdos_default_values_extraction": "", |
|
195 |
"slaves_initialization": "", |
|
196 |
"retrieve_variables": [], |
|
197 |
"publish_variables": [], |
|
198 |
} |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
199 |
|
2111 | 200 |
# Initialize variable storing variable mapping state |
201 |
for slave_entries in self.UsedVariables.itervalues(): |
|
202 |
for entry_infos in slave_entries.itervalues(): |
|
203 |
entry_infos["mapped"] = False |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
204 |
|
2111 | 205 |
# Sort slaves by position (IEC_Channel) |
206 |
self.Slaves.sort() |
|
207 |
# Initialize dictionary storing alias auto-increment position values |
|
208 |
alias = {} |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
209 |
|
2111 | 210 |
# Generating code for each slave |
211 |
for (slave_idx, slave_alias, slave) in self.Slaves: |
|
212 |
type_infos = slave.getType() |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
213 |
|
2111 | 214 |
# Defining slave alias and auto-increment position |
215 |
if alias.get(slave_alias) is not None: |
|
216 |
alias[slave_alias] += 1 |
|
217 |
else: |
|
218 |
alias[slave_alias] = 0 |
|
219 |
slave_pos = (slave_alias, alias[slave_alias]) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
220 |
|
2111 | 221 |
# Extract slave device informations |
2137
b65abacdbdf9
Added support for multiple module extra params in ModulesLibrary
Laurent Bessard
parents:
2121
diff
changeset
|
222 |
device, module_extra_params = self.Controler.GetModuleInfos(type_infos) |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
223 |
if device is None: |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
224 |
msg = _("No informations found for device %s!") \ |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
225 |
% (type_infos["device_type"]) |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
226 |
raise ValueError(msg) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
227 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
228 |
# Extract slaves variables to be mapped |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
229 |
slave_variables = self.UsedVariables.get(slave_idx, {}) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
230 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
231 |
# Extract slave device object dictionary entries |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
232 |
device_entries = device.GetEntriesList() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
233 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
234 |
# Adding code for declaring slave in master code template strings |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
235 |
for element in ["vendor", "product_code", "revision_number"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
236 |
type_infos[element] = ExtractHexDecValue(type_infos[element]) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
237 |
type_infos.update(dict(zip(["slave", "alias", "position"], (slave_idx,) + slave_pos))) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
238 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
239 |
# Extract slave device CoE informations |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
240 |
device_coe = device.getCoE() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
241 |
if device_coe is not None: |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
242 |
|
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
243 |
# If device support CanOpen over Ethernet, adding code for calling |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
244 |
# init commands when initializing slave in master code template strings |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
245 |
initCmds = [] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
246 |
for initCmd in device_coe.getInitCmd(): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
247 |
initCmds.append({ |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
248 |
"Index": ExtractHexDecValue(initCmd.getIndex()), |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
249 |
"Subindex": ExtractHexDecValue(initCmd.getSubIndex()), |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
250 |
"Value": initCmd.getData().getcontent()}) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
251 |
initCmds.extend(slave.getStartupCommands()) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
252 |
for initCmd in initCmds: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
253 |
index = initCmd["Index"] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
254 |
subindex = initCmd["Subindex"] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
255 |
entry = device_entries.get((index, subindex), None) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
256 |
if entry is not None: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
257 |
data_size = entry["BitSize"] / 8 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
258 |
data_str = ("0x%%.%dx" % (data_size * 2)) % initCmd["Value"] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
259 |
init_cmd_infos = { |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
260 |
"index": index, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
261 |
"subindex": subindex, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
262 |
"data": data_str, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
263 |
"data_type": DATATYPECONVERSION.get(entry["Type"]), |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
264 |
"data_size": data_size |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
265 |
} |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
266 |
init_cmd_infos.update(type_infos) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
267 |
str_completion["slaves_initialization"] += SLAVE_INITIALIZATION_TEMPLATE % init_cmd_infos |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
268 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
269 |
# Extract slave device PDO configuration capabilities |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
270 |
PdoAssign = device_coe.getPdoAssign() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
271 |
PdoConfig = device_coe.getPdoConfig() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
272 |
else: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
273 |
PdoAssign = PdoConfig = False |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
274 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
275 |
# Test if slave has a configuration or need one |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
276 |
if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0 and PdoConfig and PdoAssign: |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
277 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
278 |
str_completion["slaves_declaration"] += "static ec_slave_config_t *slave%(slave)d = NULL;\n" % type_infos |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
279 |
str_completion["slaves_configuration"] += SLAVE_CONFIGURATION_TEMPLATE % type_infos |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
280 |
|
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
281 |
# Initializing |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
282 |
pdos_infos = { |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
283 |
"pdos_entries_infos": [], |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
284 |
"pdos_infos": [], |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
285 |
"pdos_sync_infos": [], |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
286 |
} |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
287 |
pdos_infos.update(type_infos) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
288 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
289 |
sync_managers = [] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
290 |
for sync_manager_idx, sync_manager in enumerate(device.getSm()): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
291 |
sync_manager_infos = { |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
292 |
"index": sync_manager_idx, |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
293 |
"name": sync_manager.getcontent(), |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
294 |
"slave": slave_idx, |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
295 |
"pdos": [], |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
296 |
"pdos_number": 0, |
2111 | 297 |
} |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
298 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
299 |
sync_manager_control_byte = ExtractHexDecValue(sync_manager.getControlByte()) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
300 |
sync_manager_direction = sync_manager_control_byte & 0x0c |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
301 |
sync_manager_watchdog = sync_manager_control_byte & 0x40 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
302 |
if sync_manager_direction: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
303 |
sync_manager_infos["sync_manager_type"] = "EC_DIR_OUTPUT" |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
304 |
else: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
305 |
sync_manager_infos["sync_manager_type"] = "EC_DIR_INPUT" |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
306 |
if sync_manager_watchdog: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
307 |
sync_manager_infos["watchdog"] = "EC_WD_ENABLE" |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
308 |
else: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
309 |
sync_manager_infos["watchdog"] = "EC_WD_DISABLE" |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
310 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
311 |
sync_managers.append(sync_manager_infos) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
312 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
313 |
pdos_index = [] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
314 |
exclusive_pdos = {} |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
315 |
selected_pdos = [] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
316 |
for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] + |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
317 |
[(pdo, "Outputs") for pdo in device.getRxPdo()]): |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
318 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
319 |
pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
320 |
pdos_index.append(pdo_index) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
321 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
322 |
excluded_list = pdo.getExclude() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
323 |
if len(excluded_list) > 0: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
324 |
exclusion_list = [pdo_index] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
325 |
for excluded in excluded_list: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
326 |
exclusion_list.append(ExtractHexDecValue(excluded.getcontent())) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
327 |
exclusion_list.sort() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
328 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
329 |
exclusion_scope = exclusive_pdos.setdefault(tuple(exclusion_list), []) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
330 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
331 |
entries = pdo.getEntry() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
332 |
pdo_mapping_match = { |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
333 |
"index": pdo_index, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
334 |
"matching": 0, |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
335 |
"count": len(entries), |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
336 |
"assigned": pdo.getSm() is not None |
2111 | 337 |
} |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
338 |
exclusion_scope.append(pdo_mapping_match) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
339 |
|
2111 | 340 |
for entry in entries: |
341 |
index = ExtractHexDecValue(entry.getIndex().getcontent()) |
|
342 |
subindex = ExtractHexDecValue(entry.getSubIndex()) |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
343 |
if slave_variables.get((index, subindex), None) is not None: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
344 |
pdo_mapping_match["matching"] += 1 |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
345 |
|
2374
aed3ca79a10a
clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
346 |
if pdo.getFixed() is not True: |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
347 |
pdo_mapping_match["matching"] += \ |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
348 |
module_extra_params["max_pdo_size"] - \ |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
349 |
pdo_mapping_match["count"] |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
350 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
351 |
elif pdo.getMandatory(): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
352 |
selected_pdos.append(pdo_index) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
353 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
354 |
excluded_pdos = [] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
355 |
for exclusion_scope in exclusive_pdos.itervalues(): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
356 |
exclusion_scope.sort(ExclusionSortFunction) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
357 |
start_excluding_index = 0 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
358 |
if exclusion_scope[0]["matching"] > 0: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
359 |
selected_pdos.append(exclusion_scope[0]["index"]) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
360 |
start_excluding_index = 1 |
2381
1c40e3976cc2
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2379
diff
changeset
|
361 |
excluded_pdos.extend([ |
1c40e3976cc2
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2379
diff
changeset
|
362 |
pdo["index"] |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
363 |
for pdo in exclusion_scope[start_excluding_index:] |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
364 |
if PdoAssign or not pdo["assigned"]]) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
365 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
366 |
for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] + |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
367 |
[(pdo, "Outputs") for pdo in device.getRxPdo()]): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
368 |
entries = pdo.getEntry() |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
369 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
370 |
pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
371 |
if pdo_index in excluded_pdos: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
372 |
continue |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
373 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
374 |
pdo_needed = pdo_index in selected_pdos |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
375 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
376 |
entries_infos = [] |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
377 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
378 |
for entry in entries: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
379 |
index = ExtractHexDecValue(entry.getIndex().getcontent()) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
380 |
subindex = ExtractHexDecValue(entry.getSubIndex()) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
381 |
entry_infos = { |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
382 |
"index": index, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
383 |
"subindex": subindex, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
384 |
"name": ExtractName(entry.getName()), |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
385 |
"bitlen": entry.getBitLen(), |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
386 |
} |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
387 |
entry_infos.update(type_infos) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
388 |
entries_infos.append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
389 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
390 |
entry_declaration = slave_variables.get((index, subindex), None) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
391 |
if entry_declaration is not None and not entry_declaration["mapped"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
392 |
pdo_needed = True |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
393 |
|
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
394 |
entry_infos.update(dict(zip(["var_type", "dir", "var_name", "no_decl", "extra_declarations"], |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
395 |
entry_declaration["infos"]))) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
396 |
entry_declaration["mapped"] = True |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
397 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
398 |
entry_type = entry.getDataType().getcontent() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
399 |
if entry_infos["var_type"] != entry_type: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
400 |
message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"] |
2379
015b724c30a5
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2378
diff
changeset
|
401 |
if self.Controler.GetSizeOfType(entry_infos["var_type"]) != \ |
015b724c30a5
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2378
diff
changeset
|
402 |
self.Controler.GetSizeOfType(entry_type): |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
403 |
raise ValueError(message) |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
404 |
else: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
405 |
self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
406 |
|
2379
015b724c30a5
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2378
diff
changeset
|
407 |
if (entry_infos["dir"] == "I" and pdo_type != "Inputs") or \ |
015b724c30a5
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2378
diff
changeset
|
408 |
(entry_infos["dir"] == "Q" and pdo_type != "Outputs"): |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
409 |
raise ValueError(_("Wrong direction for location \"%s\"!") % entry_infos["var_name"]) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
410 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
411 |
ConfigureVariable(entry_infos, str_completion) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
412 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
413 |
elif pdo_type == "Outputs" and entry.getDataType() is not None and device_coe is not None: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
414 |
data_type = entry.getDataType().getcontent() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
415 |
entry_infos["dir"] = "Q" |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
416 |
entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
417 |
entry_infos["data_type"] = DATATYPECONVERSION.get(data_type) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
418 |
entry_infos["var_type"] = data_type |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
419 |
entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
420 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
421 |
ConfigureVariable(entry_infos, str_completion) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
422 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
423 |
str_completion["slaves_output_pdos_default_values_extraction"] += \ |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
424 |
SLAVE_OUTPUT_PDO_DEFAULT_VALUE % entry_infos |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
425 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
426 |
if pdo_needed: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
427 |
for excluded in pdo.getExclude(): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
428 |
excluded_index = ExtractHexDecValue(excluded.getcontent()) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
429 |
if excluded_index not in excluded_pdos: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
430 |
excluded_pdos.append(excluded_index) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
431 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
432 |
sm = pdo.getSm() |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
433 |
if sm is None: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
434 |
for sm_idx, sync_manager in enumerate(sync_managers): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
435 |
if sync_manager["name"] == pdo_type: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
436 |
sm = sm_idx |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
437 |
if sm is None: |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
438 |
raise ValueError(_("No sync manager available for %s pdo!") % pdo_type) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
439 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
440 |
sync_managers[sm]["pdos_number"] += 1 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
441 |
sync_managers[sm]["pdos"].append( |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
442 |
{"slave": slave_idx, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
443 |
"index": pdo_index, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
444 |
"name": ExtractName(pdo.getName()), |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
445 |
"type": pdo_type, |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
446 |
"entries": entries_infos, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
447 |
"entries_number": len(entries_infos), |
2374
aed3ca79a10a
clean etherlab: pep8, E712 comparison to True should be 'if cond is True:' or 'if cond:'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2360
diff
changeset
|
448 |
"fixed": pdo.getFixed() is True}) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
449 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
450 |
if PdoConfig and PdoAssign: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
451 |
dynamic_pdos = {} |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
452 |
dynamic_pdos_number = 0 |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
453 |
for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
454 |
("Outputs", 0x1a00, 0x1C00)]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
455 |
for sync_manager in sync_managers: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
456 |
if sync_manager["name"] == category: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
457 |
category_infos = dynamic_pdos.setdefault(category, {}) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
458 |
category_infos["sync_manager"] = sync_manager |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
459 |
category_infos["pdos"] = [pdo for pdo in category_infos["sync_manager"]["pdos"] |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
460 |
if not pdo["fixed"] and pdo["type"] == category] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
461 |
category_infos["current_index"] = min_index |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
462 |
category_infos["max_index"] = max_index |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
463 |
break |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
464 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
465 |
for (index, subindex), entry_declaration in slave_variables.iteritems(): |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
466 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
467 |
if not entry_declaration["mapped"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
468 |
entry = device_entries.get((index, subindex), None) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
469 |
if entry is None: |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
470 |
msg = _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") \ |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
471 |
% (index, subindex, type_infos["device_type"]) |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
472 |
raise ValueError(msg) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
473 |
|
2111 | 474 |
entry_infos = { |
475 |
"index": index, |
|
476 |
"subindex": subindex, |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
477 |
"name": entry["Name"], |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
478 |
"bitlen": entry["BitSize"], |
2111 | 479 |
} |
480 |
entry_infos.update(type_infos) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
481 |
|
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
482 |
entry_infos.update(dict(zip(["var_type", "dir", "var_name", "no_decl", "extra_declarations"], |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
483 |
entry_declaration["infos"]))) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
484 |
entry_declaration["mapped"] = True |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
485 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
486 |
if entry_infos["var_type"] != entry["Type"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
487 |
message = _("Wrong type for location \"%s\"!") % entry_infos["var_name"] |
2379
015b724c30a5
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2378
diff
changeset
|
488 |
if self.Controler.GetSizeOfType(entry_infos["var_type"]) != \ |
015b724c30a5
clean etherlab: pep8, E129 visually indented line with same indent as next logical line
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2378
diff
changeset
|
489 |
self.Controler.GetSizeOfType(entry["Type"]): |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
490 |
raise ValueError(message) |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
491 |
else: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
492 |
self.Controler.GetCTRoot().logger.write_warning(message + "\n") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
493 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
494 |
if entry_infos["dir"] == "I" and entry["PDOMapping"] in ["T", "RT"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
495 |
pdo_type = "Inputs" |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
496 |
elif entry_infos["dir"] == "Q" and entry["PDOMapping"] in ["R", "RT"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
497 |
pdo_type = "Outputs" |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
498 |
else: |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
499 |
msg = _("Wrong direction for location \"%s\"!") \ |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
500 |
% entry_infos["var_name"] |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
501 |
raise ValueError(msg) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
502 |
|
2377
88a9d64560d3
clean etherlab: pep8, W601 .has_key() is deprecated, use 'in'
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2374
diff
changeset
|
503 |
if pdo_type not in dynamic_pdos: |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
504 |
msg = _("No Sync manager defined for %s!") % pdo_type |
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
505 |
raise ValueError(msg) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
506 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
507 |
ConfigureVariable(entry_infos, str_completion) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
508 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
509 |
if len(dynamic_pdos[pdo_type]["pdos"]) > 0: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
510 |
pdo = dynamic_pdos[pdo_type]["pdos"][0] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
511 |
elif module_extra_params["add_pdo"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
512 |
while dynamic_pdos[pdo_type]["current_index"] in pdos_index: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
513 |
dynamic_pdos[pdo_type]["current_index"] += 1 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
514 |
if dynamic_pdos[pdo_type]["current_index"] >= dynamic_pdos[pdo_type]["max_index"]: |
2378
7aa47c09f8f5
clean etherlab: pep8, W602 deprecated form of raising exception
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2377
diff
changeset
|
515 |
raise ValueError(_("No more free PDO index available for %s!") % pdo_type) |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
516 |
pdos_index.append(dynamic_pdos[pdo_type]["current_index"]) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
517 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
518 |
dynamic_pdos_number += 1 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
519 |
pdo = {"slave": slave_idx, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
520 |
"index": dynamic_pdos[pdo_type]["current_index"], |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
521 |
"name": "Dynamic PDO %d" % dynamic_pdos_number, |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
522 |
"type": pdo_type, |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
523 |
"entries": [], |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
524 |
"entries_number": 0, |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
525 |
"fixed": False} |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
526 |
dynamic_pdos[pdo_type]["sync_manager"]["pdos_number"] += 1 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
527 |
dynamic_pdos[pdo_type]["sync_manager"]["pdos"].append(pdo) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
528 |
dynamic_pdos[pdo_type]["pdos"].append(pdo) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
529 |
else: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
530 |
break |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
531 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
532 |
pdo["entries"].append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
533 |
if entry_infos["bitlen"] < module_extra_params["pdo_alignment"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
534 |
pdo["entries"].append(" {0x0000, 0x00, %d}, /* None */" % ( |
2407
5f2b1bb464a0
clean etherlab: pylint, C0330 # (bad-continuation) Wrong hanging indentation before block
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2405
diff
changeset
|
535 |
module_extra_params["pdo_alignment"] - entry_infos["bitlen"])) |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
536 |
pdo["entries_number"] += 1 |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
537 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
538 |
if pdo["entries_number"] == module_extra_params["max_pdo_size"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
539 |
dynamic_pdos[pdo_type]["pdos"].pop(0) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
540 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
541 |
pdo_offset = 0 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
542 |
entry_offset = 0 |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
543 |
for sync_manager_infos in sync_managers: |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
544 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
545 |
for pdo_infos in sync_manager_infos["pdos"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
546 |
pdo_infos["offset"] = entry_offset |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
547 |
pdo_entries = pdo_infos["entries"] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
548 |
pdos_infos["pdos_infos"].append( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
549 |
(" {0x%(index).4x, %(entries_number)d, " + |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
550 |
"slave_%(slave)d_pdo_entries + %(offset)d}, /* %(name)s */") % pdo_infos) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
551 |
entry_offset += len(pdo_entries) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
552 |
pdos_infos["pdos_entries_infos"].extend(pdo_entries) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
553 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
554 |
sync_manager_infos["offset"] = pdo_offset |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
555 |
pdo_offset_shift = sync_manager_infos["pdos_number"] |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
556 |
pdos_infos["pdos_sync_infos"].append( |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
557 |
(" {%(index)d, %(sync_manager_type)s, %(pdos_number)d, " + |
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
558 |
("slave_%(slave)d_pdos + %(offset)d" if pdo_offset_shift else "NULL") + |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
559 |
", %(watchdog)s},") % sync_manager_infos) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
560 |
pdo_offset += pdo_offset_shift |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
561 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
562 |
for element in ["pdos_entries_infos", "pdos_infos", "pdos_sync_infos"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
563 |
pdos_infos[element] = "\n".join(pdos_infos[element]) |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
564 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
565 |
str_completion["pdos_configuration_declaration"] += SLAVE_PDOS_CONFIGURATION_DECLARATION % pdos_infos |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
566 |
|
2144
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
567 |
for (index, subindex), entry_declaration in slave_variables.iteritems(): |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
568 |
if not entry_declaration["mapped"]: |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
569 |
message = _("Entry index 0x%4.4x, subindex 0x%2.2x not mapped for device %s") % \ |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
570 |
(index, subindex, type_infos["device_type"]) |
bbd78ac226d0
Added error message when a device informations can't be found in ESI files
Laurent Bessard
parents:
2140
diff
changeset
|
571 |
self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n") |
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
572 |
|
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
573 |
for element in ["used_pdo_entry_offset_variables_declaration", |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
574 |
"used_pdo_entry_configuration", |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
575 |
"located_variables_declaration", |
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
576 |
"retrieve_variables", |
2111 | 577 |
"publish_variables"]: |
578 |
str_completion[element] = "\n".join(str_completion[element]) |
|
2355
fec77f2b9e07
cleanup etherlab: pep8, W291 trailing whitespace
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents:
2165
diff
changeset
|
579 |
|
2111 | 580 |
etherlabfile = open(filepath, 'w') |
581 |
etherlabfile.write(plc_etherlab_code % str_completion) |
|
582 |
etherlabfile.close() |