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