src/sdo.c
author etisserant
Sun, 15 Apr 2007 00:49:34 +0200
changeset 161 c4908cc776a9
parent 154 1b3165f2d17d
child 163 212a9ea3b968
permissions -rw-r--r--
SetODEntry now call CO_data->storeODSubEntry(Index,SubIndex) for variables to be Stored (when column Save==True in GUI)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
84
19def60bd29c forgot some comments ...
frdupin
parents: 82
diff changeset
    23
/* #define DEBUG_WAR_CONSOLE_ON */
19def60bd29c forgot some comments ...
frdupin
parents: 82
diff changeset
    24
/* #define DEBUG_ERR_CONSOLE_ON */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
#include "objacces.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
#include "sdo.h"
149
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
    28
#include "canfestival.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    30
/* Uncomment if your compiler does not support inline functions */
86
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
    31
#define NO_INLINE 
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    32
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    33
#ifdef NO_INLINE
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    34
  #define INLINE 
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    35
#else
86
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
    36
  #define INLINE inline
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    37
#endif
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    38
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    39
/*Internals prototypes*/
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    40
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    41
/** Called by writeNetworkDict */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    42
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, 
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    43
		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback);
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    44
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    45
/** Called by readNetworkDict */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    46
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, 
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    47
	UNS8 dataType, SDOCallback_t Callback);
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    48
	
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    49
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
/***************************************************************************/
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    51
/* SDO (un)packing macros */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
/** Returns the command specifier (cs, ccs, scs) from the first byte of the SDO   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
#define getSDOcs(byte) (byte >> 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 2 bits   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
#define getSDOn2(byte) ((byte >> 2) & 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 3 bits   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
#define getSDOn3(byte) ((byte >> 1) & 7)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
/** Returns the transfer type from the first byte of the SDO   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
#define getSDOe(byte) ((byte >> 1) & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
/** Returns the size indicator from the first byte of the SDO   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
#define getSDOs(byte) (byte & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
/** Returns the indicator of end transmission from the first byte of the SDO   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
#define getSDOc(byte) (byte & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
/** Returns the toggle from the first byte of the SDO   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
#define getSDOt(byte) ((byte >> 4) & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
/** Returns the index from the bytes 1 and 2 of the SDO   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
#define getSDOindex(byte1, byte2) ((byte2 << 8) | (byte1))
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
/** Returns the subIndex from the byte 3 of the SDO   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
 */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    87
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
#define getSDOsubIndex(byte3) (byte3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    90
/***************************************************************************
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    91
**
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
void SDOTimeoutAlarm(CO_Data* d, UNS32 id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
    MSG_ERR(0x1A01, "SDO timeout. SDO response not received.", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
    MSG_WAR(0x2A02, "server node : ", d->transfers[id].nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
    MSG_WAR(0x2A02, "      index : ", d->transfers[id].index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
    MSG_WAR(0x2A02, "   subIndex : ", d->transfers[id].subIndex); 
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    99
    /* Reset timer handler */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
    d->transfers[id].timer = TIMER_NONE;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   101
    /* Call the user function to inform of the problem.*/
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 87
diff changeset
   102
    (*d->SDOtimeoutError)((UNS8)id);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   103
    /* Sending a SDO abort */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
    sendSDOabort(d, d->transfers[id].whoami, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
		 d->transfers[id].index, d->transfers[id].subIndex, SDOABT_TIMED_OUT);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   106
    /* Reset the line*/
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 87
diff changeset
   107
    resetSDOline(d, (UNS8)id);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
