lib/sdo_request.c
author Florian Pose
Fri, 05 Oct 2018 10:24:11 +0200
branchstable-1.5
changeset 2724 b4a109b9e2a8
parent 2478 9640948881fd
permissions -rw-r--r--
Set --enable-sii-assign by default.
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
     5
 *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
     6
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
     7
 *  This file is part of the IgH EtherCAT master userspace library.
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
     8
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
     9
 *  The IgH EtherCAT master userspace library is free software; you can
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    10
 *  redistribute it and/or modify it under the terms of the GNU Lesser General
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    11
 *  Public License as published by the Free Software Foundation; version 2.1
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    12
 *  of the License.
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    14
 *  The IgH EtherCAT master userspace library is distributed in the hope that
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    15
 *  it will be useful, but WITHOUT ANY WARRANTY; without even the implied
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    16
 *  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    17
 *  GNU Lesser General Public License for more details.
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    19
 *  You should have received a copy of the GNU Lesser General Public License
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    20
 *  along with the IgH EtherCAT master userspace library. If not, see
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    21
 *  <http://www.gnu.org/licenses/>.
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    22
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    23
 *  ---
2421
bc2d4bf9cbe5 Removed trailing spaces.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    24
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    25
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    26
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
    27
 *  industrial property and similar rights of Beckhoff Automation GmbH.
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
/** \file
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 * Canopen over EtherCAT SDO request functions.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <stdio.h>
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include <string.h>
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
    40
#include "ioctl.h"
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "sdo_request.h"
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "slave_config.h"
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "master.h"
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    45
/*****************************************************************************/
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    46
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    47
void ec_sdo_request_clear(ec_sdo_request_t *req)
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    48
{
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    49
    if (req->data) {
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    50
        free(req->data);
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    51
    }
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    52
}
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    53
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
/*****************************************************************************
1959
656f114153c2 Free all userspace library objects on releasing master.
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
    55
 * Application interface.
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
 ****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
2434
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    58
void ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index,
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    59
        uint8_t subindex)
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    60
{
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    61
    ec_ioctl_sdo_request_t data;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    62
    int ret;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    63
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    64
    data.config_index = req->config->index;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    65
    data.request_index = req->index;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    66
    data.sdo_index = index;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    67
    data.sdo_subindex = subindex;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    68
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    69
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_INDEX, &data);
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    70
    if (EC_IOCTL_IS_ERROR(ret)) {
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    71
        fprintf(stderr, "Failed to set SDO request index/subindex: %s\n",
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    72
                strerror(EC_IOCTL_ERRNO(ret)));
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    73
    }
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    74
}
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    75
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    76
/*****************************************************************************/
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
    77
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
void ecrt_sdo_request_timeout(ec_sdo_request_t *req, uint32_t timeout)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    ec_ioctl_sdo_request_t data;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
    81
    int ret;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    data.config_index = req->config->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    data.request_index = req->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    data.timeout = timeout;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
    87
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_TIMEOUT, &data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
    88
    if (EC_IOCTL_IS_ERROR(ret)) {
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
        fprintf(stderr, "Failed to set SDO request timeout: %s\n",
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
    90
                strerror(EC_IOCTL_ERRNO(ret)));
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
    91
    }
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
uint8_t *ecrt_sdo_request_data(ec_sdo_request_t *req)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    return req->data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
size_t ecrt_sdo_request_data_size(const ec_sdo_request_t *req)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
    return req->data_size;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
ec_request_state_t ecrt_sdo_request_state(ec_sdo_request_t *req)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    ec_ioctl_sdo_request_t data;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   113
    int ret;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    data.config_index = req->config->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    data.request_index = req->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   118
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_STATE, &data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   119
    if (EC_IOCTL_IS_ERROR(ret)) {
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
        fprintf(stderr, "Failed to get SDO request state: %s\n",
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   121
                strerror(EC_IOCTL_ERRNO(ret)));
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   122
        return EC_REQUEST_ERROR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   123
    }
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
    if (data.size) { // new data waiting to be copied
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
        if (req->mem_size < data.size) {
2478
9640948881fd Minor: Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 2434
diff changeset
   127
            fprintf(stderr, "Received %zu bytes do not fit info SDO data"
9640948881fd Minor: Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 2434
diff changeset
   128
                    " memory (%zu bytes)!\n", data.size, req->mem_size);
2431
eee9ed9901f7 Do not re-alloc memory in library implementation of ecrt_sdo_request_state().
Florian Pose <fp@igh-essen.com>
parents: 2428
diff changeset
   129
            return EC_REQUEST_ERROR;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        data.data = req->data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   134
        ret = ioctl(req->config->master->fd,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   135
                EC_IOCTL_SDO_REQUEST_DATA, &data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   136
        if (EC_IOCTL_IS_ERROR(ret)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   137
            fprintf(stderr, "Failed to get SDO data: %s\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   138
                    strerror(EC_IOCTL_ERRNO(ret)));
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
            return EC_REQUEST_ERROR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        req->data_size = data.size;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    return data.state;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
void ecrt_sdo_request_read(ec_sdo_request_t *req)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
    ec_ioctl_sdo_request_t data;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   152
    int ret;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
    data.config_index = req->config->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    data.request_index = req->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   157
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_READ, &data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   158
    if (EC_IOCTL_IS_ERROR(ret)) {
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
        fprintf(stderr, "Failed to command an SDO read operation : %s\n",
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   160
                strerror(EC_IOCTL_ERRNO(ret)));
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   161
    }
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
void ecrt_sdo_request_write(ec_sdo_request_t *req)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    ec_ioctl_sdo_request_t data;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   169
    int ret;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    data.config_index = req->config->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
    data.request_index = req->index;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    data.data = req->data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    data.size = req->data_size;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   176
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_WRITE, &data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   177
    if (EC_IOCTL_IS_ERROR(ret)) {
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
        fprintf(stderr, "Failed to command an SDO write operation : %s\n",
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   179
                strerror(EC_IOCTL_ERRNO(ret)));
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents: 2431
diff changeset
   180
    }
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
/*****************************************************************************/