416 (" {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " + |
416 (" {%(alias)d, %(position)d, 0x%(vendor).8x, 0x%(product_code).8x, 0x%(index).4x, " + |
417 "%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos) |
417 "%(subindex)d, &slave%(slave)d_%(index).4x_%(subindex).2x},") % entry_infos) |
418 |
418 |
419 if entry_infos["dir"] == "I": |
419 if entry_infos["dir"] == "I": |
420 str_completion["retrieve_variables"].append( |
420 str_completion["retrieve_variables"].append( |
421 (" beremiz%(var_name)s = EC_READ_BIT(domain1_pd + " + |
421 (" beremiz%(var_name)s = EC_READ_%(data_type)s(domain1_pd + " + |
422 "slave%(slave)d_%(index).4x_%(subindex).2x);") % entry_infos) |
422 "slave%(slave)d_%(index).4x_%(subindex).2x);") % entry_infos) |
423 elif entry_infos["dir"] == "Q": |
423 elif entry_infos["dir"] == "Q": |
424 str_completion["publish_variables"].append( |
424 str_completion["publish_variables"].append( |
425 (" EC_WRITE_BIT(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
425 (" EC_WRITE_%(data_type)s(domain1_pd + slave%(slave)d_%(index).4x_%(subindex).2x, " + |
426 "beremiz%(var_name)s);") % entry_infos) |
426 "beremiz%(var_name)s);") % entry_infos) |
427 |
427 |
428 |
428 |
429 class _EthercatCFileGenerator: |
429 class _EthercatCFileGenerator: |
430 |
430 |
527 sync_manager_infos["watchdog"] = "EC_WD_DISABLE" |
527 sync_manager_infos["watchdog"] = "EC_WD_DISABLE" |
528 |
528 |
529 sync_managers.append(sync_manager_infos) |
529 sync_managers.append(sync_manager_infos) |
530 |
530 |
531 pdos_index = [] |
531 pdos_index = [] |
532 for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] + |
532 for only_mandatory in [True, False]: |
533 [(pdo, "Outputs") for pdo in device.getRxPdo()]): |
533 for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] + |
534 entries = pdo.getEntry() |
534 [(pdo, "Outputs") for pdo in device.getRxPdo()]): |
535 |
535 entries = pdo.getEntry() |
536 pdo_needed = pdo.getMandatory() |
536 |
537 pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
537 pdo_needed = pdo.getMandatory() |
538 pdos_index.append(pdo_index) |
538 if only_mandatory != pdo_needed: |
539 entries_infos = [] |
539 continue |
540 |
540 |
541 for entry in entries: |
541 pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent()) |
542 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
542 pdos_index.append(pdo_index) |
543 subindex = ExtractHexDecValue(entry.getSubIndex()) |
543 entries_infos = [] |
544 entry_infos = { |
544 |
545 "index": index, |
545 for entry in entries: |
546 "subindex": subindex, |
546 index = ExtractHexDecValue(entry.getIndex().getcontent()) |
547 "name": ExtractName(entry.getName()), |
547 subindex = ExtractHexDecValue(entry.getSubIndex()) |
548 "bitlen": entry.getBitLen(), |
548 entry_infos = { |
549 } |
549 "index": index, |
550 entry_infos.update(type_infos) |
550 "subindex": subindex, |
551 entries_infos.append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) |
551 "name": ExtractName(entry.getName()), |
552 |
552 "bitlen": entry.getBitLen(), |
553 entry_declaration = slave_variables.get((index, subindex), None) |
553 } |
554 if entry_declaration is not None: |
554 entry_infos.update(type_infos) |
555 pdo_needed = True |
555 entries_infos.append(" {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos) |
556 |
556 |
557 entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["infos"]))) |
557 entry_declaration = slave_variables.get((index, subindex), None) |
558 entry_declaration["mapped"] = True |
558 if entry_declaration is not None and not entry_declaration["mapped"]: |
559 |
559 pdo_needed = True |
560 if entry_infos["var_type"] != entry.getDataType().getcontent(): |
560 |
561 raise ValueError, _("Wrong type for location \"%s\"!") % entry_infos["var_name"] |
561 entry_infos.update(dict(zip(["var_type", "dir", "var_name"], entry_declaration["infos"]))) |
562 |
562 entry_declaration["mapped"] = True |
563 if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or |
563 |
564 entry_infos["dir"] == "Q" and pdo_type != "Outputs"): |
564 if entry_infos["var_type"] != entry.getDataType().getcontent(): |
565 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
565 raise ValueError, _("Wrong type for location \"%s\"!") % entry_infos["var_name"] |
566 |
566 |
567 ConfigureVariable(entry_infos, str_completion) |
567 if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or |
568 |
568 entry_infos["dir"] == "Q" and pdo_type != "Outputs"): |
569 if pdo_needed: |
569 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
570 sm = pdo.getSm() |
570 |
571 if sm is None: |
571 ConfigureVariable(entry_infos, str_completion) |
572 for sm_idx, sync_manager in enumerate(sync_managers): |
572 |
573 if sync_manager["Name"] == pdo_type: |
573 if pdo_needed: |
574 sm = sm_idx |
574 sm = pdo.getSm() |
575 if sm is None: |
575 if sm is None: |
576 raise ValueError, _("No sync manager available for %s pdo!") % pdo_type |
576 for sm_idx, sync_manager in enumerate(sync_managers): |
577 |
577 if sync_manager["name"] == pdo_type: |
578 sync_managers[sm]["pdos_number"] += 1 |
578 sm = sm_idx |
579 sync_managers[sm]["pdos"].append( |
579 if sm is None: |
580 {"slave": slave_idx, |
580 raise ValueError, _("No sync manager available for %s pdo!") % pdo_type |
581 "index": pdo_index, |
581 |
582 "name": ExtractName(pdo.getName()), |
582 sync_managers[sm]["pdos_number"] += 1 |
583 "type": pdo_type, |
583 sync_managers[sm]["pdos"].append( |
584 "entries": entries_infos, |
584 {"slave": slave_idx, |
585 "entries_number": len(entries_infos), |
585 "index": pdo_index, |
586 "fixed": pdo.getFixed() == True}) |
586 "name": ExtractName(pdo.getName()), |
|
587 "type": pdo_type, |
|
588 "entries": entries_infos, |
|
589 "entries_number": len(entries_infos), |
|
590 "fixed": pdo.getFixed() == True}) |
587 |
591 |
588 dynamic_pdos = {} |
592 dynamic_pdos = {} |
589 dynamic_pdos_number = 0 |
593 dynamic_pdos_number = 0 |
590 for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), |
594 for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), |
591 ("Outputs", 0x1a00, 0x1C00)]: |
595 ("Outputs", 0x1a00, 0x1C00)]: |
859 if entry is not None: |
863 if entry is not None: |
860 entry["PDO index"] = pdo_index |
864 entry["PDO index"] = pdo_index |
861 entry["PDO name"] = pdo_name |
865 entry["PDO name"] = pdo_name |
862 entry["PDO type"] = pdo_type |
866 entry["PDO type"] = pdo_type |
863 else: |
867 else: |
864 if pdo_type == "Transmit": |
868 entry_type = pdo_entry.getDataType() |
865 access = "ro" |
869 if entry_type is not None: |
866 else: |
870 if pdo_type == "Transmit": |
867 access = "wo" |
871 access = "ro" |
868 entries[(index, subindex)] = { |
872 else: |
869 "Index": entry_index, |
873 access = "wo" |
870 "SubIndex": entry_subindex, |
874 entries[(index, subindex)] = { |
871 "Name": ExtractName(pdo_entry.getName()), |
875 "Index": entry_index, |
872 "Type": pdo_entry.getDataType().getcontent(), |
876 "SubIndex": entry_subindex, |
873 "Access": access, |
877 "Name": ExtractName(pdo_entry.getName()), |
874 "PDO index": pdo_index, |
878 "Type": entry_type.getcontent(), |
875 "PDO name": pdo_name, |
879 "Access": access, |
876 "PDO type": pdo_type} |
880 "PDO index": pdo_index, |
|
881 "PDO name": pdo_name, |
|
882 "PDO type": pdo_type} |
877 |
883 |
878 class RootClass: |
884 class RootClass: |
879 |
885 |
880 PlugChildsTypes = [("EthercatNode",_EthercatPlug,"Ethercat Master")] |
886 PlugChildsTypes = [("EthercatNode",_EthercatPlug,"Ethercat Master")] |
881 |
887 |
929 modules_infos.loadXMLTree(child, ["xmlns:xsi", "xsi:noNamespaceSchemaLocation"]) |
935 modules_infos.loadXMLTree(child, ["xmlns:xsi", "xsi:noNamespaceSchemaLocation"]) |
930 |
936 |
931 if modules_infos is not None: |
937 if modules_infos is not None: |
932 vendor = modules_infos.getVendor() |
938 vendor = modules_infos.getVendor() |
933 |
939 |
934 vendor_category = self.ModulesLibrary.setdefault(vendor.getId(), {"name": ExtractName(vendor.getName(), _("Miscellaneous")), |
940 vendor_category = self.ModulesLibrary.setdefault(ExtractHexDecValue(vendor.getId()), |
935 "groups": {}}) |
941 {"name": ExtractName(vendor.getName(), _("Miscellaneous")), |
|
942 "groups": {}}) |
936 |
943 |
937 for group in modules_infos.getDescriptions().getGroups().getGroup(): |
944 for group in modules_infos.getDescriptions().getGroups().getGroup(): |
938 group_type = group.getType() |
945 group_type = group.getType() |
939 |
946 |
940 vendor_category["groups"].setdefault(group_type, {"name": ExtractName(group.getName(), group_type), |
947 vendor_category["groups"].setdefault(group_type, {"name": ExtractName(group.getName(), group_type), |
979 device_type_occurrences.append(device_infos) |
986 device_type_occurrences.append(device_infos) |
980 for device_type_occurrences in device_dict.itervalues(): |
987 for device_type_occurrences in device_dict.itervalues(): |
981 if len(device_type_occurrences) > 1: |
988 if len(device_type_occurrences) > 1: |
982 for occurrence in device_type_occurrences: |
989 for occurrence in device_type_occurrences: |
983 occurrence["name"] += _(" (rev. %s)") % occurrence["infos"]["revision_number"] |
990 occurrence["name"] += _(" (rev. %s)") % occurrence["infos"]["revision_number"] |
984 library.sort(lambda x, y: x["name"].__cmp__(y["name"])) |
991 library.sort(lambda x, y: cmp(x["name"], y["name"])) |
985 return library |
992 return library |
986 |
993 |
987 def GetModuleInfos(self, type_infos): |
994 def GetModuleInfos(self, type_infos): |
988 vendor = self.ModulesLibrary.get(type_infos["vendor"], None) |
995 vendor = self.ModulesLibrary.get(ExtractHexDecValue(type_infos["vendor"]), None) |
989 if vendor is not None: |
996 if vendor is not None: |
990 for group_name, group in vendor["groups"].iteritems(): |
997 for group_name, group in vendor["groups"].iteritems(): |
991 for device_type, device in group["devices"]: |
998 for device_type, device in group["devices"]: |
992 product_code = ExtractHexDecValue(device.getType().getProductCode()) |
999 product_code = ExtractHexDecValue(device.getType().getProductCode()) |
993 revision_number = ExtractHexDecValue(device.getType().getRevisionNo()) |
1000 revision_number = ExtractHexDecValue(device.getType().getRevisionNo()) |