etherlab/EthercatCFileGenerator.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Tue, 26 Jun 2018 14:48:44 +0300
changeset 2228 12cb48823b8c
parent 2165 02a2b5dee5e3
child 2355 fec77f2b9e07
child 2641 c9deff128c37
permissions -rw-r--r--
Fix size of ProjectDialog used by PLCOpenEditor

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