#define StopSDO_TIMER(id) \
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
MSG_WAR(0x3A05, "StopSDO_TIMER for line : ", line);\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
d->transfers[id].timer = DelAlarm(d->transfers[id].timer);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
#define StartSDO_TIMER(id) \
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
MSG_WAR(0x3A06, "StartSDO_TIMER for line : ", line);\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
d->transfers[id].timer = SetAlarm(d,id,&SDOTimeoutAlarm,MS_TO_TIMEVAL(SDO_TIMEOUT_MS),0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
#define RestartSDO_TIMER(id) \
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
MSG_WAR(0x3A07, "restartSDO_TIMER for line : ", line);\
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
if(d->transfers[id].timer != TIMER_NONE) { StopSDO_TIMER(id) StartSDO_TIMER(id) }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   122
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
/** Reset all sdo buffers
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
 */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
void resetSDO (CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
  UNS8 j;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   128
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
  /* transfer structure initialization */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
    for (j = 0 ; j < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; j++) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
      resetSDOline(d, j);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   137
  UNS8      size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
  UNS32 errorCode;
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
   139
  MSG_WAR(0x3A08, "Enter in SDOlineToObjdict ", line);
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 87
diff changeset
   140
  size = (UNS8)d->transfers[line].count;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
  errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
			 (void *) d->transfers[line].data, &size, 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
  if (errorCode != OD_SUCCESSFUL)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   144
    return errorCode;
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
   145
  MSG_WAR(0x3A08, "exit of SDOlineToObjdict ", line);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
UNS32 objdictToSDOline (CO_Data* d, UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
  UNS8  size = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
  UNS8  dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
  UNS32 errorCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
12
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   157
  MSG_WAR(0x3A05, "objdict->line index : ", d->transfers[line].index);
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   158
  MSG_WAR(0x3A06, "  subIndex : ", d->transfers[line].subIndex);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   159
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
  errorCode = getODentry(d, 	d->transfers[line].index,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
  				d->transfers[line].subIndex,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
  				(void *)d->transfers[line].data,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
  				&size, &dataType, 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
  if (errorCode != OD_SUCCESSFUL)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
    return errorCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
  d->transfers[line].count = size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
  d->transfers[line].offset = 0;
12
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   170
#if 0
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   171
   /*Me laisser ça, please ! (FD)*/
12
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   172
  {
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   173
    UNS8 i;
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   174
    for (i = 0 ; i < 10 ; i++) {
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   175
      MSG_WAR(i, "data= ", d->transfers[line].data[i]);
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   176
    }     
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   177
  }
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   178
#endif
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
  UNS8 offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   186
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
  if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   188
    MSG_ERR(0x1A10,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   189
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   190
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   191
    if ((d->transfers[line].offset + nbBytes) > d->transfers[line].count) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
    MSG_ERR(0x1A11,"SDO Size of data too large. Exceed count", nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   193
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
  }
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 87
diff changeset
   195
  offset = (UNS8)d->transfers[line].offset;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
  for (i = 0 ; i < nbBytes ; i++) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
    * (data + i) = d->transfers[line].data[offset + i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
  d->transfers[line].offset = d->transfers[line].offset + nbBytes;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS8 nbBytes, UNS8* data)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
  UNS8 offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   208
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
  if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
    MSG_ERR(0x1A15,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
  }
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 87
diff changeset
   213
  offset = (UNS8)d->transfers[line].offset;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
  for (i = 0 ; i < nbBytes ; i++) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
    d->transfers[line].data[offset + i] = * (data + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
  d->transfers[line].offset = d->transfers[line].offset + nbBytes;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   219
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   220
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
UNS8 failedSDO (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS16 index, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
		UNS8 subIndex, UNS32 abortCode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
  UNS8 line;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
  err = getSDOlineOnUse( d, nodeId, whoami, &line );
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   227
  if (!err) /* If a line on use have been found.*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
    MSG_WAR(0x3A20, "FailedSDO : line found : ", line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
  if ((! err) && (whoami == SDO_SERVER)) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
    resetSDOline( d, line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
    MSG_WAR(0x3A21, "FailedSDO : line released : ", line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   232
  }
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
   233
  if ((! err) && (whoami == SDO_CLIENT)) {
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
   234
    StopSDO_TIMER(line);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
    d->transfers[line].state = SDO_ABORTED_INTERNAL;
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
   236
  }
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
  MSG_WAR(0x3A22, "Sending SDO abort ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
  err = sendSDOabort(d, whoami, index, subIndex, abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
    MSG_WAR(0x3A23, "Unable to send the SDO abort", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
void resetSDOline ( CO_Data* d, UNS8 line )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
  UNS8 i; 
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
   250
  MSG_WAR(0x3A25, "reset SDO line nb : ", line); 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
  initSDOline(d, line, 0, 0, 0, SDO_RESET);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
  for (i = 0 ; i < SDO_MAX_LENGTH_TRANSFERT ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
    d->transfers[line].data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
UNS8 initSDOline (CO_Data* d, UNS8 line, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 state)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
{
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
   259
  MSG_WAR(0x3A25, "init SDO line nb : ", line); 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   260
  if (state == SDO_DOWNLOAD_IN_PROGRESS || state == SDO_UPLOAD_IN_PROGRESS){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   261
  	StartSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   262
  }else{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
  	StopSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
  d->transfers[line].nodeId = nodeId; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
  d->transfers[line].index = index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
  d->transfers[line].subIndex = subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
  d->transfers[line].state = state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
  d->transfers[line].toggle = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
  d->transfers[line].count = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
  d->transfers[line].offset = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
  d->transfers[line].dataType = 0;
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   273
  d->transfers[line].Callback = NULL;  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
UNS8 getSDOfreeLine ( CO_Data* d, UNS8 whoami, UNS8 *line )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   280
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   283
  for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
    if ( d->transfers[i].state == SDO_RESET ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
      *line = i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
      d->transfers[i].whoami = whoami;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
      return 0;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   288
    } /* end if */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   289
  } /* end for */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   290
  MSG_ERR(0x1A25, "Too many SDO in progress. Aborted.", i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   291
  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
UNS8 getSDOlineOnUse (CO_Data* d, UNS8 nodeId, UNS8 whoami, UNS8 *line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
  for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
    if ( (d->transfers[i].state != SDO_RESET) &&
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
	 (d->transfers[i].nodeId == nodeId) && 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
	 (d->transfers[i].whoami == whoami) ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
      *line = i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
      return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
  } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
UNS8 closeSDOtransfer (CO_Data* d, UNS8 nodeId, UNS8 whoami)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
  UNS8 line;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
  err = getSDOlineOnUse(d, nodeId, whoami, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
    MSG_WAR(0x2A30, "No SDO communication to close for node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
  resetSDOline(d, line);  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   326
UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 * nbBytes)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
{
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   328
  if (d->transfers[line].count == 0) /* if received initiate SDO protocol with e=0 and s=0 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
    * nbBytes = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
  else
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 87
diff changeset
   331
    * nbBytes = (UNS8)d->transfers[line].count - (UNS8)d->transfers[line].offset;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS8 nbBytes)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   338
  if (nbBytes > SDO_MAX_LENGTH_TRANSFERT) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
    MSG_ERR(0x1A35,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
  d->transfers[line].count = nbBytes;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
UNS8 sendSDO (CO_Data* d, UNS8 whoami, s_SDO sdo)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
{	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
  UNS16 offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
  UNS16 lastIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
  UNS8 found = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   353
  Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   354
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
  UNS32 * pwCobId = NULL;
87
074126d73842 little/big endian and nodeId
frdupin
parents: 86
diff changeset
   356
  UNS32 * pwNodeId = NULL;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   357
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   358
  MSG_WAR(0x3A38, "sendSDO",0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   359
  if( !((d->nodeState == Operational) ||  (d->nodeState == Pre_operational ))) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
    MSG_WAR(0x2A39, "unable to send the SDO (not in op or pre-op mode", d->nodeState);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
  }  				
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
  /*get the server->client cobid*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
  if ( whoami == SDO_SERVER )	{/*case server. Easy because today only one server SDO is authorized in CanFestival*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
    offset = d->firstIndex->SDO_SVR;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   367
    if (offset == 0) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   368
      MSG_ERR(0x1A42, "SendSDO : No SDO server found", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
      return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
    pwCobId = d->objdict[offset].pSubindex[2].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   372
    MSG_WAR(0x3A41, "I am server. cobId : ", *pwCobId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   374
  else {			/*case client*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
    /* Get the client->server cobid.*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
    UNS16 sdoNum = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
    offset = d->firstIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
    lastIndex = d->lastIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
    if (offset == 0) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
      MSG_ERR(0x1A42, "SendSDO : No SDO client index found", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
      return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   382
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
    /* First, have to find at the index where is defined the communication with the server node */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
    while (offset <= lastIndex){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
      MSG_WAR(0x3A43,"Reading index : ", 0x1280 + sdoNum);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
      if (d->objdict[offset].bSubCount <= 3) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
	MSG_ERR(0x1A28, "Subindex 3  not found at index ", 0x1280 + sdoNum);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
      pwNodeId = d->objdict[offset].pSubindex[3].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
      MSG_WAR(0x3A44, "Found nodeId server = ", *pwNodeId);	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
      if(*pwNodeId == sdo.nodeId) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
	found = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
	break;          
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
      }      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
      offset ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
      sdoNum ++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   398
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
    if (! found){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
      MSG_WAR (0x2A45, "No SDO client corresponds to the mesage to send to node ", sdo.nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
      return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
    /* Second, read the cobid client->server */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
    pwCobId = d->objdict[offset].pSubindex[1].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
  /* message copy for sending */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   407
  m.cob_id.w = *pwCobId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
  m.rtr = NOT_A_REQUEST; 
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   409
  /* the length of SDO must be 8 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
  m.len = 8;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
  for (i = 0 ; i < 8 ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
    m.data[i] =  sdo.body.data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
  }
149
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
   414
  return canSend(d->canHandle,&m);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   418
UNS8 sendSDOabort (CO_Data* d, UNS8 whoami, UNS16 index, UNS8 subIndex, UNS32 abortCode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
  s_SDO sdo;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   421
  UNS8 ret;
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
   422
  MSG_WAR(0x2A50,"Sending SDO abort ", abortCode);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
  sdo.nodeId = *d->bDeviceNodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
  sdo.body.data[0] = 0x80;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   425
  /* Index */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   426
  sdo.body.data[1] = index & 0xFF; /* LSB */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   427
  sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   428
  /* Subindex */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
  sdo.body.data[3] = subIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   430
  /* Data */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
  sdo.body.data[4] = (UNS8)(abortCode & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
  sdo.body.data[5] = (UNS8)((abortCode >> 8) & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
  sdo.body.data[6] = (UNS8)((abortCode >> 16) & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
  sdo.body.data[7] = (UNS8)((abortCode >> 24) & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
  ret = sendSDO(d, whoami, sdo);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
  return ret;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   440
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
UNS8 proceedSDO (CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   442
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
  UNS8 line;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   445
  UNS8 nbBytes; /* received or to be transmited. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   446
  UNS8 nodeId = 0;  /* The node from which the SDO is received */
87
074126d73842 little/big endian and nodeId
frdupin
parents: 86
diff changeset
   447
  UNS32 nodeId_32; /* node id in 32 bits, for temporary use */
074126d73842 little/big endian and nodeId
frdupin
parents: 86
diff changeset
   448
  UNS32 *pNodeId = NULL;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   449
  UNS8 whoami = SDO_UNKNOWN;  /* SDO_SERVER or SDO_CLIENT.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   450
  UNS32 errorCode; /* while reading or writing in the local object dictionary.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   451
  s_SDO sdo;    /* SDO to transmit */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
  UNS16 index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
  UNS8 subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
  UNS32 abortCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
  UNS8 i,j;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   456
  UNS32 *     pCobId = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   457
  UNS16 offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   458
  UNS16 lastIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   459
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   460
  MSG_WAR(0x3A60, "proceedSDO ", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   461
  whoami = SDO_UNKNOWN;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   462
  /* Looking for the cobId in the object dictionary. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   463
  /* Am-I a server ? */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   464
  offset = d->firstIndex->SDO_SVR;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   465
  lastIndex = d->lastIndex->SDO_SVR;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   466
  j = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   467
  if(offset) while (offset <= lastIndex) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   468
     if (d->objdict[offset].bSubCount <= 1) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   469
	  MSG_ERR(0x1A61, "Subindex 1  not found at index ", 0x1200 + j);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   470
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   471
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   472
      pCobId = d->objdict[offset].pSubindex[1].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   473
      if ( *pCobId == (*m).cob_id.w ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   474
	whoami = SDO_SERVER;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   475
	MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   476
	/* In case of server, the node id of the client may be unknown. So we put the index minus offset */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   477
	/* 0x1200 where the cobid received is defined. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   478
	nodeId = j;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   479
	break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   480
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   481
      j++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   482
      offset++;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   483
  } /* end while */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   484
  if (whoami == SDO_UNKNOWN) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   485
    /* Am-I client ? */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   486
    offset = d->firstIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   487
    lastIndex = d->lastIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   488
    j = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   489
    if(offset) while (offset <= lastIndex) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   490
       if (d->objdict[offset].bSubCount <= 3) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   491
	 MSG_ERR(0x1A63, "Subindex 3  not found at index ", 0x1280 + j);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   492
	 return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
       }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   494
       /* a) Looking for the cobid received. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   495
       pCobId = d->objdict[offset].pSubindex[2].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   496
       if (*pCobId == (*m).cob_id.w ) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   497
	 /* b) cobid found, so reading the node id of the server. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   498
	 pNodeId = d->objdict[offset].pSubindex[3].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   499
	 whoami = SDO_CLIENT;
87
074126d73842 little/big endian and nodeId
frdupin
parents: 86
diff changeset
   500
	 nodeId_32 = *pNodeId;
074126d73842 little/big endian and nodeId
frdupin
parents: 86
diff changeset
   501
	 nodeId = (UNS8)nodeId_32;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   502
	 MSG_WAR(0x3A64, "proceedSDO. I am server. index : ", 0x1280 + j);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   503
	 MSG_WAR(0x3A65, "                 Server nodeId : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   504
	 break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   505
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   506
       j++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   507
       offset++;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   508
    } /* end while */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   509
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   510
  if (whoami == SDO_UNKNOWN) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   511
    return 0xFF;/* This SDO was not for us ! */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   512
  }
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   513
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   514
  /* Test if the size of the SDO is ok */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   515
  if ( (*m).len != 8) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   516
    MSG_ERR(0x1A67, "Error size SDO. CobId  : ", (*m).cob_id.w);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   517
    failedSDO(d, nodeId, whoami, 0, 0, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   518
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   519
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   520
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   521
  if (whoami == SDO_CLIENT) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   522
    MSG_WAR(0x3A68, "I am CLIENT. Received SDO from nodeId : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   523
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   524
  else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   525
    MSG_WAR(0x3A69, "I am SERVER. Received SDO cobId : ", (*m).cob_id.w);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   526
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   527
    
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   528
  /* Testing the command specifier */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   529
  /* Allowed : cs = 0, 1, 2, 3, 4. (=  all except those for block tranfert). */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   530
  /* cs = other : Not allowed -> abort. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   531
  switch (getSDOcs(m->data[0])) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   532
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   533
  case 0:
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   534
    /* I am SERVER */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   535
    if (whoami == SDO_SERVER) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   536
      /* Receiving a download segment data. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   537
      /* A SDO transfert should have been yet initiated. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   538
      err = getSDOlineOnUse( d, nodeId, whoami, &line ); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   539
      if (!err)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   540
	err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   541
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   542
	MSG_ERR(0x1A70, "SDO error : Received download segment for unstarted trans. index 0x1200 + ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   543
		nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   544
	failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   545
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   546
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   547
      /* Reset the wathdog */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   548
      RestartSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   549
      MSG_WAR(0x3A71, "Received SDO download segment defined at index 0x1200 + ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   550
      index = d->transfers[line].index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   551
      subIndex = d->transfers[line].subIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   552
      /* Toggle test. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   553
      if (d->transfers[line].toggle != getSDOt(m->data[0])) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   554
	MSG_ERR(0x1A72, "SDO error : Toggle error : ", getSDOt(m->data[0])); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   555
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   556
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   557
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   558
      /* Nb of data to be downloaded */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   559
      nbBytes = 7 - getSDOn3(m->data[0]);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   560
      /* Store the data in the transfert structure. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   561
      err = SDOtoLine(d, line, nbBytes, (*m).data + 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   562
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   563
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   564
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   565
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   566
      /* Sending the SDO response, CS = 1 */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   567
      sdo.nodeId = *d->bDeviceNodeId; /* The node id of the server, (here it is the sender). */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   568
      sdo.body.data[0] = (1 << 5) | (d->transfers[line].toggle << 4);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   569
      for (i = 1 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   570
	sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   571
      MSG_WAR(0x3A73, "SDO. Send response to download request defined at index 0x1200 + ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   572
      sendSDO(d, whoami, sdo);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   573
      /* Inverting the toggle for the next segment. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   574
      d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   575
      /* If it was the last segment, */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   576
      if (getSDOc(m->data[0])) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   577
	/* Transfering line data to object dictionary. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   578
	/* The code does not use the "d" of initiate frame. So it is safe if e=s=0 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   579
	errorCode = SDOlineToObjdict(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   580
	if (errorCode) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   581
	  MSG_ERR(0x1A54, "SDO error : Unable to copy the data in the object dictionary", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   582
	  failedSDO(d, nodeId, whoami, index, subIndex, errorCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   583
	  return 0xFF;	  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   584
	}
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   585
	/* Release of the line */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   586
	resetSDOline(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   587
	MSG_WAR(0x3A74, "SDO. End of download defined at index 0x1200 + ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   588
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   589
    } /* end if SERVER */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   590
    else { /* if CLIENT */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   591
      /* I am CLIENT */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   592
      /* It is a request for a previous upload segment. We should find a line opened for this.*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   593
      err = getSDOlineOnUse( d, nodeId, whoami, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   594
      if (!err)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
	err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   596
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   597
	MSG_ERR(0x1A75, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   598
	failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   599
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   600
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   601
      /* Reset the wathdog */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   602
      RestartSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   603
      index = d->transfers[line].index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   604
      subIndex = d->transfers[line].subIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   605
      /* test of the toggle; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   606
      if (d->transfers[line].toggle != getSDOt(m->data[0])) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   607
	MSG_ERR(0x1A76, "SDO error : Received segment response Toggle error. from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   608
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   609
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   610
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   611
      /* nb of data to be uploaded */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   612
      nbBytes = 7 - getSDOn3(m->data[0]);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   613
      /* Storing the data in the line structure. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
      err = SDOtoLine(d, line, nbBytes, (*m).data + 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   615
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   616
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   617
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   618
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   619
      /* Inverting the toggle for the next segment. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   620
      d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   621
      /* If it was the last segment,*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   622
      if ( getSDOc(m->data[0])) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   623
	/* Put in state finished */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   624
	/* The code is safe for the case e=s=0 in initiate frame. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   625
	StopSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   626
	d->transfers[line].state = SDO_FINISHED;
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   627
	if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   628
	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   629
	MSG_WAR(0x3A77, "SDO. End of upload from node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   630
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   631
      else { /* more segments to receive */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   632
	     /* Sending the request for the next segment. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   633
	sdo.nodeId = nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   634
	sdo.body.data[0] = (3 << 5) | (d->transfers[line].toggle << 4);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   635
	for (i = 1 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   636
	  sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   637
	sendSDO(d, whoami, sdo);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   638
	MSG_WAR(0x3A78, "SDO send upload segment request to nodeId", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   639
      }            
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   640
    } /* End if CLIENT */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   641
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   642
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   643
  case 1:
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   644
    /* I am SERVER */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   645
    /* Receive of an initiate download */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   646
    if (whoami == SDO_SERVER) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   647
      index = getSDOindex(m->data[1],m->data[2]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   648
      subIndex = getSDOsubIndex(m->data[3]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   649
      MSG_WAR(0x3A79, "Received SDO Initiate Download (to store data) defined at index 0x1200 + ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   650
	      nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   651
      MSG_WAR(0x3A80, "Writing at index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   652
      MSG_WAR(0x3A80, "Writing at subIndex : ", subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   653
      
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   654
      /* Search if a SDO transfert have been yet initiated */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   655
      err = getSDOlineOnUse( d, nodeId, whoami, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   656
      if (! err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   657
	MSG_ERR(0x1A81, "SDO error : Transmission yet started.", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   658
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   659
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   660
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   661
      /* No line on use. Great ! */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   662
      /* Try to open a new line. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   663
      err = getSDOfreeLine( d, whoami, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   664
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   665
	MSG_ERR(0x1A82, "SDO error : No line free, too many SDO in progress. Aborted.", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   666
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   667
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   668
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   669
      initSDOline(d, line, nodeId, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS);      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   670
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   671
      if (getSDOe(m->data[0])) { /* If SDO expedited */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   672
	/* nb of data to be downloaded */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   673
	nbBytes = 4 - getSDOn2(m->data[0]);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   674
	/* Storing the data in the line structure. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   675
	d->transfers[line].count = nbBytes;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   676
	err = SDOtoLine(d, line, nbBytes, (*m).data + 4);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   677
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   678
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   679
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   680
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   681
	}	  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   682
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   683
	/* SDO expedited -> transfert finished. Data can be stored in the dictionary. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   684
	/* The line will be reseted when it is downloading in the dictionary. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   685
	MSG_WAR(0x3A83, "SDO Initiate Download is an expedited transfert. Finished.: ", nodeId);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   686
	/* Transfering line data to object dictionary. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   687
	errorCode = SDOlineToObjdict(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   688
	if (errorCode) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   689
	  MSG_ERR(0x1A84, "SDO error : Unable to copy the data in the object dictionary", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   690
	  failedSDO(d, nodeId, whoami, index, subIndex, errorCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   691
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   692
	}
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   693
	/* Release of the line. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   694
	resetSDOline(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   695
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   696
      else {/* So, if it is not an expedited transfert */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   697
	if (getSDOs(m->data[0])) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   698
	  /* TODO : if e and s = 0, not reading m->data[4] but put nbBytes = 0 */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   699
	  nbBytes = m->data[4]; /* Transfert limited to 255 bytes. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   700
	  err = setSDOlineRestBytes(d, nodeId, nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   701
	  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   702
	    failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   703
	    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   704
	  }	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   705
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   706
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   707
      /*Sending a SDO, cs=3*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   708
      sdo.nodeId = *d->bDeviceNodeId; /* The node id of the server, (here it is the sender).*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   709
      sdo.body.data[0] = 3 << 5;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   710
      sdo.body.data[1] = index & 0xFF;        /* LSB */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   711
      sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   712
      sdo.body.data[3] = subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   713
      for (i = 4 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   714
		sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   715
      sendSDO(d, whoami, sdo);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   716
    } /* end if I am SERVER */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   717
    else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   718
      /* I am CLIENT */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   719
      /* It is a response for a previous download segment. We should find a line opened for this. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
      err = getSDOlineOnUse( d, nodeId, whoami, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   721
      if (!err)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   722
	err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   723
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   724
	MSG_ERR(0x1A85, "SDO error : Received segment response for unknown trans. from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   725
	failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   726
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   727
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   728
      /* Reset the wathdog */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   729
      RestartSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   730
      index = d->transfers[line].index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   731
      subIndex = d->transfers[line].subIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   732
      /* test of the toggle; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   733
      if (d->transfers[line].toggle != getSDOt(m->data[0])) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   734
	MSG_ERR(0x1A86, "SDO error : Received segment response Toggle error. from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   735
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   736
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   737
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   738
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   739
      /* End transmission or downloading next segment. We need to know if it will be the last one. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   740
      getSDOlineRestBytes(d, line, &nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   741
      if (nbBytes == 0) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   742
	MSG_WAR(0x3A87, "SDO End download. segment response received. OK. from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   743
	StopSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   744
	d->transfers[line].state = SDO_FINISHED;
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   745
	if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   746
	return 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   747
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   748
      /* At least one transfer to send.	*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   749
      if (nbBytes > 7) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   750
	/* several segments to download.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   751
	/* code to send the next segment. (cs = 0; c = 0) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   752
	d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   753
	sdo.nodeId = nodeId; /* The server node Id; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   754
	sdo.body.data[0] = (d->transfers[line].toggle << 4);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   755
	err = lineToSDO(d, line, 7, sdo.body.data + 1);	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   756
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   757
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   758
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   759
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   760
      } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   761
      else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   762
	/* Last segment. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   763
	/* code to send the last segment. (cs = 0; c = 1)*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   764
	d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   765
	sdo.nodeId = nodeId; /* The server node Id; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   766
	sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   767
	err = lineToSDO(d, line, nbBytes, sdo.body.data + 1);	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   768
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   769
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   770
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   771
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   772
	for (i = nbBytes + 1 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   773
	  sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   774
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   775
      MSG_WAR(0x3A88, "SDO sending download segment to nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   776
      sendSDO(d, whoami, sdo); 
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   777
    } /* end if I am a CLIENT */			  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   778
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   779
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   780
  case 2:
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   781
    /* I am SERVER */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   782
    /* Receive of an initiate upload.*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   783
    if (whoami == SDO_SERVER) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   784
      index = getSDOindex(m->data[1],m->data[2]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   785
      subIndex = getSDOsubIndex(m->data[3]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   786
      MSG_WAR(0x3A89, "Received SDO Initiate upload (to send data) defined at index 0x1200 + ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   787
	      nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   788
      MSG_WAR(0x3A90, "Reading at index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   789
      MSG_WAR(0x3A91, "Reading at subIndex : ", subIndex);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   790
      /* Search if a SDO transfert have been yet initiated*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   791
      err = getSDOlineOnUse( d, nodeId, whoami, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   792
      if (! err) {
12
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   793
	    MSG_ERR(0x1A92, "SDO error : Transmission yet started at line : ", line); 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   794
        MSG_WAR(0x3A93, "nodeId = ", nodeId); 
12
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   795
	    failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
1d3b9ad366c8 CANOPEN_BIG_ENDIAN :
dejoigny
parents: 6
diff changeset
   796
	    return 0xFF;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   797
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   798
      /* No line on use. Great !*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   799
      /* Try to open a new line.*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   800
      err = getSDOfreeLine( d, whoami, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   801
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   802
	MSG_ERR(0x1A71, "SDO error : No line free, too many SDO in progress. Aborted.", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   803
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   804
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   805
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   806
      initSDOline(d, line, nodeId, index, subIndex, SDO_UPLOAD_IN_PROGRESS);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   807
      /* Transfer data from dictionary to the line structure. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   808
      errorCode = objdictToSDOline(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   809
     
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   810
      if (errorCode) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   811
	MSG_ERR(0x1A94, "SDO error : Unable to copy the data from object dictionary. Err code : ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   812
		errorCode); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   813
	failedSDO(d, nodeId, whoami, index, subIndex, errorCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   814
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   815
	}
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   816
      /* Preparing the response.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   817
      getSDOlineRestBytes(d, line, &nbBytes);	/* Nb bytes to transfer ? */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   818
      sdo.nodeId = nodeId; /* The server node Id; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   819
      if (nbBytes > 4) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   820
	/* normal transfert. (segmented). */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   821
	/* code to send the initiate upload response. (cs = 2) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   822
	sdo.body.data[0] = (2 << 5) | 1;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   823
	sdo.body.data[1] = index & 0xFF;        /* LSB */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   824
	sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   825
	sdo.body.data[3] = subIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   826
        sdo.body.data[4] = nbBytes; /* Limitation of canfestival2 : Max tranfert is 256 bytes.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   827
	/* It takes too much memory to upgrate to 2^32 because the size of data is also coded */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   828
	/* in the object dictionary, at every index and subindex. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   829
	for (i = 5 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   830
	  sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   831
	MSG_WAR(0x3A95, "SDO. Sending normal upload initiate response defined at index 0x1200 + ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   832
	sendSDO(d, whoami, sdo); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   833
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   834
      else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   835
	/* Expedited upload. (cs = 2 ; e = 1) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   836
	sdo.body.data[0] = (2 << 5) | ((4 - nbBytes) << 2) | 3;  
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   837
	sdo.body.data[1] = index & 0xFF;        /* LSB */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   838
	sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   839
	sdo.body.data[3] = subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   840
	err = lineToSDO(d, line, nbBytes, sdo.body.data + 4);	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   841
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   842
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   843
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   844
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   845
	for (i = 4 + nbBytes ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   846
	  sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   847
	MSG_WAR(0x3A96, "SDO. Sending expedited upload initiate response defined at index 0x1200 + ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   848
		nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   849
	sendSDO(d, whoami, sdo); 
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   850
	/* Release the line.*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   851
	resetSDOline(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   852
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   853
    } /* end if I am SERVER*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   854
    else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   855
      /* I am CLIENT */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   856
      /* It is the response for the previous initiate upload request.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   857
      /* We should find a line opened for this. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   858
      err = getSDOlineOnUse( d, nodeId, whoami, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   859
      if (!err)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   860
	err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   861
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   862
	MSG_ERR(0x1A97, "SDO error : Received response for unknown upload request from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   863
	failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   864
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   865
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   866
      /* Reset the wathdog */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   867
      RestartSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   868
      index = d->transfers[line].index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   869
      subIndex = d->transfers[line].subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   870
      
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   871
      if (getSDOe(m->data[0])) { /* If SDO expedited */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   872
	/* nb of data to be uploaded */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   873
	  nbBytes = 4 - getSDOn2(m->data[0]);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   874
	/* Storing the data in the line structure. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   875
	err = SDOtoLine(d, line, nbBytes, (*m).data + 4);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   876
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   877
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   878
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   879
	}
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   880
	/* SDO expedited -> transfert finished. data are available via  getReadResultNetworkDict(). */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   881
	MSG_WAR(0x3A98, "SDO expedited upload finished. Response received from node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   882
	StopSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   883
	d->transfers[line].count = nbBytes;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   884
	d->transfers[line].state = SDO_FINISHED;
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   885
	if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   886
	return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   887
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   888
      else { /* So, if it is not an expedited transfert */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   889
	/* Storing the nb of data to receive. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   890
	if (getSDOs(m->data[0])) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   891
	  nbBytes = m->data[4]; /* Remember the limitation to 255 bytes to transfert */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   892
	  err = setSDOlineRestBytes(d, line, nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   893
	  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   894
	    failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   895
	    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   896
	  }	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   897
	}
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   898
	/* Requesting next segment. (cs = 3) */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   899
	sdo.nodeId = nodeId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   900
	sdo.body.data[0] = 3 << 5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   901
	for (i = 1 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   902
	  sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   903
	MSG_WAR(0x3A99, "SDO. Sending upload segment request to node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   904
	sendSDO(d, whoami, sdo);  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   905
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   906
    } /* End if CLIENT */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   907
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   908
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   909
  case 3:
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   910
    /* I am SERVER */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   911
    if (whoami == SDO_SERVER) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   912
      /* Receiving a upload segment. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   913
      /* A SDO transfert should have been yet initiated. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   914
      err = getSDOlineOnUse( d, nodeId, whoami, &line ); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   915
      if (!err)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   916
	err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   917
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   918
	MSG_ERR(0x1AA0, "SDO error : Received upload segment for unstarted trans. index 0x1200 + ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   919
		nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   920
	failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   921
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   922
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   923
      /* Reset the wathdog */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   924
      RestartSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   925
      MSG_WAR(0x3AA1, "Received SDO upload segment defined at index 0x1200 + ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   926
      index = d->transfers[line].index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   927
      subIndex = d->transfers[line].subIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   928
      /* Toggle test.*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   929
      if (d->transfers[line].toggle != getSDOt(m->data[0])) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   930
	MSG_ERR(0x1AA2, "SDO error : Toggle error : ", getSDOt(m->data[0])); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   931
	failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   932
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   933
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   934
      /* Uploading next segment. We need to know if it will be the last one. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   935
      getSDOlineRestBytes(d, line, &nbBytes);	  	  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   936
      if (nbBytes > 7) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   937
	/* The segment to transfer is not the last one.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   938
	/* code to send the next segment. (cs = 0; c = 0) */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   939
	sdo.nodeId = nodeId; /* The server node Id; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   940
	sdo.body.data[0] = (d->transfers[line].toggle << 4);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   941
	err = lineToSDO(d, line, 7, sdo.body.data + 1);	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   942
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   943
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   944
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   945
	}
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   946
	/* Inverting the toggle for the next tranfert. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   947
	d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   948
	MSG_WAR(0x3AA3, "SDO. Sending upload segment defined at index 0x1200 + ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   949
	sendSDO(d, whoami, sdo); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   950
      } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   951
      else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   952
	/* Last segment. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   953
	/* code to send the last segment. (cs = 0; c = 1) */	    
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   954
	sdo.nodeId = nodeId; /* The server node Id; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   955
	sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   956
	err = lineToSDO(d, line, nbBytes, sdo.body.data + 1);	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   957
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   958
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   959
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   960
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   961
	for (i = nbBytes + 1 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   962
	  sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   963
	MSG_WAR(0x3AA4, "SDO. Sending last upload segment defined at index 0x1200 + ", nodeId);      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   964
	sendSDO(d, whoami, sdo);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   965
	/* Release the line */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   966
	resetSDOline(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   967
      }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   968
    } /* end if SERVER*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   969
    else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   970
      /* I am CLIENT */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   971
      /* It is the response for the previous initiate download request. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   972
      /* We should find a line opened for this. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   973
      err = getSDOlineOnUse( d, nodeId, whoami, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   974
      if (!err)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   975
	err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   976
      if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   977
	MSG_ERR(0x1AA5, "SDO error : Received response for unknown download request from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   978
	failedSDO(d, nodeId, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   979
	return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   980
      }
154
1b3165f2d17d Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents: 149
diff changeset
   981
      /* Reset the watchdog */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   982
      RestartSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   983
      index = d->transfers[line].index;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   984
      subIndex = d->transfers[line].subIndex;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   985
      /* End transmission or requesting  next segment. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   986
      getSDOlineRestBytes(d, line, &nbBytes);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   987
      if (nbBytes == 0) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   988
	MSG_WAR(0x3AA6, "SDO End download expedited. Response received. from nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   989
	StopSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   990
	d->transfers[line].state = SDO_FINISHED;
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
   991
	if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   992
	return 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   993
      }	  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   994
      if (nbBytes > 7) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   995
	/* more than one request to send */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   996
	/* code to send the next segment. (cs = 0; c = 0)	*/    
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
   997
	sdo.nodeId = nodeId; /* The server node Id; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   998
	sdo.body.data[0] = (d->transfers[line].toggle << 4);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   999
	err = lineToSDO(d, line, 7, sdo.body.data + 1);	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1000
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1001
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1002
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1003
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1004
      } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1005
      else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1006
	/* Last segment.*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1007
	/* code to send the last segment. (cs = 0; c = 1)	*/   
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1008
	sdo.nodeId = nodeId; /* The server node Id; */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1009
	sdo.body.data[0] = (d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1010
	err = lineToSDO(d, line, nbBytes, sdo.body.data + 1);	 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1011
	if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1012
	  failedSDO(d, nodeId, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1013
	  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1014
	}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1015
	for (i = nbBytes + 1 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1016
	  sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1017
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1018
      MSG_WAR(0x3AA7, "SDO sending download segment to nodeId", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1019
      sendSDO(d, whoami, sdo); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1020
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1021
    } /* end if I am a CLIENT		*/	  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1022
    break;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1023
82
81505425b1e5 16 bits arch compatibility and unused variables
frdupin
parents: 71
diff changeset
  1024
   case 4:
81505425b1e5 16 bits arch compatibility and unused variables
frdupin
parents: 71
diff changeset
  1025
     abortCode = (*m).data[3] |
81505425b1e5 16 bits arch compatibility and unused variables
frdupin
parents: 71
diff changeset
  1026
      ((UNS32)m->data[5] << 8) |
81505425b1e5 16 bits arch compatibility and unused variables
frdupin
parents: 71
diff changeset
  1027
      ((UNS32)m->data[6] << 16) |
81505425b1e5 16 bits arch compatibility and unused variables
frdupin
parents: 71
diff changeset
  1028
      ((UNS32)m->data[7] << 24);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1029
    /* Received SDO abort. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1030
    /* Looking for the line concerned. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1031
    if (whoami == SDO_SERVER) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1032
      err = getSDOlineOnUse( d, nodeId, whoami, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1033
      if (!err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1034
	resetSDOline( d, line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1035
	MSG_WAR(0x3AA8, "SD0. Received SDO abort. Line released. Code : ", abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1036
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1037
      else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1038
	MSG_WAR(0x3AA9, "SD0. Received SDO abort. No line found. Code : ", abortCode);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1039
      /* Tips : The end user has no way to know that the server node has received an abort SDO. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1040
      /* Its is ok, I think.*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1041
    }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1042
    else { /* If I am CLIENT */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1043
      err = getSDOlineOnUse( d, nodeId, whoami, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1044
      if (!err) {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1045
	/* The line *must* be released by the core program. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1046
	StopSDO_TIMER(line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1047
	d->transfers[line].state = SDO_ABORTED_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1048
	MSG_WAR(0x3AB0, "SD0. Received SDO abort. Line state ABORTED. Code : ", abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1049
      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1050
      else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1051
	MSG_WAR(0x3AB1, "SD0. Received SDO abort. No line found. Code : ", abortCode);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1052
    } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1053
    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1054
  default:
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1055
    /* Error : Unknown cs */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1056
    MSG_ERR(0x1AB2, "SDO. Received unknown command specifier : ", getSDOcs(m->data[0]));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1057
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1058
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1059
  } /* End switch */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1060
  return 0;     
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1061
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1062
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1063
/*******************************************************************)******/
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1064
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, 
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1065
		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1066
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1067
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1068
  UNS8 SDOfound = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1069
  UNS8 line;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1070
  s_SDO sdo;    /* SDO to transmit */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1071
  UNS8 i, j;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1072
  UNS16     lastIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1073
  UNS16     offset;
86
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
  1074
  UNS32      *pNodeIdServer;
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
  1075
  UNS32      nodeIdServer;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1076
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1077
  MSG_WAR(0x3AC0, "Send SDO to write in the dictionary of node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1078
  MSG_WAR(0x3AC1, "                                   At index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1079
  MSG_WAR(0x3AC2, "                                   subIndex : ", subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1080
  MSG_WAR(0x3AC3, "                                   nb bytes : ", count);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1081
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1082
  /* Verify that there is no SDO communication yet. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1083
  err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1084
  if (!err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1085
    MSG_ERR(0x1AC4, "SDO error : Communication yet established. with node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1086
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1087
  }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1088
  /* Taking the line ... */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1089
  err = getSDOfreeLine( d, SDO_CLIENT, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1090
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1091
    MSG_ERR(0x1AC5, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1092
    return (0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1093
  }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1094
  /* Check which SDO to use to communicate with the node */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1095
  offset = d->firstIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1096
  lastIndex = d->lastIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1097
  if (offset == 0) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1098
    MSG_ERR(0x1AC6, "writeNetworkDict : No SDO client index found", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1099
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1100
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1101
  i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1102
   while (offset <= lastIndex) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1103
     if (d->objdict[offset].bSubCount <= 3) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1104
	 MSG_ERR(0x1AC8, "Subindex 3  not found at index ", 0x1280 + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1105
	 return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1106
     }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1107
     /* looking for the nodeId server */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1108
     pNodeIdServer = d->objdict[offset].pSubindex[3].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1109
     nodeIdServer = *pNodeIdServer;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1110
     MSG_WAR(0x1AD2, "index : ", 0x1280 + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1111
     MSG_WAR(0x1AD3, "nodeIdServer : ", nodeIdServer);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1112
   
86
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
  1113
    if(nodeIdServer == (UNS32)nodeId) {
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1114
      SDOfound = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1115
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1116
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1117
    offset++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1118
    i++;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1119
  } /* end while */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1120
  if (!SDOfound) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1121
    MSG_ERR(0x1AC9, "SDO. Error. No client found to communicate with node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1122
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1123
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1124
  MSG_WAR(0x3AD0,"        SDO client defined at index  : ", 0x1280 + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1125
  initSDOline(d, line, nodeId, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1126
  d->transfers[line].count = count;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1127
  d->transfers[line].dataType = dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1128
  
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1129
  /* Copy data to transfers structure. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1130
  for (j = 0 ; j < count ; j++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1131
# ifdef CANOPEN_BIG_ENDIAN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1132
    if (dataType == 0)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1133
      d->transfers[line].data[count - 1 - j] = ((char *)data)[j];
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1134
    else /* String of bytes. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1135
      d->transfers[line].data[j] = ((char *)data)[j];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1136
#  else 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1137
    d->transfers[line].data[j] = ((char *)data)[j];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1138
#  endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1139
  }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1140
  /* Send the SDO to the server. Initiate download, cs=1. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1141
  sdo.nodeId = nodeId;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1142
  if (count <= 4) { /* Expedited transfert */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1143
    sdo.body.data[0] = (1 << 5) | ((4 - count) << 2) | 3;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1144
    for (i = 4 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1145
      sdo.body.data[i] = d->transfers[line].data[i - 4];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1146
    d->transfers[line].offset = count;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1147
  }	
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1148
  else { /* Normal transfert */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1149
    sdo.body.data[0] = (1 << 5) | 1;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1150
    sdo.body.data[4] = count; /* nb of byte to transmit. Max = 255. (canfestival2 limitation). */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1151
    for (i = 5 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1152
      sdo.body.data[i] = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1153
  }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1154
  sdo.body.data[1] = index & 0xFF;        /* LSB */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1155
  sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1156
  sdo.body.data[3] = subIndex;
154
1b3165f2d17d Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents: 149
diff changeset
  1157
1b3165f2d17d Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents: 149
diff changeset
  1158
  d->transfers[line].Callback = Callback;
1b3165f2d17d Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents: 149
diff changeset
  1159
    
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1160
  err = sendSDO(d, SDO_CLIENT, sdo);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1161
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1162
    MSG_ERR(0x1AD1, "SDO. Error while sending SDO to node : ", nodeId);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1163
    /* release the line */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1164
    resetSDOline(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1165
    return 0xFF;
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1166
  }
154
1b3165f2d17d Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents: 149
diff changeset
  1167
1b3165f2d17d Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents: 149
diff changeset
  1168
  
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1169
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1170
}
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1171
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1172
/*--------------------------------------------------------------------------*/
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1173
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1174
UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, 
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1175
		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data)
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1176
{
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1177
	return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, NULL);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1178
}
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1179
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1180
/*--------------------------------------------------------------------------*/
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1181
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1182
UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index, 
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1183
		       UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback)
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1184
{
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1185
	return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback);	
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1186
}
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1187
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1188
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1189
/***************************************************************************/
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1190
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1191
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1192
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1193
  UNS8 SDOfound = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1194
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1195
  UNS8 line;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1196
  s_SDO sdo;    /* SDO to transmit */
86
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
  1197
  UNS32      *pNodeIdServer;
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
  1198
  UNS32      nodeIdServer;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1199
  UNS16     offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1200
  UNS16     lastIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1201
  MSG_WAR(0x3AD5, "Send SDO to read in the dictionary of node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1202
  MSG_WAR(0x3AD6, "                                  At index : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1203
  MSG_WAR(0x3AD7, "                                  subIndex : ", subIndex);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1204
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1205
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1206
  /* Verify that there is no SDO communication yet. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1207
  err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1208
  if (!err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1209
    MSG_ERR(0x1AD8, "SDO error : Communication yet established. with node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1210
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1211
  }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1212
  /* Taking the line ... */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1213
  err = getSDOfreeLine( d, SDO_CLIENT, &line );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1214
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1215
    MSG_ERR(0x1AD9, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1216
    return (0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1217
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1218
  else
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1219
    MSG_WAR(0x3AE0, "Transmission on line : ", line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1220
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1221
  /* Check which SDO to use to communicate with the node */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1222
  offset = d->firstIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1223
  lastIndex = d->lastIndex->SDO_CLT;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1224
  if (offset == 0) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1225
    MSG_ERR(0x1AE1, "writeNetworkDict : No SDO client index found", 0); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1226
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1227
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1228
  i = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1229
  while (offset <= lastIndex) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1230
     if (d->objdict[offset].bSubCount <= 3) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1231
	 MSG_ERR(0x1AE2, "Subindex 3  not found at index ", 0x1280 + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1232
	 return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1233
     }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1234
     /* looking for the nodeId server */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1235
     pNodeIdServer = d->objdict[offset].pSubindex[3].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1236
     nodeIdServer = *pNodeIdServer;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1237
   
86
683702a46416 big endian bogue : nodeIdServer in now in 32 bits
frdupin
parents: 84
diff changeset
  1238
    if(nodeIdServer == (UNS32)nodeId) {
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1239
      SDOfound = 1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1240
      break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1241
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1242
    offset++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1243
    i++;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1244
  } /* end while */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1245
  if (!SDOfound) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1246
    MSG_ERR(0x1AE3, "SDO. Error. No client found to communicate with node : ", nodeId);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1247
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1248
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1249
  MSG_WAR(0x3AE4,"        SDO client defined at index  : ", 0x1280 + i);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1250
  initSDOline(d, line, nodeId, index, subIndex, SDO_UPLOAD_IN_PROGRESS);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1251
  getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1252
  sdo.nodeId = nodeId;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1253
  /* Send the SDO to the server. Initiate upload, cs=2. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1254
  d->transfers[line].dataType = dataType;				
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1255
  sdo.body.data[0] = (2 << 5);	
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1256
  sdo.body.data[1] = index & 0xFF;        /* LSB */
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1257
  sdo.body.data[2] = (index >> 8) & 0xFF; /* MSB */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1258
  sdo.body.data[3] = subIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1259
  for (i = 4 ; i < 8 ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1260
    sdo.body.data[i] = 0;
154
1b3165f2d17d Implemented writeNetworkDictCallBack test in TestMasterSlave example. Fixed callback assignement race condition in sdo.c.
etisserant
parents: 149
diff changeset
  1261
  d->transfers[line].Callback = Callback;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1262
  err = sendSDO(d, SDO_CLIENT, sdo);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1263
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1264
    MSG_ERR(0x1AE5, "SDO. Error while sending SDO to node : ", nodeId);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1265
    /* release the line */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1266
    resetSDOline(d, line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1267
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1268
  }		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1269
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1270
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1271
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1272
/*--------------------------------------------------------------------------*/
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1273
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1274
UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType)
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1275
{
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1276
	return _readNetworkDict (d, nodeId, index, subIndex, dataType, NULL);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1277
}
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1278
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1279
/*--------------------------------------------------------------------------*/
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1280
UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback)
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1281
{
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1282
	return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback);
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1283
}
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
  1284
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1285
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1286
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1287
UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS8 *size, 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1288
			       UNS32 * abortCode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1289
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1290
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1291
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1292
  UNS8 line;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1293
  * size = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1294
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1295
  /* Looking for the line tranfert. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1296
  err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1297
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1298
    MSG_ERR(0x1AF0, "SDO error : No line found for communication with node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1299
    return SDO_ABORTED_INTERNAL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1300
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1301
  if (d->transfers[line].state != SDO_FINISHED)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1302
    return d->transfers[line].state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1303
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1304
  /* Transfert is finished. Put the value in the data. */
145
e747d2e26af0 Win32 Native support and dynamicaly loaded CAN drivers for Linux, Cygwin and Win32.
etisserant
parents: 87
diff changeset
  1305
  * size = (UNS8)d->transfers[line].count;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1306
  for  ( i = 0 ; i < *size ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1307
# ifdef CANOPEN_BIG_ENDIAN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1308
    if (d->transfers[line].dataType != visible_string)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1309
      ( (char *) data)[*size - 1 - i] = d->transfers[line].data[i];
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1310
    else /* String of bytes. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1311
      ( (char *) data)[i] = d->transfers[line].data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1312
# else 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1313
    ( (char *) data)[i] = d->transfers[line].data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1314
# endif
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1315
  } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1316
  return SDO_FINISHED;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1317
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1318
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1319
/***************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1320
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1321
UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1322
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1323
  UNS8 line = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1324
  UNS8 err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1325
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1326
  * abortCode = 0;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
  1327
  /* Looking for the line tranfert. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1328
  err = getSDOlineOnUse(d, nodeId, SDO_CLIENT, &line);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1329
  if (err) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1330
    MSG_ERR(0x1AF1, "SDO error : No line found for communication with node : ", nodeId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1331
    return SDO_ABORTED_INTERNAL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1332
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1333
  * abortCode = d->transfers[line].abortCode;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1334
  return d->transfers[line].state;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1335
}
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
  1336
149
fe50ada8020b Changes in the API:
etisserant
parents: 145
diff changeset
  1337
void _SDOtimeoutError (UNS8 line){}