634 return -1; |
634 return -1; |
635 } |
635 } |
636 } |
636 } |
637 """ |
637 """ |
638 |
638 |
|
639 SLAVE_OUTPUT_PDO_DEFAULT_VALUE = """ |
|
640 { |
|
641 uint8_t value[%(data_size)d]; |
|
642 if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) { |
|
643 fprintf(stderr, "Failed to get default value for output PDO in slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code); |
|
644 return -1; |
|
645 } |
|
646 for (i = 0; i < result_size; i++) { |
|
647 %(real_var)s = (%(real_var)s << 8) + value[i]; |
|
648 } |
|
649 } |
|
650 """ |
|
651 |
639 def ConfigureVariable(entry_infos, str_completion): |
652 def ConfigureVariable(entry_infos, str_completion): |
640 entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None) |
653 entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None) |
641 if entry_infos["data_type"] is None: |
654 if entry_infos["data_type"] is None: |
642 raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"] |
655 raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"] |
643 |
656 |
644 entry_infos["real_var"] = "beremiz" + entry_infos["var_name"] |
657 if entry_infos.has_key("real_var"): |
645 str_completion["located_variables_declaration"].extend( |
658 str_completion["located_variables_declaration"].append( |
646 ["IEC_%(var_type)s %(real_var)s;" % entry_infos, |
659 "IEC_%(var_type)s %(real_var)s;" % entry_infos) |
647 "IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos]) |
660 else: |
|
661 entry_infos["real_var"] = "beremiz" + entry_infos["var_name"] |
|
662 str_completion["located_variables_declaration"].extend( |
|
663 ["IEC_%(var_type)s %(real_var)s;" % entry_infos, |
|
664 "IEC_%(var_type)s *%(var_name)s = &%(real_var)s;" % entry_infos]) |
648 |
665 |
649 str_completion["used_pdo_entry_offset_variables_declaration"].append( |
666 str_completion["used_pdo_entry_offset_variables_declaration"].append( |
650 "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos) |
667 "unsigned int slave%(slave)d_%(index).4x_%(subindex).2x;" % entry_infos) |
651 |
668 |
652 if entry_infos["data_type"] == "BIT": |
669 if entry_infos["data_type"] == "BIT": |
723 "used_pdo_entry_offset_variables_declaration": [], |
740 "used_pdo_entry_offset_variables_declaration": [], |
724 "used_pdo_entry_configuration": [], |
741 "used_pdo_entry_configuration": [], |
725 "pdos_configuration_declaration": "", |
742 "pdos_configuration_declaration": "", |
726 "slaves_declaration": "", |
743 "slaves_declaration": "", |
727 "slaves_configuration": "", |
744 "slaves_configuration": "", |
|
745 "slaves_output_pdos_default_values_extraction": "", |
728 "slaves_initialization": "", |
746 "slaves_initialization": "", |
729 "retrieve_variables": [], |
747 "retrieve_variables": [], |
730 "publish_variables": [], |
748 "publish_variables": [], |
731 } |
749 } |
732 |
750 |
844 if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or |
862 if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or |
845 entry_infos["dir"] == "Q" and pdo_type != "Outputs"): |
863 entry_infos["dir"] == "Q" and pdo_type != "Outputs"): |
846 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
864 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
847 |
865 |
848 ConfigureVariable(entry_infos, str_completion) |
866 ConfigureVariable(entry_infos, str_completion) |
|
867 |
|
868 elif pdo_type == "Outputs" and entry.getDataType() is not None: |
|
869 entry_infos["dir"] = "Q" |
|
870 entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8) |
|
871 entry_infos["var_type"] = entry.getDataType().getcontent() |
|
872 entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos |
|
873 |
|
874 ConfigureVariable(entry_infos, str_completion) |
|
875 |
|
876 str_completion["slaves_output_pdos_default_values_extraction"] += \ |
|
877 SLAVE_OUTPUT_PDO_DEFAULT_VALUE % entry_infos |
849 |
878 |
850 if pdo_needed: |
879 if pdo_needed: |
851 for excluded in pdo.getExclude(): |
880 for excluded in pdo.getExclude(): |
852 excluded_index = ExtractHexDecValue(excluded.getcontent()) |
881 excluded_index = ExtractHexDecValue(excluded.getcontent()) |
853 if excluded_index not in excluded_pdos: |
882 if excluded_index not in excluded_pdos: |