--- a/etherlab/etherlab.py Thu Apr 25 23:01:06 2013 +0200
+++ b/etherlab/etherlab.py Fri Apr 26 13:57:10 2013 +0200
@@ -232,9 +232,19 @@
"Access": access,
"PDOMapping": pdomapping}
-DEFAULT_ALIGNMENT = 8
-
class ModulesLibrary:
+
+ MODULES_EXTRA_PARAMS = [
+ ("pdo_alignment", {
+ "column_label": _("PDO alignment (bits)"),
+ "default": 8}),
+ ("max_pdo_size", {
+ "column_label": _("Max entries by PDO (-1=unbounded)"),
+ "default": -1}),
+ ("add_pdo", {
+ "column_label": _("Creating new PDO (1=possible)"),
+ "default": 0})
+ ]
def __init__(self, path, parent_library=None):
self.Path = path
@@ -246,13 +256,13 @@
self.LoadModules()
else:
self.Library = None
- self.LoadAlignments()
+ self.LoadModulesExtraParams()
def GetPath(self):
return self.Path
- def GetAlignmentFilePath(self):
- return os.path.join(self.Path, "alignments.cfg")
+ def GetModulesExtraParamsFilePath(self):
+ return os.path.join(self.Path, "modules_extra_params.cfg")
def LoadModules(self):
self.Library = {}
@@ -310,14 +320,14 @@
if profile_filter is None or profile_filter in device.GetProfileNumbers():
product_code = device.getType().getProductCode()
revision_number = device.getType().getRevisionNo()
- alignment = self.GetAlignment(vendor_id, product_code, revision_number)
+ module_infos = {"device_type": device_type,
+ "vendor": vendor_id,
+ "product_code": product_code,
+ "revision_number": revision_number}
+ module_infos.update(self.GetModuleExtraParams(vendor_id, product_code, revision_number))
device_infos = {"name": ExtractName(device.getName()),
"type": ETHERCAT_DEVICE,
- "infos": {"device_type": device_type,
- "vendor": vendor_id,
- "product_code": product_code,
- "revision_number": revision_number,
- "alignment": alignment},
+ "infos": module_infos,
"children": []}
group_infos["children"].append(device_infos)
device_type_occurrences = device_dict.setdefault(device_type, [])
@@ -353,7 +363,7 @@
revision_number = ExtractHexDecValue(device_infos.getType().getRevisionNo())
if (product_code == ExtractHexDecValue(module_infos["product_code"]) and
revision_number == ExtractHexDecValue(module_infos["revision_number"])):
- return device_infos, self.GetAlignment(vendor, product_code, revision_number)
+ return device_infos, self.GetModuleExtraParams(vendor, product_code, revision_number)
return None, None
def ImportModuleLibrary(self, filepath):
@@ -363,10 +373,10 @@
return True
return False
- def LoadAlignments(self):
- self.Alignments = {}
-
- csvfile_path = self.GetAlignmentFilePath()
+ def LoadModulesExtraParams(self):
+ self.ModulesExtraParams = {}
+
+ csvfile_path = self.GetModulesExtraParamsFilePath()
if os.path.exists(csvfile_path):
csvfile = open(csvfile_path, "rb")
sample = csvfile.read(1024)
@@ -379,39 +389,48 @@
has_header = False
else:
try:
- self.Alignments[tuple(map(int, row[:3]))] = int(row[3])
+ self.ModulesExtraParams[tuple(map(int, row[:3]))] = dict(
+ zip([param for param, params_infos in self.MODULES_EXTRA_PARAMS],
+ int(row[3])))
except:
pass
csvfile.close()
-
- def SaveAlignments(self):
- csvfile = open(self.GetAlignmentFilePath(), "wb")
+
+ def SaveModulesExtraParams(self):
+ csvfile = open(self.GetModulesExtraParamsFilePath(), "wb")
+ extra_params = [param for param, params_infos in self.MODULES_EXTRA_PARAMS]
writer = csv.writer(csvfile, delimiter=';')
- writer.writerow(['Vendor', 'product_code', 'revision_number', 'alignment'])
- for (vendor, product_code, revision_number), alignment in self.Alignments.iteritems():
- writer.writerow([vendor, product_code, revision_number, alignment])
+ writer.writerow(['Vendor', 'product_code', 'revision_number'] + extra_params)
+ for (vendor, product_code, revision_number), module_extra_params in self.ModulesExtraParams.iteritems():
+ writer.writerow([vendor, product_code, revision_number] +
+ [module_extra_params.get(param, '')
+ for param in extra_params])
csvfile.close()
- def SetAlignment(self, vendor, product_code, revision_number, alignment):
+ def SetModuleExtraParam(self, vendor, product_code, revision_number, param, value):
vendor = ExtractHexDecValue(vendor)
product_code = ExtractHexDecValue(product_code)
revision_number = ExtractHexDecValue(revision_number)
- self.Alignments[tuple([vendor, product_code, revision_number])] = alignment
- self.SaveAlignments()
-
- def GetAlignment(self, vendor, product_code, revision_number):
+ self.ModulesExtraParams[tuple([vendor, product_code, revision_number])][param] = value
+ self.SaveModulesExtraParams()
+
+ def GetModuleExtraParams(self, vendor, product_code, revision_number):
vendor = ExtractHexDecValue(vendor)
product_code = ExtractHexDecValue(product_code)
revision_number = ExtractHexDecValue(revision_number)
- alignment = self.Alignments.get(tuple([vendor, product_code, revision_number]))
- if alignment is not None:
- return alignment
-
if self.ParentLibrary is not None:
- return self.ParentLibrary.GetAlignment(vendor, product_code, revision_number)
- return DEFAULT_ALIGNMENT
+ extra_params = self.ParentLibrary.GetModuleExtraParams(vendor, product_code, revision_number)
+ else:
+ extra_params = {}
+
+ extra_params.update(self.ModulesExtraParams.get(tuple([vendor, product_code, revision_number]), {}))
+
+ for param, param_infos in self.MODULES_EXTRA_PARAMS:
+ extra_params.setdefault(param, param_infos["default"])
+
+ return extra_params
USERDATA_DIR = wx.StandardPaths.Get().GetUserDataDir()
if wx.Platform != '__WXMSW__':