src/objacces.c
author Edouard Tisserant
Mon, 23 Apr 2018 12:32:03 +0200
changeset 805 570e3a444023
parent 666 9febdd6fdc71
permissions -rw-r--r--
Workaround Alchemy task not beeing waken up when closing file descriptor it is waiting on, sequel of Xenomai3 all posix file ops
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     2
  This file is part of CanFestival, a library implementing CanOpen
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     3
  Stack.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     4
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     5
  Copyright (C): Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     6
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     7
  See COPYING file for copyrights details.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     8
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
     9
  This library is free software; you can redistribute it and/or
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    10
  modify it under the terms of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    11
  License as published by the Free Software Foundation; either
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    12
  version 2.1 of the License, or (at your option) any later version.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    13
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    14
  This library is distributed in the hope that it will be useful,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    17
  Lesser General Public License for more details.
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    18
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    19
  You should have received a copy of the GNU Lesser General Public
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    20
  License along with this library; if not, write to the Free Software
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    21
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    22
  USA
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    24
/*!
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    25
** @file   objacces.c
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    26
** @author Edouard TISSERANT and Francis DUPIN
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    27
** @date   Tue Jun  5 08:55:23 2007
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    28
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    29
** @brief
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    30
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    31
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    32
*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    33
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    34
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    35
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 55
diff changeset
    37
/* #define DEBUG_WAR_CONSOLE_ON */
95cd3376cc9f compilator compatitibility
frdupin
parents: 55
diff changeset
    38
/* #define DEBUG_ERR_CONSOLE_ON */
11
64ed038bdc74 Bogue:big endian
dejoigny
parents: 10
diff changeset
    39
1
b3dc740b4b04 Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents: 0
diff changeset
    40
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 215
diff changeset
    41
#include "data.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
629
b9274b595650 CosateQ contribution.
edouard
parents: 594
diff changeset
    43
//We need the function implementation for linking
b9274b595650 CosateQ contribution.
edouard
parents: 594
diff changeset
    44
