changeset 2081 | b1801bf4365c |
parent 2080 | 6d0d94cd0fe0 |
child 2082 | caae3ad2d03b |
2080:6d0d94cd0fe0 | 2081:b1801bf4365c |
---|---|
724 } |
724 } |
725 """ |
725 """ |
726 |
726 |
727 SLAVE_INITIALIZATION_TEMPLATE = """ |
727 SLAVE_INITIALIZATION_TEMPLATE = """ |
728 { |
728 { |
729 uint8_t value[] = {%(data)s}; |
729 uint8_t value[%(data_size)d]; |
730 EC_WRITE_%(data_type)s((uint8_t *)value, %(data)s); |
|
730 if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) { |
731 if (ecrt_master_sdo_download(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &abort_code)) { |
731 fprintf(stderr, "Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code); |
732 fprintf(stderr, "Failed to initialize slave %(device_type)s at alias %(alias)d and position %(position)d.\\nError: %%d\\n", abort_code); |
732 return -1; |
733 return -1; |
733 } |
734 } |
734 } |
735 } |
739 uint8_t value[%(data_size)d]; |
740 uint8_t value[%(data_size)d]; |
740 if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) { |
741 if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) { |
741 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); |
742 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); |
742 return -1; |
743 return -1; |
743 } |
744 } |
744 for (i = 0; i < result_size; i++) { |
745 %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value); |
745 %(real_var)s = (%(real_var)s << 8) + value[i]; |
|
746 } |
|
747 } |
746 } |
748 """ |
747 """ |
749 |
748 |
750 def ConfigureVariable(entry_infos, str_completion): |
749 def ConfigureVariable(entry_infos, str_completion): |
751 entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None) |
750 entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None) |
890 index = ExtractHexDecValue(initCmd.getIndex()) |
889 index = ExtractHexDecValue(initCmd.getIndex()) |
891 subindex = ExtractHexDecValue(initCmd.getSubIndex()) |
890 subindex = ExtractHexDecValue(initCmd.getSubIndex()) |
892 entry = device_entries.get((index, subindex), None) |
891 entry = device_entries.get((index, subindex), None) |
893 if entry is not None: |
892 if entry is not None: |
894 data_size = entry["BitSize"] / 8 |
893 data_size = entry["BitSize"] / 8 |
895 data = ("%%.%dx" % (data_size * 2)) % initCmd.getData().getcontent() |
894 data_str = ("0x%%.%dx" % (data_size * 2)) % initCmd.getData().getcontent() |
896 data_str = ",".join(["0x%s" % data[i:i+2] for i in xrange(0, data_size * 2, 2)]) |
|
897 init_cmd_infos = { |
895 init_cmd_infos = { |
898 "index": index, |
896 "index": index, |
899 "subindex": subindex, |
897 "subindex": subindex, |
900 "data": data_str, |
898 "data": data_str, |
899 "data_type": DATATYPECONVERSION.get(entry["Type"]), |
|
901 "data_size": data_size |
900 "data_size": data_size |
902 } |
901 } |
903 init_cmd_infos.update(type_infos) |
902 init_cmd_infos.update(type_infos) |
904 str_completion["slaves_initialization"] += SLAVE_INITIALIZATION_TEMPLATE % init_cmd_infos |
903 str_completion["slaves_initialization"] += SLAVE_INITIALIZATION_TEMPLATE % init_cmd_infos |
905 |
904 |
1000 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
999 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"] |
1001 |
1000 |
1002 ConfigureVariable(entry_infos, str_completion) |
1001 ConfigureVariable(entry_infos, str_completion) |
1003 |
1002 |
1004 elif pdo_type == "Outputs" and entry.getDataType() is not None and device_coe is not None: |
1003 elif pdo_type == "Outputs" and entry.getDataType() is not None and device_coe is not None: |
1004 data_type = entry.getDataType().getcontent() |
|
1005 entry_infos["dir"] = "Q" |
1005 entry_infos["dir"] = "Q" |
1006 entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8) |
1006 entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8) |
1007 entry_infos["var_type"] = entry.getDataType().getcontent() |
1007 entry_infos["data_type"] = DATATYPECONVERSION.get(data_type) |
1008 entry_infos["var_type"] = data_type |
|
1008 entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos |
1009 entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos |
1009 |
1010 |
1010 ConfigureVariable(entry_infos, str_completion) |
1011 ConfigureVariable(entry_infos, str_completion) |
1011 |
1012 |
1012 str_completion["slaves_output_pdos_default_values_extraction"] += \ |
1013 str_completion["slaves_output_pdos_default_values_extraction"] += \ |