lib/sdo_request.c
author Knud Baastrup <kba@deif.com>
Tue, 14 Apr 2015 13:10:55 -0400
changeset 2628 d123727b805b
parent 2589 2b9c78543663
permissions -rw-r--r--
Maximum length of foe filename extended to 255.
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
 *
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
     5
 *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
2b9c78543663 Reverted default branch to stable-1.5.
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.
2589
2b9c78543663 Reverted default branch to stable-1.5.
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/>.
2589
2b9c78543663 Reverted default branch to stable-1.5.
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
 *  ---
2589
2b9c78543663 Reverted default branch to stable-1.5.
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    58
void ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    59
        uint8_t subindex)
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    60
{
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    61
    ec_ioctl_sdo_request_t data;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    62
    int ret;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    63
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    64
    data.config_index = req->config->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    65
    data.request_index = req->index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    66
    data.sdo_index = index;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    67
    data.sdo_subindex = subindex;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    68
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    69
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_INDEX, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    70
    if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    71
        fprintf(stderr, "Failed to set SDO request index/subindex: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    72
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    73
    }
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    74
}
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    75
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    76
/*****************************************************************************/
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    87
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_TIMEOUT, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
    90
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   118
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_STATE, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   121
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   122
        return EC_REQUEST_ERROR;
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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) {
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   127
            fprintf(stderr, "Received %zu bytes do not fit info SDO data"
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   128
                    " memory (%zu bytes)!\n", data.size, req->mem_size);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   134
        ret = ioctl(req->config->master->fd,
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   135
                EC_IOCTL_SDO_REQUEST_DATA, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   136
        if (EC_IOCTL_IS_ERROR(ret)) {
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   137
            fprintf(stderr, "Failed to get SDO data: %s\n",
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   157
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_READ, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   160
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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;
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   176
    ret = ioctl(req->config->master->fd, EC_IOCTL_SDO_REQUEST_WRITE, &data);
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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",
2589
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
diff changeset
   179
                strerror(EC_IOCTL_ERRNO(ret)));
2b9c78543663 Reverted default branch to stable-1.5.
Florian Pose <fp@igh-essen.com>
parents: 1959
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
/*****************************************************************************/