//Only a placeholder with a define isnt enough!
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    45
UNS8 accessDictionaryError(UNS16 index, UNS8 subIndex,
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 469
diff changeset
    46
                           UNS32 sizeDataDict, UNS32 sizeDataGiven, UNS32 code)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
{
629
b9274b595650 CosateQ contribution.
edouard
parents: 594
diff changeset
    48
#ifdef DEBUG_WAR_CONSOLE_ON
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
  MSG_WAR(0x2B09,"Dictionary index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
  MSG_WAR(0X2B10,"           subindex : ", subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
  switch (code) {
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    52
  case  OD_NO_SUCH_OBJECT:
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    53
    MSG_WAR(0x2B11,"Index not found ", index);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    54
    break;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    55
  case OD_NO_SUCH_SUBINDEX :
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    56
    MSG_WAR(0x2B12,"SubIndex not found ", subIndex);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    57
    break;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    58
  case OD_WRITE_NOT_ALLOWED :
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    59
    MSG_WAR(0x2B13,"Write not allowed, data is read only ", index);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    60
    break;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    61
  case OD_LENGTH_DATA_INVALID :
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    62
    MSG_WAR(0x2B14,"Conflict size data. Should be (bytes)  : ", sizeDataDict);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    63
    MSG_WAR(0x2B15,"But you have given the size  : ", sizeDataGiven);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    64
    break;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    65
  case OD_NOT_MAPPABLE :
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    66
    MSG_WAR(0x2B16,"Not mappable data in a PDO at index    : ", index);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    67
    break;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    68
  case OD_VALUE_TOO_LOW :
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    69
    MSG_WAR(0x2B17,"Value range error : value too low. SDOabort : ", code);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    70
    break;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    71
  case OD_VALUE_TOO_HIGH :
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    72
    MSG_WAR(0x2B18,"Value range error : value too high. SDOabort : ", code);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    73
    break;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
  default :
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
    MSG_WAR(0x2B20, "Unknown error code : ", code);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
  }
629
b9274b595650 CosateQ contribution.
edouard
parents: 594
diff changeset
    77
  #endif
b9274b595650 CosateQ contribution.
edouard
parents: 594
diff changeset
    78
469
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
    79
  return 0;
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
    80
}
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    81
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    82
UNS32 _getODentry( CO_Data* d,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    83
                   UNS16 wIndex,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    84
                   UNS8 bSubindex,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    85
                   void * pDestData,
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 469
diff changeset
    86
                   UNS32 * pExpectedSize,
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    87
                   UNS8 * pDataType,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    88
                   UNS8 checkAccess,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    89
                   UNS8 endianize)
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
    90
{ /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
    91
    loop if it fails. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
  UNS32 errorCode;
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 469
diff changeset
    93
  UNS32 szData;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
  const indextable *ptrTable;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
  ODCallback_t *Callback;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
  ptrTable = (*d->scanIndexOD)(wIndex, &errorCode, &Callback);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
  if (errorCode != OD_SUCCESSFUL)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
    return errorCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
  if( ptrTable->bSubCount <= bSubindex ) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 55
diff changeset
   102
    /* Subindex not found */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
    accessDictionaryError(wIndex, bSubindex, 0, 0, OD_NO_SUCH_SUBINDEX);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
    return OD_NO_SUCH_SUBINDEX;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
  }
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   106
402
77f875d45250 Fixed faulty read access checking on OD access. Added read acces s checking in SDO (was disabled)
etisserant
parents: 378
diff changeset
   107
  if (checkAccess && (ptrTable->pSubindex[bSubindex].bAccessType & WO)) {
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   108
    MSG_WAR(0x2B30, "Access Type : ", ptrTable->pSubindex[bSubindex].bAccessType);
450
dff8cc600cba Fixed typo in objaccess.c. Thanks to James
etisserant
parents: 437
diff changeset
   109
    accessDictionaryError(wIndex, bSubindex, 0, 0, OD_READ_NOT_ALLOWED);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
    return OD_READ_NOT_ALLOWED;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
666
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   113
  if (pDestData == 0) {
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   114
    return SDOABT_GENERAL_ERROR;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   115
  }
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   116
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   117
  if (ptrTable->pSubindex[bSubindex].size > *pExpectedSize) {
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   118
    /* Requested variable is too large to fit into a transfer line, inform    *
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   119
     * the caller about the real size of the requested variable.              */
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   120
    *pExpectedSize = ptrTable->pSubindex[bSubindex].size;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   121
    return SDOABT_OUT_OF_MEMORY;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   122
  }
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   123
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
  *pDataType = ptrTable->pSubindex[bSubindex].bDataType;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   125
  szData = ptrTable->pSubindex[bSubindex].size;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   126
12
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 11
diff changeset
   127
#  ifdef CANOPEN_BIG_ENDIAN
666
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   128
  if(endianize && *pDataType > boolean && !(
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   129
         *pDataType >= visible_string &&
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   130
         *pDataType <= domain)) {
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   131
    /* data must be transmited with low byte first */
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   132
    UNS8 i, j = 0;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   133
    MSG_WAR(boolean, "data type ", *pDataType);
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   134
    MSG_WAR(visible_string, "data type ", *pDataType);
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   135
    for ( i = szData ; i > 0 ; i--) {
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   136
      MSG_WAR(i," ", j);
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   137
      ((UNS8*)pDestData)[j++] =
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   138
        ((UNS8*)ptrTable->pSubindex[bSubindex].pObject)[i-1];
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   139
    }
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   140
    *pExpectedSize = szData;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   141
  }
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   142
  else /* no endianisation change */
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   143
#  endif
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   144
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   145
  if(*pDataType != visible_string) {
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   146
      memcpy(pDestData, ptrTable->pSubindex[bSubindex].pObject,szData);
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   147
      *pExpectedSize = szData;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   148
  }else{
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   149
      /* TODO : CONFORM TO DS-301 :
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   150
       *  - stop using NULL terminated strings
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   151
       *  - store string size in td_subindex
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   152
       * */
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   153
      /* Copy null terminated string to user, and return discovered size */
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   154
      UNS8 *ptr = (UNS8*)ptrTable->pSubindex[bSubindex].pObject;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   155
      UNS8 *ptr_start = ptr;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   156
      /* *pExpectedSize IS < szData . if null, use szData */
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   157
      UNS8 *ptr_end = ptr + (*pExpectedSize ? *pExpectedSize : szData) ;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   158
      UNS8 *ptr_dest = (UNS8*)pDestData;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   159
      while( *ptr && ptr < ptr_end){
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   160
          *(ptr_dest++) = *(ptr++);
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   161
      }
666
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   162
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   163
    *pExpectedSize = (UNS32) (ptr - ptr_start);
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   164
    /* terminate string if not maximum length */
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   165
    if (*pExpectedSize < szData)
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   166
            *(ptr) = 0;
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   167
  }
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   168
9febdd6fdc71 patch from Stefan Kratochwil <entwicklung@inovel.de> : canfestival-3-fm3_698.patch
fbeaulier
parents: 648
diff changeset
   169
  return OD_SUCCESSFUL;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   170
}
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   171
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   172
UNS32 _setODentry( CO_Data* d,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   173
                   UNS16 wIndex,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   174
                   UNS8 bSubindex,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   175
                   void * pSourceData,
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 469
diff changeset
   176
                   UNS32 * pExpectedSize,
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   177
                   UNS8 checkAccess,
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   178
                   UNS8 endianize)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
{
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 469
diff changeset
   180
  UNS32 szData;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
  UNS8 dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
  UNS32 errorCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
  const indextable *ptrTable;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
  ODCallback_t *Callback;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
  ptrTable =(*d->scanIndexOD)(wIndex, &errorCode, &Callback);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
  if (errorCode != OD_SUCCESSFUL)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
    return errorCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
  if( ptrTable->bSubCount <= bSubindex ) {
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   191
    /* Subindex not found */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
    accessDictionaryError(wIndex, bSubindex, 0, *pExpectedSize, OD_NO_SUCH_SUBINDEX);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
    return OD_NO_SUCH_SUBINDEX;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
  }
1
b3dc740b4b04 Commit some Fix from Francis on sdo.c and abjacces.c. Fix endianisation problems while accessing OD. Also fix SDO abord handling bug.
etisserant
parents: 0
diff changeset
   195
  if (checkAccess && (ptrTable->pSubindex[bSubindex].bAccessType == RO)) {
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   196
    MSG_WAR(0x2B25, "Access Type : ", ptrTable->pSubindex[bSubindex].bAccessType);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
    accessDictionaryError(wIndex, bSubindex, 0, *pExpectedSize, OD_WRITE_NOT_ALLOWED);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
    return OD_WRITE_NOT_ALLOWED;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   202
  dataType = ptrTable->pSubindex[bSubindex].bDataType;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   203
  szData = ptrTable->pSubindex[bSubindex].size;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
  if( *pExpectedSize == 0 ||
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   206
      *pExpectedSize == szData ||
421
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   207
      /* allow to store a shorter string than entry size */
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   208
      (dataType == visible_string && *pExpectedSize < szData))
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   209
    {
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   210
#ifdef CANOPEN_BIG_ENDIAN
421
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   211
      /* re-endianize do not occur for bool, strings time and domains */
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   212
      if(endianize && dataType > boolean && !(
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   213
            dataType >= visible_string && 
431
166037b8f2ed Fixed typo in objacces.c bigendian side.
etisserant
parents: 430
diff changeset
   214
            dataType <= domain))
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   215
        {
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   216
          /* we invert the data source directly. This let us do range
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   217
            testing without */
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   218
          /* additional temp variable */
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   219
          UNS8 i;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   220
          for ( i = 0 ; i < ( ptrTable->pSubindex[bSubindex].size >> 1)  ; i++)
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   221
            {
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   222
              UNS8 tmp =((UNS8 *)pSourceData) [(ptrTable->pSubindex[bSubindex].size - 1) - i];
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   223
              ((UNS8 *)pSourceData) [(ptrTable->pSubindex[bSubindex].size - 1) - i] = ((UNS8 *)pSourceData)[i];
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   224
              ((UNS8 *)pSourceData)[i] = tmp;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   225
            }
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   226
        }
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   227
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
      errorCode = (*d->valueRangeTest)(dataType, pSourceData);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
      if (errorCode) {
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   230
        accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, errorCode);
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   231
        return errorCode;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
      }
2
8d4a822f95e4 Fixed Endianisation/ValueRange order in SetODentry
etisserant
parents: 1
diff changeset
   233
      memcpy(ptrTable->pSubindex[bSubindex].pObject,pSourceData, *pExpectedSize);
421
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   234
     /* TODO : CONFORM TO DS-301 : 
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   235
      *  - stop using NULL terminated strings
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   236
      *  - store string size in td_subindex 
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   237
      * */
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   238
      /* terminate visible_string with '\0' */
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   239
      if(dataType == visible_string && *pExpectedSize < szData)
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   240
        ((UNS8*)ptrTable->pSubindex[bSubindex].pObject)[*pExpectedSize] = 0;
6221b4db8c42 Added support for null terminated strings as VISIBLE_STRING.
etisserant
parents: 419
diff changeset
   241
      
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
      *pExpectedSize = szData;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   243
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   244
      /* Callbacks */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
      if(Callback && Callback[bSubindex]){
437
129bbe0504e4 Now OD callback return val ahev influance on SDO transmission (if callback fall, SDO abord may be signaled)
etisserant
parents: 431
diff changeset
   246
        errorCode = (Callback[bSubindex])(d, ptrTable, bSubindex);
129bbe0504e4 Now OD callback return val ahev influance on SDO transmission (if callback fall, SDO abord may be signaled)
etisserant
parents: 431
diff changeset
   247
        if(errorCode != OD_SUCCESSFUL)
129bbe0504e4 Now OD callback return val ahev influance on SDO transmission (if callback fall, SDO abord may be signaled)
etisserant
parents: 431
diff changeset
   248
        {
129bbe0504e4 Now OD callback return val ahev influance on SDO transmission (if callback fall, SDO abord may be signaled)
etisserant
parents: 431
diff changeset
   249
            return errorCode;
129bbe0504e4 Now OD callback return val ahev influance on SDO transmission (if callback fall, SDO abord may be signaled)
etisserant
parents: 431
diff changeset
   250
        }
129bbe0504e4 Now OD callback return val ahev influance on SDO transmission (if callback fall, SDO abord may be signaled)
etisserant
parents: 431
diff changeset
   251
       }
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   252
215
f49e5a6b7804 Manual and Documentation finish
nico
parents: 208
diff changeset
   253
      /* TODO : Store dans NVRAM */
161
c4908cc776a9 SetODEntry now call CO_data->storeODSubEntry(Index,SubIndex) for variables to be Stored (when column Save==True in GUI)
etisserant
parents: 75
diff changeset
   254
      if (ptrTable->pSubindex[bSubindex].bAccessType & TO_BE_SAVE){
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 215
diff changeset
   255
        (*d->storeODSubIndex)(d, wIndex, bSubindex);
161
c4908cc776a9 SetODEntry now call CO_data->storeODSubEntry(Index,SubIndex) for variables to be Stored (when column Save==True in GUI)
etisserant
parents: 75
diff changeset
   256
      }
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
      return OD_SUCCESSFUL;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   258
    }else{
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   259
      *pExpectedSize = szData;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
      accessDictionaryError(wIndex, bSubindex, szData, *pExpectedSize, OD_LENGTH_DATA_INVALID);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
      return OD_LENGTH_DATA_INVALID;
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   262
    }
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   263
}
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   264
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
const indextable * scanIndexOD (CO_Data* d, UNS16 wIndex, UNS32 *errorCode, ODCallback_t **Callback)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
  return (*d->scanIndexOD)(wIndex, errorCode, Callback);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
UNS32 RegisterSetODentryCallBack(CO_Data* d, UNS16 wIndex, UNS8 bSubindex, ODCallback_t Callback)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
{
469
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
   272
UNS32 errorCode;
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
   273
ODCallback_t *CallbackList;
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
   274
const indextable *odentry;
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
   275
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
   276
  odentry = scanIndexOD (d, wIndex, &errorCode, &CallbackList);
f2b07ea215b5 Applied edward's patch for OD acces macros (optimization) and boudaries check (safety).
etisserant
parents: 450
diff changeset
   277
  if(errorCode == OD_SUCCESSFUL  &&  CallbackList  &&  bSubindex < odentry->bSubCount) 
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   278
    CallbackList[bSubindex] = Callback;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   279
  return errorCode;
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   280
}
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 175
diff changeset
   281
378
d2abf6c8c27b As requested long ago, added CoData* parameter to all this applications callback, let application designer use identical callback for multiple nodes, and reduce source code length.
etisserant
parents: 215
diff changeset
   282
void _storeODSubIndex (CO_Data* d, UNS16 wIndex, UNS8 bSubindex){}