etherlab/EthercatCFileGenerator.py
branchethercat_from_kosmos
changeset 2641 c9deff128c37
parent 2165 02a2b5dee5e3
child 2643 b98d9e08231f
equal deleted inserted replaced
2192:09d5d1456616 2641:c9deff128c37
    65             goto ecat_failed;
    65             goto ecat_failed;
    66         }
    66         }
    67         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
    67         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
    68     }
    68     }
    69 """
    69 """
       
    70 
       
    71 SLAVE_OUTPUT_PDO_DEFAULT_VALUE_BIT = """
       
    72     {
       
    73         uint8_t value[%(data_size)d];
       
    74         if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
       
    75             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);
       
    76             goto ecat_failed;
       
    77         }
       
    78         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value, %(subindex)d);
       
    79     }
       
    80 """
       
    81 
       
    82 
       
    83 SLAVE_INPUT_PDO_DEFAULT_VALUE = """
       
    84     {
       
    85         uint8_t value[%(data_size)d];
       
    86         if (ecrt_master_sdo_upload(master, %(slave)d, 0x%(index).4x, 0x%(subindex).2x, (uint8_t *)value, %(data_size)d, &result_size, &abort_code)) {
       
    87             SLOGF(LOG_CRITICAL, "EtherCAT failed to get default value for input PDO in slave %(device_type)s at alias %(alias)d and position %(position)d. Error: %%ud", abort_code);
       
    88             goto ecat_failed;
       
    89         }
       
    90         %(real_var)s = EC_READ_%(data_type)s((uint8_t *)value);
       
    91     }
       
    92 """
       
    93 
       
    94 DC_VARIABLE ="""
       
    95 #define DC_ENABLE       %(dc_flag)d
       
    96 """
       
    97 
       
    98 CONFIG_DC = """
       
    99     ecrt_slave_config_dc (slave%(slave)d, 0x0%(assign_activate)ld, %(sync0_cycle_time)d, %(sync0_shift_time)d, %(sync1_cycle_time)d, %(sync1_shift_time)d);
       
   100 """
       
   101 
    70 
   102 
    71 def ConfigureVariable(entry_infos, str_completion):
   103 def ConfigureVariable(entry_infos, str_completion):
    72     entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None)
   104     entry_infos["data_type"] = DATATYPECONVERSION.get(entry_infos["var_type"], None)
    73     if entry_infos["data_type"] is None:
   105     if entry_infos["data_type"] is None:
    74         raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"]
   106         raise ValueError, _("Type of location \"%s\" not yet supported!") % entry_infos["var_name"]
   165                     raise ValueError, _("Output variables can't be defined with different locations (%s and %s)") % (entry_infos["infos"][2], name)
   197                     raise ValueError, _("Output variables can't be defined with different locations (%s and %s)") % (entry_infos["infos"][2], name)
   166         else:
   198         else:
   167             raise ValueError, _("Definition conflict for location \"%s\"") % name 
   199             raise ValueError, _("Definition conflict for location \"%s\"") % name 
   168         
   200         
   169     def GenerateCFile(self, filepath, location_str, master_number):
   201     def GenerateCFile(self, filepath, location_str, master_number):
   170         
       
   171         # Extract etherlab master code template
   202         # Extract etherlab master code template
   172         plc_etherlab_filepath = os.path.join(os.path.split(__file__)[0], "plc_etherlab.c")
   203         plc_etherlab_filepath = os.path.join(os.path.split(__file__)[0], "plc_etherlab.c")
   173         plc_etherlab_file = open(plc_etherlab_filepath, 'r')
   204         plc_etherlab_file = open(plc_etherlab_filepath, 'r')
   174         plc_etherlab_code = plc_etherlab_file.read()
   205         plc_etherlab_code = plc_etherlab_file.read()
   175         plc_etherlab_file.close()
   206         plc_etherlab_file.close()
   182             "used_pdo_entry_offset_variables_declaration": [],
   213             "used_pdo_entry_offset_variables_declaration": [],
   183             "used_pdo_entry_configuration": [],
   214             "used_pdo_entry_configuration": [],
   184             "pdos_configuration_declaration": "",
   215             "pdos_configuration_declaration": "",
   185             "slaves_declaration": "",
   216             "slaves_declaration": "",
   186             "slaves_configuration": "",
   217             "slaves_configuration": "",
       
   218             # add jblee
       
   219             "slaves_input_pdos_default_values_extraction": "",
   187             "slaves_output_pdos_default_values_extraction": "",
   220             "slaves_output_pdos_default_values_extraction": "",
   188             "slaves_initialization": "",
   221             "slaves_initialization": "",
   189             "retrieve_variables": [],
   222             "retrieve_variables": [],
   190             "publish_variables": [],
   223             "publish_variables": [],
       
   224             #-----------This Code templete for dc -------------------#
       
   225             "dc_variable" : "",
       
   226             "config_dc": ""
   191         }
   227         }
   192         
   228         
   193         # Initialize variable storing variable mapping state
   229         # Initialize variable storing variable mapping state
   194         for slave_entries in self.UsedVariables.itervalues():
   230         for slave_entries in self.UsedVariables.itervalues():
   195             for entry_infos in slave_entries.itervalues():
   231             for entry_infos in slave_entries.itervalues():
   197         
   233         
   198         # Sort slaves by position (IEC_Channel)
   234         # Sort slaves by position (IEC_Channel)
   199         self.Slaves.sort()
   235         self.Slaves.sort()
   200         # Initialize dictionary storing alias auto-increment position values
   236         # Initialize dictionary storing alias auto-increment position values
   201         alias = {}
   237         alias = {}
       
   238 
       
   239         # add jblee
       
   240         slotNumber = 1
   202         
   241         
   203         # Generating code for each slave
   242         # Generating code for each slave
   204         for (slave_idx, slave_alias, slave) in self.Slaves:
   243         for (slave_idx, slave_alias, slave) in self.Slaves:
   205             type_infos = slave.getType()
   244             type_infos = slave.getType()
   206             
   245             
   219             # Extract slaves variables to be mapped
   258             # Extract slaves variables to be mapped
   220             slave_variables = self.UsedVariables.get(slave_idx, {})
   259             slave_variables = self.UsedVariables.get(slave_idx, {})
   221             
   260             
   222             # Extract slave device object dictionary entries
   261             # Extract slave device object dictionary entries
   223             device_entries = device.GetEntriesList()
   262             device_entries = device.GetEntriesList()
       
   263             #device_entries = self.Controler.CTNParent.GetEntriesList()
   224             
   264             
   225             # Adding code for declaring slave in master code template strings
   265             # Adding code for declaring slave in master code template strings
   226             for element in ["vendor", "product_code", "revision_number"]:
   266             for element in ["vendor", "product_code", "revision_number"]:
   227                 type_infos[element] = ExtractHexDecValue(type_infos[element])
   267                 type_infos[element] = ExtractHexDecValue(type_infos[element])
   228             type_infos.update(dict(zip(["slave", "alias", "position"], (slave_idx,) + slave_pos)))
   268             type_infos.update(dict(zip(["slave", "alias", "position"], (slave_idx,) + slave_pos)))
   229             
   269             
   230             # Extract slave device CoE informations
   270             # Extract slave device CoE informations
   231             device_coe = device.getCoE()
   271             device_coe = device.getCoE()
   232             if device_coe is not None:
   272             if device_coe is not None:
   233                 
       
   234                 # If device support CanOpen over Ethernet, adding code for calling 
   273                 # If device support CanOpen over Ethernet, adding code for calling 
   235                 # init commands when initializing slave in master code template strings
   274                 # init commands when initializing slave in master code template strings
   236                 initCmds = []
   275                 initCmds = []
       
   276                 
   237                 for initCmd in device_coe.getInitCmd():
   277                 for initCmd in device_coe.getInitCmd():
   238                     initCmds.append({
   278                     initCmds.append({
   239                         "Index": ExtractHexDecValue(initCmd.getIndex()),
   279                         "Index": ExtractHexDecValue(initCmd.getIndex()),
   240                         "Subindex": ExtractHexDecValue(initCmd.getSubIndex()),
   280                         "Subindex": ExtractHexDecValue(initCmd.getSubIndex()),
   241                         "Value": initCmd.getData().getcontent()})
   281                         #"Value": initCmd.getData().getcontent()})
       
   282                         "Value": int(initCmd.getData().text, 16)})
       
   283                 
   242                 initCmds.extend(slave.getStartupCommands())
   284                 initCmds.extend(slave.getStartupCommands())
   243                 for initCmd in initCmds:
   285                 for initCmd in initCmds:
   244                     index = initCmd["Index"]
   286                     index = initCmd["Index"]
   245                     subindex = initCmd["Subindex"]
   287                     subindex = initCmd["Subindex"]
   246                     entry = device_entries.get((index, subindex), None)
   288                     entry = device_entries.get((index, subindex), None)
   262                 PdoConfig = device_coe.getPdoConfig()
   304                 PdoConfig = device_coe.getPdoConfig()
   263             else:
   305             else:
   264                 PdoAssign = PdoConfig = False
   306                 PdoAssign = PdoConfig = False
   265             
   307             
   266             # Test if slave has a configuration or need one
   308             # Test if slave has a configuration or need one
   267             if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0 and PdoConfig and PdoAssign:
   309             #if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0 and PdoConfig and PdoAssign:
   268                 
   310             if len(device.getTxPdo() + device.getRxPdo()) > 0 or len(slave_variables) > 0 or device.getSlots() is not None:
   269                 str_completion["slaves_declaration"] += "static ec_slave_config_t *slave%(slave)d = NULL;\n" % type_infos
   311                 str_completion["slaves_declaration"] += "static ec_slave_config_t *slave%(slave)d = NULL;\n" % type_infos
   270                 str_completion["slaves_configuration"] += SLAVE_CONFIGURATION_TEMPLATE % type_infos
   312                 str_completion["slaves_configuration"] += SLAVE_CONFIGURATION_TEMPLATE % type_infos
   271                 
   313 
   272                 # Initializing 
   314                 # Initializing 
   273                 pdos_infos = {
   315                 pdos_infos = {
   274                     "pdos_entries_infos": [],
   316                     "pdos_entries_infos": [],
   275                     "pdos_infos": [],
   317                     "pdos_infos": [],
   276                     "pdos_sync_infos": [], 
   318                     "pdos_sync_infos": [], 
   302                     sync_managers.append(sync_manager_infos)
   344                     sync_managers.append(sync_manager_infos)
   303                 
   345                 
   304                 pdos_index = []
   346                 pdos_index = []
   305                 exclusive_pdos = {}
   347                 exclusive_pdos = {}
   306                 selected_pdos = []
   348                 selected_pdos = []
   307                 for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
   349 
   308                                       [(pdo, "Outputs") for pdo in device.getRxPdo()]):
   350                 # add jblee
   309                     
   351                 TxPdoData = []
       
   352                 RxPdoData = []
       
   353                 PdoData = []
       
   354 
       
   355                 # add jblee
       
   356                 if len(device.getTxPdo() + device.getRxPdo()) > 0:
       
   357                     for pdo in device.getTxPdo():
       
   358                         PdoData.append((pdo, "Inputs"))
       
   359                     for pdo in device.getRxPdo():
       
   360                         PdoData.append((pdo, "Outputs"))               
       
   361 
       
   362                 # mod jblee
       
   363                 #for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
       
   364                 #                      [(pdo, "Outputs") for pdo in device.getRxPdo()]):
       
   365                 #for pdo, pdo_type in (TxPdoData + RxPdoData):
       
   366                 data_files = os.listdir(self.Controler.CTNPath())
       
   367                 PDODataList = []
       
   368                 MDPData = []
       
   369                 RxPDOData = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getRxPDO()
       
   370                 TxPDOData = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getTxPDO()
       
   371                 PDOList = RxPDOData.split() + TxPDOData.split()
       
   372                 for PDOIndex in PDOList:
       
   373                     if PDOIndex in ["RxPDO", "TxPDO", "None"]:
       
   374                         continue
       
   375                     PDODataList.append(int(PDOIndex, 0))
       
   376 
       
   377                 # add jblee for DC Configuration
       
   378                 dc_enable = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Enable()
       
   379                 sync0_cycle_time = 0
       
   380                 sync0_shift_time = 0
       
   381                 sync1_cycle_time = 0
       
   382                 sync1_shift_time = 0
       
   383                 if dc_enable :
       
   384                     sync0_cycle_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync0_Cycle_Time()
       
   385                     if sync0_cycle_token != "None":
       
   386                         sync0_cycle_time = int(sync0_cycle_token.split("_")[1]) * 1000
       
   387                     sync0_shift_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync0_Shift_Time()
       
   388                     if sync0_shift_token != "None":
       
   389                         sync0_shift_time = int(sync0_shift_token) * 1000
       
   390                     sync1_cycle_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync1_Cycle_Time()
       
   391                     if sync1_cycle_token != "None":
       
   392                         sync1_cycle_time = int(sync1_cycle_token.split("_")[1]) * 1000
       
   393                     sync1_shift_token = self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Sync1_Shift_Time()
       
   394                     if sync1_shift_token != "None":
       
   395                         sync1_shift_time = int(sync1_shift_token) * 1000
       
   396                     
       
   397                     dc_config_data = {
       
   398                         "slave" : slave_idx,
       
   399                         "assign_activate" : int(self.Controler.GetChildByIECLocation((slave_idx,)).BaseParams.getDC_Assign_Activate()),
       
   400                         "sync0_cycle_time" : sync0_cycle_time,
       
   401                         "sync0_shift_time" : sync0_shift_time,
       
   402                         "sync1_cycle_time" : sync1_cycle_time,
       
   403                         "sync1_shift_time" : sync1_shift_time,
       
   404                     }
       
   405 
       
   406                     if dc_enable and not str_completion["dc_variable"] :
       
   407                         str_completion["dc_variable"] += DC_VARIABLE % {"dc_flag" : dc_enable}
       
   408                     str_completion["config_dc"] += CONFIG_DC % dc_config_data
       
   409 
       
   410                 for data_file in data_files:
       
   411                     slave_path = os.path.join(self.Controler.CTNPath(), data_file)
       
   412                     if os.path.isdir(slave_path):
       
   413                         CheckConfNodePath = os.path.join(slave_path, "baseconfnode.xml")
       
   414                         confNodeFile = open(CheckConfNodePath, 'r')
       
   415                         checklines = confNodeFile.readlines()
       
   416                         confNodeFile.close()
       
   417                         # checklines(ex) : <BaseParams xmlns:xsd="http://www.w3.org/2001/XMLSchema" IEC_Channel="0" Name="EthercatSlave_0"/>
       
   418                         # checklines[1].split() : [<BaseParams, xmlns:xsd="http://www.w3.org/2001/XMLSchema",
       
   419                         #                           IEC_Channel="0", Name="EthercatSlave_0"/>]
       
   420                         # checklines[1].split()[2] : IEC_Channel="0"
       
   421                         # checklines[1].split()[2].split("\"") = [IEC_Channel=, 0, ]
       
   422                         pos_check = int(checklines[1].split()[2].split("\"")[1])
       
   423                         if slave_idx == pos_check:
       
   424                             MDPDataFilePath = os.path.join(slave_path, "DataForMDP.txt")
       
   425                             if os.path.isfile(MDPDataFilePath):
       
   426                                 MDPDataFile = open(MDPDataFilePath, 'r')
       
   427                                 MDPData = MDPDataFile.readlines()
       
   428                                 MDPDataFile.close()
       
   429 
       
   430                         for MDPLine in MDPData:
       
   431                             if MDPLine == "\n":
       
   432                                 continue
       
   433                             module_pos = int(MDPLine.split()[-1])
       
   434                             module = self.Controler.CTNParent.GetSelectModule(module_pos)
       
   435                             for pdo in module.getTxPdo():
       
   436                                 PdoData.append((pdo, "Inputs"))
       
   437                                 PDODataList.append(ExtractHexDecValue(pdo.getIndex().getcontent()))
       
   438                             for pdo in module.getRxPdo():
       
   439                                 PdoData.append((pdo, "Outputs"))
       
   440                                 PDODataList.append(ExtractHexDecValue(pdo.getIndex().getcontent()))
       
   441 
       
   442                 for pdo, pdo_type in PdoData:
   310                     pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
   443                     pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
   311                     pdos_index.append(pdo_index)
   444                     pdos_index.append(pdo_index)
   312                     
   445 
       
   446                     if PDODataList and (pdo_index in PDODataList):
       
   447                         continue
       
   448 
   313                     excluded_list = pdo.getExclude()
   449                     excluded_list = pdo.getExclude()
   314                     if len(excluded_list) > 0:
   450                     if len(excluded_list) > 0:
   315                         exclusion_list = [pdo_index]
   451                         exclusion_list = [pdo_index]
   316                         for excluded in excluded_list:
   452                         for excluded in excluded_list:
   317                             exclusion_list.append(ExtractHexDecValue(excluded.getcontent()))
   453                             exclusion_list.append(ExtractHexDecValue(excluded.getcontent()))
   318                         exclusion_list.sort()
   454                         exclusion_list.sort()                     
   319                         
   455                         exclusion_scope = exclusive_pdos.setdefault(tuple(exclusion_list), [])                   
   320                         exclusion_scope = exclusive_pdos.setdefault(tuple(exclusion_list), [])
       
   321                         
       
   322                         entries = pdo.getEntry()
   456                         entries = pdo.getEntry()
       
   457 
   323                         pdo_mapping_match = {
   458                         pdo_mapping_match = {
   324                             "index": pdo_index, 
   459                             "index": pdo_index, 
   325                             "matching": 0, 
   460                             "matching": 0, 
   326                             "count": len(entries), 
   461                             "count": len(entries), 
   327                             "assigned": pdo.getSm() is not None
   462                             "assigned": pdo.getSm() is not None
   328                         }
   463                         }
       
   464 
   329                         exclusion_scope.append(pdo_mapping_match)
   465                         exclusion_scope.append(pdo_mapping_match)
   330                         
   466                         
   331                         for entry in entries:
   467                         for entry in entries:
   332                             index = ExtractHexDecValue(entry.getIndex().getcontent())
   468                             index = ExtractHexDecValue(entry.getIndex().getcontent())
   333                             subindex = ExtractHexDecValue(entry.getSubIndex())
   469                             subindex = ExtractHexDecValue(entry.getSubIndex())
   350                         selected_pdos.append(exclusion_scope[0]["index"])
   486                         selected_pdos.append(exclusion_scope[0]["index"])
   351                         start_excluding_index = 1
   487                         start_excluding_index = 1
   352                     excluded_pdos.extend([pdo["index"] 
   488                     excluded_pdos.extend([pdo["index"] 
   353                         for pdo in exclusion_scope[start_excluding_index:] 
   489                         for pdo in exclusion_scope[start_excluding_index:] 
   354                         if PdoAssign or not pdo["assigned"]])
   490                         if PdoAssign or not pdo["assigned"]])
   355                 
   491 
   356                 for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
   492                 # mod jblee
   357                                       [(pdo, "Outputs") for pdo in device.getRxPdo()]):
   493                 #for pdo, pdo_type in ([(pdo, "Inputs") for pdo in device.getTxPdo()] +
   358                     entries = pdo.getEntry()
   494                 #                      [(pdo, "Outputs") for pdo in device.getRxPdo()]):
       
   495                 #for pdo, pdo_type in (TxPdoData + RxPdoData):
       
   496                 entry_check_list = []
       
   497                 index_padding = 1
       
   498                 for pdo, pdo_type in PdoData:
       
   499                     entries = pdo.getEntry()                   
   359                     
   500                     
   360                     pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
   501                     pdo_index = ExtractHexDecValue(pdo.getIndex().getcontent())
   361                     if pdo_index in excluded_pdos:
   502                     if pdo_index in excluded_pdos:
   362                         continue
   503                         continue
   363                     
   504                     if PDODataList and (pdo_index not in PDODataList):
   364                     pdo_needed = pdo_index in selected_pdos
   505                         continue
   365                     
   506                     
   366                     entries_infos = []
   507                     #pdo_needed = pdo_index in selected_pdos
   367                     
   508                     pdo_needed = pdo_index in PDODataList
       
   509 
       
   510                     if len(MDPData) > 0:
       
   511                         pdo_index += index_padding
       
   512                         index_padding += 1
       
   513 
       
   514                     entries_infos = []                   
   368                     for entry in entries:
   515                     for entry in entries:
   369                         index = ExtractHexDecValue(entry.getIndex().getcontent())
   516                         index = ExtractHexDecValue(entry.getIndex().getcontent())
   370                         subindex = ExtractHexDecValue(entry.getSubIndex())
   517                         subindex = ExtractHexDecValue(entry.getSubIndex())
       
   518 
       
   519                         # add jblee
       
   520                         if len(MDPData) > 0:
       
   521                             increse = self.Controler.CTNParent.GetMDPInfos(type_infos)                          
       
   522                             if increse and index != 0:
       
   523                                 index += int(increse[0][2]) * slotNumber
       
   524                                 
   371                         entry_infos = {
   525                         entry_infos = {
   372                             "index": index,
   526                             "index": index,
   373                             "subindex": subindex,
   527                             "subindex": subindex,
   374                             "name": ExtractName(entry.getName()),
   528                             "name": ExtractName(entry.getName()),
   375                             "bitlen": entry.getBitLen(),
   529                             "bitlen": entry.getBitLen(),
   376                         }
   530                         }
       
   531 
   377                         entry_infos.update(type_infos)
   532                         entry_infos.update(type_infos)
       
   533                         #temp_data = "    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos
       
   534                         check_data = "{0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}" % entry_infos
       
   535                         if entry_check_list and check_data in entry_check_list:
       
   536                             if (entry_infos["index"] == 0) or (entry_infos["name"] == None):
       
   537                                 pass
       
   538                             else: 
       
   539                                 continue
   378                         entries_infos.append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
   540                         entries_infos.append("    {0x%(index).4x, 0x%(subindex).2x, %(bitlen)d}, /* %(name)s */" % entry_infos)
       
   541                         entry_check_list.append(check_data)
   379                         
   542                         
   380                         entry_declaration = slave_variables.get((index, subindex), None)
   543                         entry_declaration = slave_variables.get((index, subindex), None)
   381                         if entry_declaration is not None and not entry_declaration["mapped"]:
   544                         if entry_declaration is not None and not entry_declaration["mapped"]:
   382                             pdo_needed = True
   545                             pdo_needed = True
   383                             
   546                             
   397                             if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or 
   560                             if (entry_infos["dir"] == "I" and pdo_type != "Inputs" or 
   398                                 entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
   561                                 entry_infos["dir"] == "Q" and pdo_type != "Outputs"):
   399                                 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
   562                                 raise ValueError, _("Wrong direction for location \"%s\"!") % entry_infos["var_name"]
   400                             
   563                             
   401                             ConfigureVariable(entry_infos, str_completion)
   564                             ConfigureVariable(entry_infos, str_completion)
   402                         
   565                             
   403                         elif pdo_type == "Outputs" and entry.getDataType() is not None and device_coe is not None:
   566                         elif pdo_type == "Outputs" and entry.getDataType() is not None and device_coe is not None:
   404                             data_type = entry.getDataType().getcontent()
   567                             data_type = entry.getDataType().getcontent()
   405                             entry_infos["dir"] = "Q"
   568                             entry_infos["dir"] = "Q"
   406                             entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8)
   569                             entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8)
   407                             entry_infos["data_type"] = DATATYPECONVERSION.get(data_type)
   570                             entry_infos["data_type"] = DATATYPECONVERSION.get(data_type)
   408                             entry_infos["var_type"] = data_type
   571                             entry_infos["var_type"] = data_type
   409                             entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos
   572                             entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos
   410                             
   573                             
   411                             ConfigureVariable(entry_infos, str_completion)
   574                             ConfigureVariable(entry_infos, str_completion)
   412                             
   575 
   413                             str_completion["slaves_output_pdos_default_values_extraction"] += \
   576                             if entry_infos["data_type"] == "BIT" :
   414                                 SLAVE_OUTPUT_PDO_DEFAULT_VALUE % entry_infos
   577                                 str_completion["slaves_output_pdos_default_values_extraction"] += \
   415                             
   578                                     SLAVE_OUTPUT_PDO_DEFAULT_VALUE_BIT % entry_infos
       
   579                             else :
       
   580                                 str_completion["slaves_output_pdos_default_values_extraction"] += \
       
   581                                     SLAVE_OUTPUT_PDO_DEFAULT_VALUE % entry_infos
       
   582 
       
   583                         elif pdo_type == "Inputs" and entry.getDataType() is not None and device_coe is not None:
       
   584                             data_type = entry.getDataType().getcontent()
       
   585                             entry_infos["dir"] = "I"
       
   586                             entry_infos["data_size"] = max(1, entry_infos["bitlen"] / 8)
       
   587                             entry_infos["data_type"] = DATATYPECONVERSION.get(data_type)
       
   588                             entry_infos["var_type"] = data_type
       
   589                             entry_infos["real_var"] = "slave%(slave)d_%(index).4x_%(subindex).2x_default" % entry_infos
       
   590                             
       
   591                             ConfigureVariable(entry_infos, str_completion)
       
   592                             
       
   593                             str_completion["slaves_input_pdos_default_values_extraction"] += \
       
   594                                 SLAVE_INPUT_PDO_DEFAULT_VALUE % entry_infos
       
   595                     
   416                     if pdo_needed:
   596                     if pdo_needed:
   417                         for excluded in pdo.getExclude():
   597                         for excluded in pdo.getExclude():
   418                             excluded_index = ExtractHexDecValue(excluded.getcontent())
   598                             excluded_index = ExtractHexDecValue(excluded.getcontent())
   419                             if excluded_index not in excluded_pdos:
   599                             if excluded_index not in excluded_pdos:
   420                                 excluded_pdos.append(excluded_index)
   600                                 excluded_pdos.append(excluded_index)
   421                         
   601                         
       
   602                         ############################################################
   422                         sm = pdo.getSm()
   603                         sm = pdo.getSm()
   423                         if sm is None:
   604                         if sm is None:
   424                             for sm_idx, sync_manager in enumerate(sync_managers):
   605                             for sm_idx, sync_manager in enumerate(sync_managers):
   425                                 if sync_manager["name"] == pdo_type:
   606                                 if sync_manager["name"] == pdo_type:
   426                                     sm = sm_idx
   607                                     sm = sm_idx
   427                         if sm is None:
   608                         if sm is None:
   428                             raise ValueError, _("No sync manager available for %s pdo!") % pdo_type
   609                             raise ValueError, _("No sync manager available for %s pdo!") % pdo_type
   429                             
   610                         
   430                         sync_managers[sm]["pdos_number"] += 1
   611                         sync_managers[sm]["pdos_number"] += 1
   431                         sync_managers[sm]["pdos"].append(
   612                         sync_managers[sm]["pdos"].append(
   432                             {"slave": slave_idx,
   613                             {"slave": slave_idx,
   433                              "index": pdo_index,
   614                              "index": pdo_index,
   434                              "name": ExtractName(pdo.getName()),
   615                              "name": ExtractName(pdo.getName()),
   435                              "type": pdo_type, 
   616                              "type": pdo_type, 
   436                              "entries": entries_infos,
   617                              "entries": entries_infos,
   437                              "entries_number": len(entries_infos),
   618                              "entries_number": len(entries_infos),
   438                              "fixed": pdo.getFixed() == True})
   619                              "fixed": pdo.getFixed() == True})
       
   620                         #############################################################
       
   621 
       
   622                     # for MDP
       
   623                     slotNumber += 1
   439             
   624             
   440                 if PdoConfig and PdoAssign:
   625                 if PdoConfig and PdoAssign:
   441                     dynamic_pdos = {}
   626                     dynamic_pdos = {}
   442                     dynamic_pdos_number = 0
   627                     dynamic_pdos_number = 0
   443                     for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), 
   628                     for category, min_index, max_index in [("Inputs", 0x1600, 0x1800), 
   457                         if not entry_declaration["mapped"]:
   642                         if not entry_declaration["mapped"]:
   458                             entry = device_entries.get((index, subindex), None)
   643                             entry = device_entries.get((index, subindex), None)
   459                             if entry is None:
   644                             if entry is None:
   460                                 raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \
   645                                 raise ValueError, _("Unknown entry index 0x%4.4x, subindex 0x%2.2x for device %s") % \
   461                                                  (index, subindex, type_infos["device_type"])
   646                                                  (index, subindex, type_infos["device_type"])
   462                             
   647 
   463                             entry_infos = {
   648                             entry_infos = {
   464                                 "index": index,
   649                                 "index": index,
   465                                 "subindex": subindex,
   650                                 "subindex": subindex,
   466                                 "name": entry["Name"],
   651                                 "name": entry["Name"],
   467                                 "bitlen": entry["BitSize"],
   652                                 "bitlen": entry["BitSize"],
   524                             if pdo["entries_number"] == module_extra_params["max_pdo_size"]:
   709                             if pdo["entries_number"] == module_extra_params["max_pdo_size"]:
   525                                 dynamic_pdos[pdo_type]["pdos"].pop(0)
   710                                 dynamic_pdos[pdo_type]["pdos"].pop(0)
   526                 
   711                 
   527                 pdo_offset = 0
   712                 pdo_offset = 0
   528                 entry_offset = 0
   713                 entry_offset = 0
       
   714                 slotNumber = 1
   529                 for sync_manager_infos in sync_managers:
   715                 for sync_manager_infos in sync_managers:
   530                 
       
   531                     for pdo_infos in sync_manager_infos["pdos"]:
   716                     for pdo_infos in sync_manager_infos["pdos"]:
   532                         pdo_infos["offset"] = entry_offset
   717                         pdo_infos["offset"] = entry_offset
   533                         pdo_entries = pdo_infos["entries"]
   718                         pdo_entries = pdo_infos["entries"]
   534                         pdos_infos["pdos_infos"].append(
   719                         pdos_infos["pdos_infos"].append(
   535                             ("    {0x%(index).4x, %(entries_number)d, " + 
   720                             ("    {0x%(index).4x, %(entries_number)d, " + 
   548                 for element in ["pdos_entries_infos", "pdos_infos", "pdos_sync_infos"]:
   733                 for element in ["pdos_entries_infos", "pdos_infos", "pdos_sync_infos"]:
   549                     pdos_infos[element] = "\n".join(pdos_infos[element])
   734                     pdos_infos[element] = "\n".join(pdos_infos[element])
   550                 
   735                 
   551                 str_completion["pdos_configuration_declaration"] += SLAVE_PDOS_CONFIGURATION_DECLARATION % pdos_infos
   736                 str_completion["pdos_configuration_declaration"] += SLAVE_PDOS_CONFIGURATION_DECLARATION % pdos_infos
   552             
   737             
   553             for (index, subindex), entry_declaration in slave_variables.iteritems():
   738             #for (index, subindex), entry_declaration in slave_variables.iteritems():
   554                 if not entry_declaration["mapped"]:
   739             #    if not entry_declaration["mapped"]:
   555                     message = _("Entry index 0x%4.4x, subindex 0x%2.2x not mapped for device %s") % \
   740             #        message = _("Entry index 0x%4.4x, subindex 0x%2.2x not mapped for device %s") % \
   556                                     (index, subindex, type_infos["device_type"])
   741             #                        (index, subindex, type_infos["device_type"])
   557                     self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n")
   742             #        self.Controler.GetCTRoot().logger.write_warning(_("Warning: ") + message + "\n")
   558                     
   743                     
   559         for element in ["used_pdo_entry_offset_variables_declaration", 
   744         for element in ["used_pdo_entry_offset_variables_declaration", 
   560                         "used_pdo_entry_configuration", 
   745                         "used_pdo_entry_configuration", 
   561                         "located_variables_declaration", 
   746                         "located_variables_declaration", 
   562                         "retrieve_variables", 
   747                         "retrieve_variables",