lib/master.c
branchstable-1.5
changeset 2241 0ba77ef52922
parent 2124 c4afc5fede19
child 2242 d23f69156cfd
equal deleted inserted replaced
2235:cd49c2c31dcb 2241:0ba77ef52922
     1 /******************************************************************************
     1 /******************************************************************************
     2  *  
     2  *
     3  *  $Id$
     3  *  $Id$
     4  *  
     4  *
     5  *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
     5  *  Copyright (C) 2006-2009  Florian Pose, Ingenieurgemeinschaft IgH
     6  *  
     6  *
     7  *  This file is part of the IgH EtherCAT master userspace library.
     7  *  This file is part of the IgH EtherCAT master userspace library.
     8  *  
     8  *
     9  *  The IgH EtherCAT master userspace library is free software; you can
     9  *  The IgH EtherCAT master userspace library is free software; you can
    10  *  redistribute it and/or modify it under the terms of the GNU Lesser General
    10  *  redistribute it and/or modify it under the terms of the GNU Lesser General
    11  *  Public License as published by the Free Software Foundation; version 2.1
    11  *  Public License as published by the Free Software Foundation; version 2.1
    12  *  of the License.
    12  *  of the License.
    13  *
    13  *
    17  *  GNU Lesser General Public License for more details.
    17  *  GNU Lesser General Public License for more details.
    18  *
    18  *
    19  *  You should have received a copy of the GNU Lesser General Public License
    19  *  You should have received a copy of the GNU Lesser General Public License
    20  *  along with the IgH EtherCAT master userspace library. If not, see
    20  *  along with the IgH EtherCAT master userspace library. If not, see
    21  *  <http://www.gnu.org/licenses/>.
    21  *  <http://www.gnu.org/licenses/>.
    22  *  
    22  *
    23  *  ---
    23  *  ---
    24  *  
    24  *
    25  *  The license mentioned above concerns the source code only. Using the
    25  *  The license mentioned above concerns the source code only. Using the
    26  *  EtherCAT technology and brand is only permitted in compliance with the
    26  *  EtherCAT technology and brand is only permitted in compliance with the
    27  *  industrial property and similar rights of Beckhoff Automation GmbH.
    27  *  industrial property and similar rights of Beckhoff Automation GmbH.
    28  *
    28  *
    29  *****************************************************************************/
    29  *****************************************************************************/
   116     domain = malloc(sizeof(ec_domain_t));
   116     domain = malloc(sizeof(ec_domain_t));
   117     if (!domain) {
   117     if (!domain) {
   118         fprintf(stderr, "Failed to allocate memory.\n");
   118         fprintf(stderr, "Failed to allocate memory.\n");
   119         return 0;
   119         return 0;
   120     }
   120     }
   121     
   121 
   122     index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL);
   122     index = ioctl(master->fd, EC_IOCTL_CREATE_DOMAIN, NULL);
   123     if (index == -1) {
   123     if (index == -1) {
   124         fprintf(stderr, "Failed to create domain: %s\n", strerror(errno));
   124         fprintf(stderr, "Failed to create domain: %s\n", strerror(errno));
   125         free(domain);
   125         free(domain);
   126         return 0; 
   126         return 0;
   127     }
   127     }
   128 
   128 
   129     domain->next = NULL;
   129     domain->next = NULL;
   130     domain->index = (unsigned int) index;
   130     domain->index = (unsigned int) index;
   131     domain->master = master;
   131     domain->master = master;
   164     sc = malloc(sizeof(ec_slave_config_t));
   164     sc = malloc(sizeof(ec_slave_config_t));
   165     if (!sc) {
   165     if (!sc) {
   166         fprintf(stderr, "Failed to allocate memory.\n");
   166         fprintf(stderr, "Failed to allocate memory.\n");
   167         return 0;
   167         return 0;
   168     }
   168     }
   169     
   169 
   170     data.alias = alias;
   170     data.alias = alias;
   171     data.position = position;
   171     data.position = position;
   172     data.vendor_id = vendor_id;
   172     data.vendor_id = vendor_id;
   173     data.product_code = product_code;
   173     data.product_code = product_code;
   174     
   174 
   175     if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) {
   175     if (ioctl(master->fd, EC_IOCTL_CREATE_SLAVE_CONFIG, &data) == -1) {
   176         fprintf(stderr, "Failed to create slave config: %s\n",
   176         fprintf(stderr, "Failed to create slave config: %s\n",
   177                 strerror(errno));
   177                 strerror(errno));
   178         free(sc);
   178         free(sc);
   179         return 0; 
   179         return 0;
   180     }
   180     }
   181 
   181 
   182     sc->next = NULL;
   182     sc->next = NULL;
   183     sc->master = master;
   183     sc->master = master;
   184     sc->index = data.config_index;
   184     sc->index = data.config_index;
   230     slave_info->product_code = data.product_code;
   230     slave_info->product_code = data.product_code;
   231     slave_info->revision_number = data.revision_number;
   231     slave_info->revision_number = data.revision_number;
   232     slave_info->serial_number = data.serial_number;
   232     slave_info->serial_number = data.serial_number;
   233     slave_info->alias = data.alias;
   233     slave_info->alias = data.alias;
   234     slave_info->current_on_ebus = data.current_on_ebus;
   234     slave_info->current_on_ebus = data.current_on_ebus;
       
   235     strncpy((char*) slave_info->ports, (char*) data.ports, sizeof(slave_info->ports));
   235     slave_info->al_state = data.al_state;
   236     slave_info->al_state = data.al_state;
   236     slave_info->error_flag = data.error_flag;
   237     slave_info->error_flag = data.error_flag;
   237     slave_info->sync_count = data.sync_count;
   238     slave_info->sync_count = data.sync_count;
   238     slave_info->sdo_count = data.sdo_count;
   239     slave_info->sdo_count = data.sdo_count;
   239     strncpy(slave_info->name, data.name, EC_MAX_STRING_LENGTH);
   240     strncpy(slave_info->name, data.name, EC_MAX_STRING_LENGTH);