src/sdo.c
author fbeaulier
Mon, 29 Aug 2011 16:59:55 +0200
changeset 664 a03f0aa7d219
parent 663 70fc3603e36f
child 665 90e6cf84a0d7
permissions -rw-r--r--
CHANGE: SDO block mode added, without CRC support
WARNING : API change in client functions
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     2
   This file is part of CanFestival, a library implementing CanOpen Stack.
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     3
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     4
   Copyright (C): Edouard TISSERANT and Francis DUPIN
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     5
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     6
   See COPYING file for copyrights details.
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     7
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     8
   This library is free software; you can redistribute it and/or
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
     9
   modify it under the terms of the GNU Lesser General Public
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    10
   License as published by the Free Software Foundation; either
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    11
   version 2.1 of the License, or (at your option) any later version.
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    12
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    13
   This library is distributed in the hope that it will be useful,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    16
   Lesser General Public License for more details.
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    17
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    18
   You should have received a copy of the GNU Lesser General Public
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    19
   License along with this library; if not, write to the Free Software
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    20
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    21
   */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    22
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    23
 ** @file   sdo.c
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    24
 ** @author Edouard TISSERANT and Francis DUPIN
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    25
 ** @date   Tue Jun  5 09:32:32 2007
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    26
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    27
 ** @brief
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    28
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    29
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    30
 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
84
19def60bd29c forgot some comments ...
frdupin
parents: 82
diff changeset
    32
/* #define DEBUG_WAR_CONSOLE_ON */
19def60bd29c forgot some comments ...
frdupin
parents: 82
diff changeset
    33
/* #define DEBUG_ERR_CONSOLE_ON */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
383
7d8afedb8769 Fixed missing includes causing warnings
etisserant
parents: 378
diff changeset
    35
#include "canfestival.h"
370
6fecf36df407 Fixed some endianization problems caused by switch to UNS16 for cob_id member in CAN messages. To be continued.
etisserant
parents: 365
diff changeset
    36
#include "sysdep.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    38
/* Uncomment if your compiler does not support inline functions */
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    39
#define NO_INLINE
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    40
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    41
#ifdef NO_INLINE
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    42
#define INLINE
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    43
#else
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    44
#define INLINE inline
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    45
#endif
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    46
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    47
/*Internals prototypes*/
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    48
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 174
diff changeset
    49
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    50
 ** Called by writeNetworkDict
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    51
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    52
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    53
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    54
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    55
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    56
 ** @param count
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    57
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    58
 ** @param data
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    59
 ** @param Callback
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    60
 ** @param endianize
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    61
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    62
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    63
 **/
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    64
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
    65
		UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize, UNS8 useBlockMode);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    66
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    67
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    68
 ** Called by readNetworkDict
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    69
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    70
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    71
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    72
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    73
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    74
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    75
 ** @param Callback
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    76
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    77
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    78
 **/
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    79
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex,
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
    80
		UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode);
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    81
53
73bc47a0db55 Add prototypes
frdupin
parents: 32
diff changeset
    82
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
/***************************************************************************/
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 53
diff changeset
    84
/* SDO (un)packing macros */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    85
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    86
/** Returns the command specifier (cs, ccs, scs) from the first byte of the SDO
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    87
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
#define getSDOcs(byte) (byte >> 5)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    89
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    90
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 2 bits
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    91
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    92
#define getSDOn2(byte) ((byte >> 2) & 3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    94
/** Returns the number of bytes without data from the first byte of the SDO. Coded in 3 bits
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    95
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
#define getSDOn3(byte) ((byte >> 1) & 7)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
    98
/** Returns the transfer type from the first byte of the SDO
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
    99
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
#define getSDOe(byte) ((byte >> 1) & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   102
/** Returns the size indicator from the first byte of the SDO
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   103
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
#define getSDOs(byte) (byte & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   106
/** Returns the indicator of end transmission from the first byte of the SDO
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   107
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
#define getSDOc(byte) (byte & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   110
/** Returns the toggle from the first byte of the SDO
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   111
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
#define getSDOt(byte) ((byte >> 4) & 1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   114
/** Returns the index from the bytes 1 and 2 of the SDO
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   115
*/
604
96e632bc1e58 Fixed casts subject to problems on some compilers.
edouard
parents: 597
diff changeset
   116
#define getSDOindex(byte1, byte2) (((UNS16)byte2 << 8) | ((UNS16)byte1))
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   118
/** Returns the subIndex from the byte 3 of the SDO
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   119
*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
#define getSDOsubIndex(byte3) (byte3)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   122
/** Returns the subcommand in SDO block transfert
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   123
*/
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   124
#define getSDOblockSC(byte) (byte & 3)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   125
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   126
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   127
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   128
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   129
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   130
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   131
 ** @param id
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   132
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
void SDOTimeoutAlarm(CO_Data* d, UNS32 id)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   135
	UNS16 offset;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   136
	UNS8 nodeId;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   137
	/* Get the client->server cobid.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   138
	offset = d->firstIndex->SDO_CLT;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   139
	if ((offset == 0) || ((offset+d->transfers[id].CliServNbr) > d->lastIndex->SDO_CLT)) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   140
		return ;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   141
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   142
	nodeId = *((UNS32*) d->objdict[offset+d->transfers[id].CliServNbr].pSubindex[3].pObject);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   143
	MSG_ERR(0x1A01, "SDO timeout. SDO response not received.", 0);
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   144
	MSG_WAR(0x2A02, "server node id : ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   145
	MSG_WAR(0x2A02, "         index : ", d->transfers[id].index);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   146
	MSG_WAR(0x2A02, "      subIndex : ", d->transfers[id].subIndex);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   147
	/* Reset timer handler */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   148
	d->transfers[id].timer = TIMER_NONE;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   149
	/*Set aborted state*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   150
	d->transfers[id].state = SDO_ABORTED_INTERNAL;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   151
	/* Sending a SDO abort */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   152
	sendSDOabort(d, d->transfers[id].whoami, d->transfers[id].CliServNbr,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   153
			d->transfers[id].index, d->transfers[id].subIndex, SDOABT_TIMED_OUT);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   154
	d->transfers[id].abortCode = SDOABT_TIMED_OUT;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   155
	/* Call the user function to inform of the problem.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   156
	if(d->transfers[id].Callback)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   157
		/*If ther is a callback, it is responsible to close SDO transfer (client)*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   158
		(*d->transfers[id].Callback)(d, nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   159
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   160
	/*Reset the line if (whoami == SDO_SERVER) or the callback did not close the line.
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   161
	  Otherwise this sdo transfer would never be closed. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   162
	resetSDOline(d, (UNS8)id);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
#define StopSDO_TIMER(id) \
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   166
	MSG_WAR(0x3A05, "StopSDO_TIMER for line : ", line);\
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
d->transfers[id].timer = DelAlarm(d->transfers[id].timer);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
#define StartSDO_TIMER(id) \
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   170
	MSG_WAR(0x3A06, "StartSDO_TIMER for line : ", line);\
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
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
   172
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
#define RestartSDO_TIMER(id) \
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   174
	MSG_WAR(0x3A07, "restartSDO_TIMER for line : ", line);\
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
if(d->transfers[id].timer != TIMER_NONE) { StopSDO_TIMER(id) StartSDO_TIMER(id) }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   177
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   178
 ** Reset all sdo buffers
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   179
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   180
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   181
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
void resetSDO (CO_Data* d)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   184
	UNS8 j;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   185
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   186
	/* transfer structure initialization */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   187
	for (j = 0 ; j < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; j++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   188
		resetSDOline(d, j);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   189
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   190
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   191
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   192
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   193
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   194
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   195
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   196
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   197
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   198
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
UNS32 SDOlineToObjdict (CO_Data* d, UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   201
	UNS32 size;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   202
	UNS32 errorCode;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   203
	MSG_WAR(0x3A08, "Enter in SDOlineToObjdict ", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   204
	/* if SDO initiated with e=0 and s=0 count is null, offset carry effective size*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   205
	if( d->transfers[line].count == 0)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   206
		d->transfers[line].count = d->transfers[line].offset;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   207
	size = d->transfers[line].count;
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   208
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   209
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   210
	if (size > SDO_MAX_LENGTH_TRANSFERT)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   211
	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   212
		errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   213
				(void *) d->transfers[line].dynamicData, &size, 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   214
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   215
	else
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   216
	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   217
		errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   218
				(void *) d->transfers[line].data, &size, 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   219
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   220
#else //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   221
	errorCode = setODentry(d, d->transfers[line].index, d->transfers[line].subIndex,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   222
			(void *) d->transfers[line].data, &size, 1);
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   223
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   224
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   225
	if (errorCode != OD_SUCCESSFUL)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   226
		return errorCode;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   227
	MSG_WAR(0x3A08, "exit of SDOlineToObjdict ", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   228
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   229
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   230
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   231
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   232
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   233
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   234
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   235
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   236
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   237
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   238
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   239
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   240
UNS32 objdictToSDOline (CO_Data* d, UNS8 line)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   242
	UNS32  size = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   243
	UNS8  dataType;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   244
	UNS32 errorCode;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   245
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   246
	MSG_WAR(0x3A05, "objdict->line index : ", d->transfers[line].index);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   247
	MSG_WAR(0x3A06, "  subIndex : ", d->transfers[line].subIndex);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   248
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   249
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   250
	//TODO: Read the size of the object. Depending o it put data into data or dynamicData
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   251
	errorCode = getODentry(d, 	d->transfers[line].index,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   252
			d->transfers[line].subIndex,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   253
			(void *)d->transfers[line].data,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   254
			&size, &dataType, 1);
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   255
#else //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   256
	errorCode = getODentry(d, 	d->transfers[line].index,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   257
			d->transfers[line].subIndex,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   258
			(void *)d->transfers[line].data,
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   259
			&size, &dataType, 1);
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   260
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   261
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   262
	if (errorCode != OD_SUCCESSFUL)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   263
		return errorCode;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   264
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   265
	d->transfers[line].count = size;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   266
	d->transfers[line].offset = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   267
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   268
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   269
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   270
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   271
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   272
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   273
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   274
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   275
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   276
 ** @param nbBytes
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   277
 ** @param data
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   278
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   279
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   280
 **/
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 538
diff changeset
   281
UNS8 lineToSDO (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data) {
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   282
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   283
	UNS32 offset;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   285
#ifndef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   286
	if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   287
		MSG_ERR(0x1A10,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   288
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   289
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   290
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   291
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   292
	if ((d->transfers[line].offset + nbBytes) > d->transfers[line].count) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   293
		MSG_ERR(0x1A11,"SDO Size of data too large. Exceed count", nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   294
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   295
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   296
	offset = d->transfers[line].offset;
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   297
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   298
	if (d->transfers[line].count <= SDO_MAX_LENGTH_TRANSFERT)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   299
	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   300
		for (i = 0 ; i < nbBytes ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   301
			* (data + i) = d->transfers[line].data[offset + i];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   302
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   303
	else
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   304
	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   305
		if (d->transfers[line].dynamicData == NULL)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   306
		{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   307
			MSG_ERR(0x1A11,"SDO's dynamic buffer not allocated. Line", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   308
			return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   309
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   310
		for (i = 0 ; i < nbBytes ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   311
			* (data + i) = d->transfers[line].dynamicData[offset + i];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   312
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   313
#else //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   314
	for (i = 0 ; i < nbBytes ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   315
		* (data + i) = d->transfers[line].data[offset + i];
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   316
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   317
	d->transfers[line].offset = d->transfers[line].offset + nbBytes;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   318
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   319
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   320
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   321
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   322
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   323
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   324
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   325
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   326
 ** @param nbBytes
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   327
 ** @param data
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   328
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   329
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   330
 **/
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 538
diff changeset
   331
UNS8 SDOtoLine (CO_Data* d, UNS8 line, UNS32 nbBytes, UNS8* data)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   333
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   334
	UNS32 offset;
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   335
#ifndef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   336
	if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   337
		MSG_ERR(0x1A15,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   338
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   339
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   340
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   341
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   342
	offset = d->transfers[line].offset;
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   343
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   344
	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   345
		UNS8* lineData = d->transfers[line].data;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   346
		if ((d->transfers[line].offset + nbBytes) > SDO_MAX_LENGTH_TRANSFERT) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   347
			if (d->transfers[line].dynamicData == NULL) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   348
				d->transfers[line].dynamicData = (UNS8*) malloc(SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   349
				d->transfers[line].dynamicDataSize = SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   350
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   351
				if (d->transfers[line].dynamicData == NULL) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   352
					MSG_ERR(0x1A15,"SDO allocating dynamic buffer failed, size", SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   353
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   354
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   355
				//Copy present data
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   356
				memcpy(d->transfers[line].dynamicData, d->transfers[line].data, offset);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   357
			}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   358
			else if ((d->transfers[line].offset + nbBytes) > d->transfers[line].dynamicDataSize)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   359
			{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   360
				UNS8* newDynamicBuffer = (UNS8*) realloc(d->transfers[line].dynamicData, d->transfers[line].dynamicDataSize + SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   361
				if (newDynamicBuffer == NULL) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   362
					MSG_ERR(0x1A15,"SDO reallocating dynamic buffer failed, size", d->transfers[line].dynamicDataSize + SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   363
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   364
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   365
				d->transfers[line].dynamicData = newDynamicBuffer;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   366
				d->transfers[line].dynamicDataSize += SDO_DYNAMIC_BUFFER_ALLOCATION_SIZE;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   367
			}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   368
			lineData = d->transfers[line].dynamicData;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   369
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   370
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   371
		for (i = 0 ; i < nbBytes ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   372
			lineData[offset + i] = * (data + i);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   373
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   374
#else //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   375
	for (i = 0 ; i < nbBytes ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   376
		d->transfers[line].data[offset + i] = * (data + i);
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   377
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   378
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   379
	d->transfers[line].offset = d->transfers[line].offset + nbBytes;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   380
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   381
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   382
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   383
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   384
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   385
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   386
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   387
 ** @param CliServNbr
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   388
 ** @param whoami
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   389
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   390
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   391
 ** @param abortCode
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   392
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   393
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   394
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   395
UNS8 failedSDO (CO_Data* d, UNS8 CliServNbr, UNS8 whoami, UNS16 index,
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
		UNS8 subIndex, UNS32 abortCode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   397
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   398
	UNS8 err;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   399
	UNS8 line;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   400
	err = getSDOlineOnUse( d, CliServNbr, whoami, &line );
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   401
	if (!err) /* If a line on use have been found.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   402
		MSG_WAR(0x3A20, "FailedSDO : line found : ", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   403
	if ((! err) && (whoami == SDO_SERVER)) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   404
		resetSDOline( d, line );
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   405
		MSG_WAR(0x3A21, "FailedSDO : line released : ", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   406
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   407
	if ((! err) && (whoami == SDO_CLIENT)) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   408
		StopSDO_TIMER(line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   409
		d->transfers[line].state = SDO_ABORTED_INTERNAL;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   410
		d->transfers[line].abortCode = abortCode;
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   411
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   412
	MSG_WAR(0x3A22, "Sending SDO abort ", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   413
	err = sendSDOabort(d, whoami, CliServNbr, index, subIndex, abortCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   414
	if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   415
		MSG_WAR(0x3A23, "Unable to send the SDO abort", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   416
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   417
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   418
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   419
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   420
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   421
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   422
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   423
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   424
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   425
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   426
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
void resetSDOline ( CO_Data* d, UNS8 line )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   429
	UNS32 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   430
	MSG_WAR(0x3A25, "reset SDO line nb : ", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   431
	initSDOline(d, line, 0, 0, 0, SDO_RESET);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   432
	for (i = 0 ; i < SDO_MAX_LENGTH_TRANSFERT ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   433
		d->transfers[line].data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   434
	d->transfers[line].whoami = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   435
	d->transfers[line].abortCode = 0;
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   438
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   439
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   440
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   441
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   442
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   443
 ** @param CliServNbr
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   444
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   445
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   446
 ** @param state
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   447
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   448
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   449
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   450
UNS8 initSDOline (CO_Data* d, UNS8 line, UNS8 CliServNbr, UNS16 index, UNS8 subIndex, UNS8 state)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   451
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   452
	MSG_WAR(0x3A25, "init SDO line nb : ", line);
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   453
	if (state == SDO_DOWNLOAD_IN_PROGRESS       || state == SDO_UPLOAD_IN_PROGRESS ||
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   454
        state == SDO_BLOCK_DOWNLOAD_IN_PROGRESS || state == SDO_BLOCK_UPLOAD_IN_PROGRESS){
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   455
		StartSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   456
	}else{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   457
		StopSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   458
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   459
	d->transfers[line].CliServNbr = CliServNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   460
	d->transfers[line].index = index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   461
	d->transfers[line].subIndex = subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   462
	d->transfers[line].state = state;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   463
	d->transfers[line].toggle = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   464
	d->transfers[line].count = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   465
	d->transfers[line].offset = 0;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   466
    d->transfers[line].peerCRCsupport = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   467
    d->transfers[line].blksize = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   468
    d->transfers[line].ackseq = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   469
    d->transfers[line].objsize = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   470
    d->transfers[line].lastblockoffset = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   471
    d->transfers[line].seqno = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   472
    d->transfers[line].endfield = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   473
    d->transfers[line].rxstep = RXSTEP_INIT;
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   474
	d->transfers[line].dataType = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   475
	d->transfers[line].Callback = NULL;
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   476
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   477
	free(d->transfers[line].dynamicData);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   478
	d->transfers[line].dynamicData = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   479
	d->transfers[line].dynamicDataSize = 0;
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   480
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   481
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   482
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   483
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   484
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   485
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   486
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   487
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   488
 ** @param whoami
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   489
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   490
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   491
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   492
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   493
UNS8 getSDOfreeLine ( CO_Data* d, UNS8 whoami, UNS8 *line )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   494
{
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
   495
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   496
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   497
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   498
	for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   499
		if ( d->transfers[i].state == SDO_RESET ) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   500
			*line = i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   501
			d->transfers[i].whoami = whoami;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   502
			return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   503
		} /* end if */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   504
	} /* end for */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   505
	MSG_ERR(0x1A25, "Too many SDO in progress. Aborted.", i);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   506
	return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   507
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   508
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   509
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   510
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   511
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   512
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   513
 ** @param CliServNbr
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   514
 ** @param whoami
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   515
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   516
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   517
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   518
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   519
UNS8 getSDOlineOnUse (CO_Data* d, UNS8 CliServNbr, UNS8 whoami, UNS8 *line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   520
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   521
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   522
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   523
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   524
	for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   525
		if ( (d->transfers[i].state != SDO_RESET) &&
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   526
				(d->transfers[i].state != SDO_ABORTED_INTERNAL) &&
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   527
				(d->transfers[i].CliServNbr == CliServNbr) &&
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   528
				(d->transfers[i].whoami == whoami) ) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   529
			if (line) *line = i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   530
			return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   531
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   532
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   533
	return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   534
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   535
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   536
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   537
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   538
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   539
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   540
 ** @param CliServNbr
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   541
 ** @param whoami
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   542
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   543
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   544
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   545
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   546
UNS8 getSDOlineToClose (CO_Data* d, UNS8 CliServNbr, UNS8 whoami, UNS8 *line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   547
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   548
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   549
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   550
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   551
	for (i = 0 ; i < SDO_MAX_SIMULTANEOUS_TRANSFERTS ; i++){
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   552
		if ( (d->transfers[i].state != SDO_RESET) &&
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   553
				(d->transfers[i].CliServNbr == CliServNbr) &&
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   554
				(d->transfers[i].whoami == whoami) ) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   555
			if (line) *line = i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   556
			return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   557
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   558
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   559
	return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   560
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   561
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   562
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   563
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   564
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   565
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   566
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   567
 ** @param CliServNbr
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   568
 ** @param whoami
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   569
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   570
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   571
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   572
UNS8 closeSDOtransfer (CO_Data* d, UNS8 CliServNbr, UNS8 whoami)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   573
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   574
	UNS8 err;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   575
	UNS8 line;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   576
	err = getSDOlineToClose(d, CliServNbr, whoami, &line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   577
	if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   578
		MSG_WAR(0x2A30, "No SDO communication to close", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   579
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   580
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   581
	resetSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   582
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   583
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   584
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   585
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   586
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   587
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   588
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   589
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   590
 ** @param nbBytes
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   591
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   592
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   593
 **/
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 538
diff changeset
   594
UNS8 getSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 * nbBytes)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   595
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   596
	/* SDO initiated with e=0 and s=0 have count set to null */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   597
	if (d->transfers[line].count == 0)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   598
		* nbBytes = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   599
	else
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   600
		* nbBytes = d->transfers[line].count - d->transfers[line].offset;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   601
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   602
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   603
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   604
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   605
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   606
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   607
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   608
 ** @param line
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   609
 ** @param nbBytes
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   610
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   611
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   612
 **/
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 538
diff changeset
   613
UNS8 setSDOlineRestBytes (CO_Data* d, UNS8 line, UNS32 nbBytes)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   614
{
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   615
#ifndef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   616
	if (nbBytes > SDO_MAX_LENGTH_TRANSFERT) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   617
		MSG_ERR(0x1A35,"SDO Size of data too large. Exceed SDO_MAX_LENGTH_TRANSFERT", nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   618
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   619
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   620
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
   621
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   622
	d->transfers[line].count = nbBytes;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   623
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   624
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   625
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   626
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   627
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   628
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   629
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   630
 ** @param whoami
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   631
 ** @param CliServNbr
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   632
 ** @param pData
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   633
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   634
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   635
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   636
UNS8 sendSDO (CO_Data* d, UNS8 whoami, UNS8 CliServNbr, UNS8 *pData)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   637
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   638
	UNS16 offset;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   639
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   640
	Message m;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   641
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   642
	MSG_WAR(0x3A38, "sendSDO",0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   643
	if( !((d->nodeState == Operational) ||  (d->nodeState == Pre_operational ))) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   644
		MSG_WAR(0x2A39, "unable to send the SDO (not in op or pre-op mode", d->nodeState);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   645
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   646
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   647
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   648
	/*get the server->client cobid*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   649
	if ( whoami == SDO_SERVER )	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   650
		offset = d->firstIndex->SDO_SVR;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   651
		if ((offset == 0) || ((offset+CliServNbr) > d->lastIndex->SDO_SVR)) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   652
			MSG_ERR(0x1A42, "SendSDO : SDO server not found", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   653
			return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   654
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   655
		m.cob_id = *((UNS32*) d->objdict[offset+CliServNbr].pSubindex[2].pObject);
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   656
		MSG_WAR(0x3A41, "I am server Tx cobId : ", m.cob_id);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   657
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   658
	else {			/*case client*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   659
		/* Get the client->server cobid.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   660
		offset = d->firstIndex->SDO_CLT;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   661
		if ((offset == 0) || ((offset+CliServNbr) > d->lastIndex->SDO_CLT)) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   662
			MSG_ERR(0x1A42, "SendSDO : SDO client not found", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   663
			return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   664
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   665
		m.cob_id = *((UNS32*) d->objdict[offset+CliServNbr].pSubindex[1].pObject);
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   666
		MSG_WAR(0x3A41, "I am client Tx cobId : ", m.cob_id);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   667
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   668
	/* message copy for sending */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   669
	m.rtr = NOT_A_REQUEST;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   670
	/* the length of SDO must be 8 */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   671
	m.len = 8;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   672
	for (i = 0 ; i < 8 ; i++) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   673
		m.data[i] =  pData[i];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   674
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   675
	return canSend(d->canHandle,&m);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   676
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   677
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   678
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   679
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   680
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   681
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   682
 ** @param whoami
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   683
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   684
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   685
 ** @param abortCode
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   686
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   687
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   688
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   689
UNS8 sendSDOabort (CO_Data* d, UNS8 whoami, UNS8 CliServNbr, UNS16 index, UNS8 subIndex, UNS32 abortCode)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   690
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   691
	UNS8 data[8];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   692
	UNS8 ret;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   693
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   694
	MSG_WAR(0x2A50,"Sending SDO abort ", abortCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   695
	data[0] = 0x80;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   696
	/* Index */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   697
	data[1] = index & 0xFF; /* LSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   698
	data[2] = (index >> 8) & 0xFF; /* MSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   699
	/* Subindex */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   700
	data[3] = subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   701
	/* Data */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   702
	data[4] = (UNS8)(abortCode & 0xFF);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   703
	data[5] = (UNS8)((abortCode >> 8) & 0xFF);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   704
	data[6] = (UNS8)((abortCode >> 16) & 0xFF);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   705
	data[7] = (UNS8)((abortCode >> 24) & 0xFF);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   706
	ret = sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   707
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   708
	return ret;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   709
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   710
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   711
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   712
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   713
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   714
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   715
 ** @param m
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   716
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   717
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   718
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   719
UNS8 proceedSDO (CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   720
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   721
	UNS8 err;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   722
	UNS8 cs;
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   723
	UNS8 line;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   724
	UNS32 nbBytes; 		/* received or to be transmited. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   725
	UNS8 nodeId = 0;  	/* The node Id of the server if client otherwise unused */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   726
	UNS8 CliServNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   727
	UNS8 whoami = SDO_UNKNOWN;  /* SDO_SERVER or SDO_CLIENT.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   728
	UNS32 errorCode; /* while reading or writing in the local object dictionary.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   729
	UNS8 data[8];    /* data for SDO to transmit */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   730
	UNS16 index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   731
	UNS8 subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   732
	UNS32 abortCode;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   733
	UNS32 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   734
	UNS8	j;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   735
	UNS32 *pCobId = NULL;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   736
	UNS16 offset;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   737
	UNS16 lastIndex;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   738
	UNS8 SubCommand;	/* Block transfert only */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   739
    UNS8 SeqNo;         /* Sequence number in block transfert */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   740
    UNS8 AckSeq;        /* Sequence number of last segment that was received successfully */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   741
	UNS8 NbBytesNoData; /* Number of bytes that do not contain data in last segment of block transfert */ 
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   742
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   743
	MSG_WAR(0x3A60, "proceedSDO ", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   744
	whoami = SDO_UNKNOWN;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   745
	/* Looking for the cobId in the object dictionary. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   746
	/* Am-I a server ? */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   747
	offset = d->firstIndex->SDO_SVR;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   748
	lastIndex = d->lastIndex->SDO_SVR;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   749
	j = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   750
	if(offset) while (offset <= lastIndex) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   751
		if (d->objdict[offset].bSubCount <= 1) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   752
			MSG_ERR(0x1A61, "Subindex 1  not found at index ", 0x1200 + j);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   753
			return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   754
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   755
		/* Looking for the cobid received. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   756
		pCobId = (UNS32*) d->objdict[offset].pSubindex[1].pObject;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   757
		if ( *pCobId == UNS16_LE(m->cob_id) ) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   758
			whoami = SDO_SERVER;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   759
			MSG_WAR(0x3A62, "proceedSDO. I am server. index : ", 0x1200 + j);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   760
			/* Defining Server number = index minus 0x1200 where the cobid received is defined. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   761
			CliServNbr = j;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   762
			break;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   763
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   764
		j++;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   765
		offset++;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   766
	} /* end while */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   767
	if (whoami == SDO_UNKNOWN) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   768
		/* Am-I client ? */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   769
		offset = d->firstIndex->SDO_CLT;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   770
		lastIndex = d->lastIndex->SDO_CLT;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   771
		j = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   772
		if(offset) while (offset <= lastIndex) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   773
			if (d->objdict[offset].bSubCount <= 3) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   774
				MSG_ERR(0x1A63, "Subindex 3  not found at index ", 0x1280 + j);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   775
				return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   776
			}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   777
			/* Looking for the cobid received. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   778
			pCobId = (UNS32*) d->objdict[offset].pSubindex[2].pObject;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   779
			if (*pCobId == UNS16_LE(m->cob_id) ) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   780
				whoami = SDO_CLIENT;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   781
				MSG_WAR(0x3A64, "proceedSDO. I am client index : ", 0x1280 + j);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   782
				/* Defining Client number = index minus 0x1280 where the cobid received is defined. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   783
				CliServNbr = j;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   784
				/* Reading the server node ID, if client it is mandatory in the OD */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   785
				nodeId = *((UNS8*) d->objdict[offset].pSubindex[3].pObject);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   786
				break;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   787
			}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   788
			j++;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   789
			offset++;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   790
		} /* end while */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   791
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   792
	if (whoami == SDO_UNKNOWN) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   793
		return 0xFF;/* This SDO was not for us ! */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   794
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   795
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   796
	/* Test if the size of the SDO is ok */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   797
	if ( (*m).len != 8) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   798
		MSG_ERR(0x1A67, "Error size SDO", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   799
		failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   800
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   801
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   802
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   803
	if (whoami == SDO_CLIENT) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   804
		MSG_WAR(0x3A68, "I am CLIENT number ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   805
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   806
	else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   807
		MSG_WAR(0x3A69, "I am SERVER number ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   808
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   809
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   810
	/* Look for an SDO transfert already initiated. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   811
	err = getSDOlineOnUse( d, CliServNbr, whoami, &line );
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   812
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   813
	/* Let's find cs value, first it is set as "not valid" */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   814
	cs = 0xFF; 
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   815
	/* Special cases for block transfert : in frames with segment data cs is not spécified */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   816
   	if (!err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   817
		if ((whoami == SDO_SERVER) && (d->transfers[line].state == SDO_BLOCK_DOWNLOAD_IN_PROGRESS) ||
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   818
			(whoami == SDO_CLIENT) && (d->transfers[line].state == SDO_BLOCK_UPLOAD_IN_PROGRESS)) {		
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   819
			if(m->data[0] == 0x80)	/* If first byte is 0x80 it is an abort frame (seqno = 0 not allowed) */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   820
				cs = 4;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   821
			else
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   822
				cs = 6;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   823
		}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   824
	}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   825
	/* Other cases : cs is specified */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   826
	if (cs == 0xFF)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   827
		cs = getSDOcs(m->data[0]);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   828
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   829
	/* Testing the command specifier */
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   830
	/* Allowed : cs = 0, 1, 2, 3, 4, 5, 6 */
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   831
	/* cs = other : Not allowed -> abort. */
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   832
	switch (cs) {
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   833
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   834
		case 0:
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   835
			/* I am SERVER */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   836
			if (whoami == SDO_SERVER) {
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
   837
				/* Receiving a download segment data : an SDO transfert should have been yet initiated. */
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   838
				if (!err)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   839
					err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   840
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   841
					MSG_ERR(0x1A70, "SDO error : Received download segment for unstarted trans. index 0x1200 + ",
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   842
							CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   843
					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   844
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   845
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   846
				/* Reset the wathdog */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   847
				RestartSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   848
					MSG_WAR(0x3A71, "Received SDO download segment defined at index 0x1200 + ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   849
				index = d->transfers[line].index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   850
				subIndex = d->transfers[line].subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   851
				/* Toggle test. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   852
				if (d->transfers[line].toggle != getSDOt(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   853
					MSG_ERR(0x1A72, "SDO error : Toggle error : ", getSDOt(m->data[0]));
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   854
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   855
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   856
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   857
				/* Nb of data to be downloaded */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   858
				nbBytes = 7 - getSDOn3(m->data[0]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   859
				/* Store the data in the transfert structure. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   860
				err = SDOtoLine(d, line, nbBytes, (*m).data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   861
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   862
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   863
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   864
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   865
				/* Sending the SDO response, CS = 1 */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   866
				data[0] = (1 << 5) | (d->transfers[line].toggle << 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   867
				for (i = 1 ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   868
					data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   869
				MSG_WAR(0x3A73, "SDO. Send response to download request defined at index 0x1200 + ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   870
				sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   871
				/* Inverting the toggle for the next segment. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   872
				d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   873
				/* If it was the last segment, */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   874
				if (getSDOc(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   875
					/* Transfering line data to object dictionary. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   876
					/* The code does not use the "d" of initiate frame. So it is safe if e=s=0 */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   877
					errorCode = SDOlineToObjdict(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   878
					if (errorCode) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   879
						MSG_ERR(0x1A54, "SDO error : Unable to copy the data in the object dictionary", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   880
						failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   881
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   882
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   883
					/* Release of the line */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   884
					resetSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   885
					MSG_WAR(0x3A74, "SDO. End of download defined at index 0x1200 + ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   886
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   887
			} /* end if SERVER */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   888
			else { /* if CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   889
				/* I am CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   890
				/* It is a request for a previous upload segment. We should find a line opened for this.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   891
				if (!err)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   892
					err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   893
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   894
					MSG_ERR(0x1A75, "SDO error : Received segment response for unknown trans. from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   895
					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   896
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   897
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   898
				/* Reset the wathdog */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   899
				RestartSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   900
					index = d->transfers[line].index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   901
				subIndex = d->transfers[line].subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   902
				/* test of the toggle; */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   903
				if (d->transfers[line].toggle != getSDOt(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   904
					MSG_ERR(0x1A76, "SDO error : Received segment response Toggle error. from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   905
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   906
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   907
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   908
				/* nb of data to be uploaded */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   909
				nbBytes = 7 - getSDOn3(m->data[0]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   910
				/* Storing the data in the line structure. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   911
				err = SDOtoLine(d, line, nbBytes, (*m).data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   912
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   913
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   914
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   915
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   916
				/* Inverting the toggle for the next segment. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   917
				d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   918
				/* If it was the last segment,*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   919
				if ( getSDOc(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   920
					/* Put in state finished */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   921
					/* The code is safe for the case e=s=0 in initiate frame. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   922
					StopSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   923
						d->transfers[line].state = SDO_FINISHED;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   924
					if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   925
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   926
					MSG_WAR(0x3A77, "SDO. End of upload from node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   927
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   928
				else { /* more segments to receive */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   929
					/* Sending the request for the next segment. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   930
					data[0] = (3 << 5) | (d->transfers[line].toggle << 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   931
					for (i = 1 ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   932
						data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   933
					sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   934
					MSG_WAR(0x3A78, "SDO send upload segment request to nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   935
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   936
			} /* End if CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   937
			break;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   938
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   939
		case 1:
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   940
			/* I am SERVER */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   941
			/* Receive of an initiate download */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   942
			if (whoami == SDO_SERVER) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   943
				index = getSDOindex(m->data[1],m->data[2]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   944
				subIndex = getSDOsubIndex(m->data[3]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   945
				MSG_WAR(0x3A79, "Received SDO Initiate Download (to store data) defined at index 0x1200 + ",
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   946
						CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   947
				MSG_WAR(0x3A80, "Writing at index : ", index);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   948
				MSG_WAR(0x3A80, "Writing at subIndex : ", subIndex);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   949
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   950
				/* Search if a SDO transfert have been yet initiated */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   951
				if (! err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   952
					MSG_ERR(0x1A81, "SDO error : Transmission yet started.", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   953
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   954
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   955
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   956
				/* No line on use. Great ! */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   957
				/* Try to open a new line. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   958
				err = getSDOfreeLine( d, whoami, &line );
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   959
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   960
					MSG_ERR(0x1A82, "SDO error : No line free, too many SDO in progress. Aborted.", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   961
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   962
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   963
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   964
				initSDOline(d, line, CliServNbr, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   965
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   966
				if (getSDOe(m->data[0])) { /* If SDO expedited */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   967
					/* nb of data to be downloaded */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   968
					nbBytes = 4 - getSDOn2(m->data[0]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   969
					/* Storing the data in the line structure. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   970
					d->transfers[line].count = nbBytes;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   971
					err = SDOtoLine(d, line, nbBytes, (*m).data + 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   972
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   973
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   974
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   975
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   976
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   977
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   978
					/* SDO expedited -> transfert finished. Data can be stored in the dictionary. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   979
					/*The line will be reseted when it is downloading in the dictionary. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   980
					MSG_WAR(0x3A83, "SDO Initiate Download is an expedited transfert. Finished. ", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   981
					/* Transfering line data to object dictionary. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   982
					errorCode = SDOlineToObjdict(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   983
					if (errorCode) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   984
						MSG_ERR(0x1A84, "SDO error : Unable to copy the data in the object dictionary", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   985
						failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   986
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   987
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   988
					/* Release of the line. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   989
					resetSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   990
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   991
				else {/* So, if it is not an expedited transfert */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   992
					if (getSDOs(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   993
						nbBytes = (m->data[4]) + ((UNS32)(m->data[5])<<8) + ((UNS32)(m->data[6])<<16) + ((UNS32)(m->data[7])<<24);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   994
						err = setSDOlineRestBytes(d, CliServNbr, nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   995
						if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   996
							failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   997
							return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   998
						}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
   999
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1000
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1001
				/*Sending a SDO, cs=3*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1002
				data[0] = 3 << 5;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1003
				data[1] = index & 0xFF;        /* LSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1004
				data[2] = (index >> 8) & 0xFF; /* MSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1005
				data[3] = subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1006
				for (i = 4 ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1007
					data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1008
				sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1009
			} /* end if I am SERVER */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1010
			else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1011
				/* I am CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1012
				/* It is a response for a previous download segment. We should find a line opened for this. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1013
				if (!err)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1014
					err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1015
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1016
					MSG_ERR(0x1A85, "SDO error : Received segment response for unknown trans. from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1017
					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1018
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1019
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1020
				/* Reset the wathdog */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1021
				RestartSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1022
					index = d->transfers[line].index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1023
				subIndex = d->transfers[line].subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1024
				/* test of the toggle; */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1025
				if (d->transfers[line].toggle != getSDOt(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1026
					MSG_ERR(0x1A86, "SDO error : Received segment response Toggle error. from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1027
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1028
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1029
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1030
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1031
				/* End transmission or downloading next segment. We need to know if it will be the last one. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1032
				getSDOlineRestBytes(d, line, &nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1033
				if (nbBytes == 0) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1034
					MSG_WAR(0x3A87, "SDO End download. segment response received. OK. from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1035
					StopSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1036
						d->transfers[line].state = SDO_FINISHED;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1037
					if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1038
					return 0x00;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1039
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1040
				/* At least one transfer to send.	*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1041
				if (nbBytes > 7) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1042
					/* several segments to download.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1043
					/* code to send the next segment. (cs = 0; c = 0) */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1044
					d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1045
					data[0] = (d->transfers[line].toggle << 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1046
					err = lineToSDO(d, line, 7, data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1047
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1048
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1049
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1050
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1051
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1052
				else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1053
					/* Last segment. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1054
					/* code to send the last segment. (cs = 0; c = 1)*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1055
					d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1056
					data[0] = (UNS8)((d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1057
					err = lineToSDO(d, line, nbBytes, data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1058
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1059
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1060
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1061
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1062
					for (i = nbBytes + 1 ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1063
						data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1064
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1065
				MSG_WAR(0x3A88, "SDO sending download segment to nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1066
				sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1067
			} /* end if I am a CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1068
			break;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1069
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1070
		case 2:
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1071
			/* I am SERVER */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1072
			/* Receive of an initiate upload.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1073
			if (whoami == SDO_SERVER) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1074
				index = getSDOindex(m->data[1],m->data[2]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1075
				subIndex = getSDOsubIndex(m->data[3]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1076
				MSG_WAR(0x3A89, "Received SDO Initiate upload (to send data) defined at index 0x1200 + ",
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1077
						CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1078
				MSG_WAR(0x3A90, "Reading at index : ", index);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1079
				MSG_WAR(0x3A91, "Reading at subIndex : ", subIndex);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1080
				/* Search if a SDO transfert have been yet initiated*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1081
				if (! err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1082
					MSG_ERR(0x1A92, "SDO error : Transmission yet started at line : ", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1083
					MSG_WAR(0x3A93, "Server Nbr = ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1084
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1085
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1086
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1087
				/* No line on use. Great !*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1088
				/* Try to open a new line.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1089
				err = getSDOfreeLine( d, whoami, &line );
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1090
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1091
					MSG_ERR(0x1A71, "SDO error : No line free, too many SDO in progress. Aborted.", 0);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1092
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1093
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1094
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1095
				initSDOline(d, line, CliServNbr, index, subIndex, SDO_UPLOAD_IN_PROGRESS);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1096
				/* Transfer data from dictionary to the line structure. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1097
				errorCode = objdictToSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1098
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1099
				if (errorCode) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1100
					MSG_ERR(0x1A94, "SDO error : Unable to copy the data from object dictionary. Err code : ",
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1101
							errorCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1102
					failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1103
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1104
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1105
				/* Preparing the response.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1106
				getSDOlineRestBytes(d, line, &nbBytes);	/* Nb bytes to transfer ? */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1107
				if (nbBytes > 4) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1108
					/* normal transfert. (segmented). */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1109
					/* code to send the initiate upload response. (cs = 2) */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1110
					data[0] = (2 << 5) | 1;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1111
					data[1] = index & 0xFF;        /* LSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1112
					data[2] = (index >> 8) & 0xFF; /* MSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1113
					data[3] = subIndex;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1114
					data[4] = nbBytes; 
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1115
					data[5] = nbBytes >> 8; 
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1116
					data[6] = nbBytes >> 16; 
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1117
					data[7] = nbBytes >> 24; 
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1118
 					MSG_WAR(0x3A95, "SDO. Sending normal upload initiate response defined at index 0x1200 + ", nodeId);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1119
					sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1120
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1121
				else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1122
					/* Expedited upload. (cs = 2 ; e = 1) */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1123
					data[0] = (UNS8)((2 << 5) | ((4 - nbBytes) << 2) | 3);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1124
					data[1] = index & 0xFF;        /* LSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1125
					data[2] = (index >> 8) & 0xFF; /* MSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1126
					data[3] = subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1127
					err = lineToSDO(d, line, nbBytes, data + 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1128
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1129
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1130
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1131
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1132
					for (i = 4 + nbBytes ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1133
						data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1134
					MSG_WAR(0x3A96, "SDO. Sending expedited upload initiate response defined at index 0x1200 + ",
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1135
							CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1136
					sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1137
					/* Release the line.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1138
					resetSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1139
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1140
			} /* end if I am SERVER*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1141
			else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1142
				/* I am CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1143
				/* It is the response for the previous initiate upload request.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1144
				/* We should find a line opened for this. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1145
				if (!err)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1146
					err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1147
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1148
					MSG_ERR(0x1A97, "SDO error : Received response for unknown upload request from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1149
					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1150
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1151
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1152
				/* Reset the wathdog */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1153
				RestartSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1154
					index = d->transfers[line].index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1155
				subIndex = d->transfers[line].subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1156
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1157
				if (getSDOe(m->data[0])) { /* If SDO expedited */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1158
					/* nb of data to be uploaded */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1159
					nbBytes = 4 - getSDOn2(m->data[0]);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1160
					/* Storing the data in the line structure. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1161
					err = SDOtoLine(d, line, nbBytes, (*m).data + 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1162
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1163
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1164
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1165
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1166
					/* SDO expedited -> transfert finished. data are available via  getReadResultNetworkDict(). */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1167
					MSG_WAR(0x3A98, "SDO expedited upload finished. Response received from node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1168
					StopSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1169
						d->transfers[line].count = nbBytes;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1170
					d->transfers[line].state = SDO_FINISHED;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1171
					if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1172
					return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1173
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1174
				else { /* So, if it is not an expedited transfert */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1175
					/* Storing the nb of data to receive. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1176
					if (getSDOs(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1177
						nbBytes = m->data[4] + ((UNS32)(m->data[5])<<8) + ((UNS32)(m->data[6])<<16) + ((UNS32)(m->data[7])<<24);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1178
						err = setSDOlineRestBytes(d, line, nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1179
						if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1180
							failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1181
							return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1182
						}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1183
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1184
					/* Requesting next segment. (cs = 3) */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1185
					data[0] = 3 << 5;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1186
					for (i = 1 ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1187
						data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1188
					MSG_WAR(0x3A99, "SDO. Sending upload segment request to node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1189
					sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1190
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1191
			} /* End if CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1192
			break;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1193
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1194
		case 3:
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1195
			/* I am SERVER */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1196
			if (whoami == SDO_SERVER) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1197
				/* Receiving a upload segment. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1198
				/* A SDO transfert should have been yet initiated. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1199
				if (!err)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1200
					err = d->transfers[line].state != SDO_UPLOAD_IN_PROGRESS;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1201
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1202
					MSG_ERR(0x1AA0, "SDO error : Received upload segment for unstarted trans. index 0x1200 + ",
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1203
							CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1204
					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1205
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1206
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1207
				/* Reset the wathdog */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1208
				RestartSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1209
					MSG_WAR(0x3AA1, "Received SDO upload segment defined at index 0x1200 + ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1210
				index = d->transfers[line].index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1211
				subIndex = d->transfers[line].subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1212
				/* Toggle test.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1213
				if (d->transfers[line].toggle != getSDOt(m->data[0])) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1214
					MSG_ERR(0x1AA2, "SDO error : Toggle error : ", getSDOt(m->data[0]));
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1215
					failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_TOGGLE_NOT_ALTERNED);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1216
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1217
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1218
				/* Uploading next segment. We need to know if it will be the last one. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1219
				getSDOlineRestBytes(d, line, &nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1220
				if (nbBytes > 7) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1221
					/* The segment to transfer is not the last one.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1222
					/* code to send the next segment. (cs = 0; c = 0) */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1223
					data[0] = (d->transfers[line].toggle << 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1224
					err = lineToSDO(d, line, 7, data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1225
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1226
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1227
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1228
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1229
					/* Inverting the toggle for the next tranfert. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1230
					d->transfers[line].toggle = ! d->transfers[line].toggle & 1;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1231
					MSG_WAR(0x3AA3, "SDO. Sending upload segment defined at index 0x1200 + ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1232
					sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1233
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1234
				else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1235
					/* Last segment. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1236
					/* code to send the last segment. (cs = 0; c = 1) */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1237
					data[0] = (UNS8)((d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1238
					err = lineToSDO(d, line, nbBytes, data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1239
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1240
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1241
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1242
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1243
					for (i = nbBytes + 1 ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1244
						data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1245
					MSG_WAR(0x3AA4, "SDO. Sending last upload segment defined at index 0x1200 + ", CliServNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1246
					sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1247
					/* Release the line */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1248
					resetSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1249
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1250
			} /* end if SERVER*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1251
			else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1252
				/* I am CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1253
				/* It is the response for the previous initiate download request. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1254
				/* We should find a line opened for this. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1255
				if (!err)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1256
					err = d->transfers[line].state != SDO_DOWNLOAD_IN_PROGRESS;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1257
				if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1258
					MSG_ERR(0x1AA5, "SDO error : Received response for unknown download request from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1259
					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1260
					return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1261
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1262
				/* Reset the watchdog */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1263
				RestartSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1264
					index = d->transfers[line].index;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1265
				subIndex = d->transfers[line].subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1266
				/* End transmission or requesting  next segment. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1267
				getSDOlineRestBytes(d, line, &nbBytes);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1268
				if (nbBytes == 0) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1269
					MSG_WAR(0x3AA6, "SDO End download expedited. Response received. from nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1270
					StopSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1271
						d->transfers[line].state = SDO_FINISHED;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1272
					if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1273
					return 0x00;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1274
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1275
				if (nbBytes > 7) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1276
					/* more than one request to send */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1277
					/* code to send the next segment. (cs = 0; c = 0)	*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1278
					data[0] = (d->transfers[line].toggle << 4);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1279
					err = lineToSDO(d, line, 7, data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1280
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1281
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1282
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1283
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1284
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1285
				else {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1286
					/* Last segment.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1287
					/* code to send the last segment. (cs = 0; c = 1)	*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1288
					data[0] = (UNS8)((d->transfers[line].toggle << 4) | ((7 - nbBytes) << 1) | 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1289
					err = lineToSDO(d, line, nbBytes, data + 1);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1290
					if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1291
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1292
						return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1293
					}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1294
					for (i = nbBytes + 1 ; i < 8 ; i++)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1295
						data[i] = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1296
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1297
				MSG_WAR(0x3AA7, "SDO sending download segment to nodeId", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1298
				sendSDO(d, whoami, CliServNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1299
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1300
			} /* end if I am a CLIENT		*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1301
			break;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1302
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1303
		case 4:
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1304
			abortCode =
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1305
				(UNS32)m->data[4] |
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1306
				((UNS32)m->data[5] << 8) |
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1307
				((UNS32)m->data[6] << 16) |
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1308
				((UNS32)m->data[7] << 24);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1309
			/* Received SDO abort. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1310
			if (whoami == SDO_SERVER) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1311
				if (!err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1312
					resetSDOline( d, line );
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1313
					MSG_WAR(0x3AA8, "SD0. Received SDO abort. Line released. Code : ", abortCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1314
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1315
				else
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1316
					MSG_WAR(0x3AA9, "SD0. Received SDO abort. No line found. Code : ", abortCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1317
				/* Tips : The end user has no way to know that the server node has received an abort SDO. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1318
				/* Its is ok, I think.*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1319
			}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1320
			else { /* If I am CLIENT */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1321
				if (!err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1322
					/* The line *must* be released by the core program. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1323
					StopSDO_TIMER(line)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1324
						d->transfers[line].state = SDO_ABORTED_RCV;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1325
					d->transfers[line].abortCode = abortCode;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1326
					MSG_WAR(0x3AB0, "SD0. Received SDO abort. Line state ABORTED. Code : ", abortCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1327
					if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1328
				}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1329
				else
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1330
					MSG_WAR(0x3AB1, "SD0. Received SDO abort. No line found. Code : ", abortCode);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1331
			}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1332
			break;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1333
		case 5: /* Command specifier for data transmission - the client or server is the data producer */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1334
			SubCommand = getSDOblockSC(m->data[0]);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1335
			if (whoami == SDO_SERVER) { /* Server block upload */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1336
				if (SubCommand == SDO_BCS_INITIATE_UPLOAD_REQUEST) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1337
				    index = getSDOindex(m->data[1],m->data[2]);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1338
				    subIndex = getSDOsubIndex(m->data[3]);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1339
				    MSG_WAR(0x3AB2, "Received SDO Initiate block upload defined at index 0x1200 + ",
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1340
						CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1341
				    MSG_WAR(0x3AB3, "Reading at index : ", index);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1342
				    MSG_WAR(0x3AB4, "Reading at subIndex : ", subIndex);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1343
				    /* Search if a SDO transfert have been yet initiated */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1344
				    if (! err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1345
					    MSG_ERR(0x1A93, "SDO error : Transmission yet started at line : ", line);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1346
					    MSG_WAR(0x3AB5, "Server Nbr = ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1347
					    failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1348
					    return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1349
				    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1350
				    /* No line on use. Great !*/
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1351
				    /* Try to open a new line.*/
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1352
				    err = getSDOfreeLine( d, whoami, &line );
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1353
				    if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1354
					    MSG_ERR(0x1A73, "SDO error : No line free, too many SDO in progress. Aborted.", 0);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1355
					    failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1356
					    return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1357
				    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1358
				    initSDOline(d, line, CliServNbr, index, subIndex, SDO_BLOCK_UPLOAD_IN_PROGRESS);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1359
                    d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1360
                    d->transfers[line].blksize = m->data[4];
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1361
				    /* Transfer data from dictionary to the line structure. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1362
				    errorCode = objdictToSDOline(d, line);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1363
				    if (errorCode) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1364
					    MSG_ERR(0x1A95, "SDO error : Unable to copy the data from object dictionary. Err code : ",
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1365
							errorCode);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1366
					    failedSDO(d, CliServNbr, whoami, index, subIndex, errorCode);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1367
					    return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1368
				    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1369
 				    /* Preparing the response.*/
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1370
				    getSDOlineRestBytes(d, line, &nbBytes);	/* get Nb bytes to transfer */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1371
                    d->transfers[line].objsize = nbBytes;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1372
                    data[0] = (6 << 5) | (1 << 1) | SDO_BSS_INITIATE_UPLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1373
					data[1] = index & 0xFF;        /* LSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1374
					data[2] = (index >> 8) & 0xFF; /* MSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1375
					data[3] = subIndex;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1376
					data[4] = nbBytes;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1377
					data[5] = nbBytes >> 8;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1378
					data[6] = nbBytes >> 16;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1379
					data[7] = nbBytes >> 24;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1380
					MSG_WAR(0x3A9A, "SDO. Sending normal block upload initiate response defined at index 0x1200 + ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1381
					sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1382
                }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1383
				else if (SubCommand == SDO_BCS_END_UPLOAD_REQUEST) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1384
				    MSG_WAR(0x3AA2, "Received SDO block END upload request defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1385
 				    /* A SDO transfert should have been yet initiated. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1386
				    if (!err)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1387
					    err = d->transfers[line].state != SDO_BLOCK_UPLOAD_IN_PROGRESS;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1388
				    if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1389
					    MSG_ERR(0x1AA1, "SDO error : Received block upload request for unstarted trans. index 0x1200 + ",
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1390
							    CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1391
					    failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1392
					    return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1393
				    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1394
                    /* Release the line */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1395
					resetSDOline(d, line);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1396
                }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1397
				else if ((SubCommand == SDO_BCS_UPLOAD_RESPONSE) || (SubCommand == SDO_BCS_START_UPLOAD)) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1398
 				    /* A SDO transfert should have been yet initiated. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1399
				    if (!err)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1400
					    err = d->transfers[line].state != SDO_BLOCK_UPLOAD_IN_PROGRESS;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1401
				    if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1402
					    MSG_ERR(0x1AA1, "SDO error : Received block upload response for unstarted trans. index 0x1200 + ",
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1403
							    CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1404
					    failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1405
					    return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1406
				    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1407
				    /* Reset the wathdog */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1408
				    RestartSDO_TIMER(line);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1409
				    /* Uploading first or next block */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1410
				    index = d->transfers[line].index;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1411
				    subIndex = d->transfers[line].subIndex;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1412
                    if (SubCommand == SDO_BCS_UPLOAD_RESPONSE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1413
					    MSG_WAR(0x3AA2, "Received SDO block upload response defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1414
                        d->transfers[line].blksize = m->data[2];
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1415
                        AckSeq = (m->data[1]) & 0x7f;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1416
                        getSDOlineRestBytes(d, line, &nbBytes);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1417
                        if((nbBytes == 0) && (AckSeq == d->transfers[line].seqno)){ /* Si tout est envoyé et confirmé reçu on envoi un block end upload response */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1418
                            data[0] = (6 << 5) | ((d->transfers[line].endfield) << 2) | SDO_BSS_END_UPLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1419
                            for (i = 1 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1420
						        data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1421
					        MSG_WAR(0x3AA5, "SDO. Sending block END upload response defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1422
					        sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1423
                            break;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1424
                        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1425
                        else
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1426
                            d->transfers[line].offset = d->transfers[line].lastblockoffset + 7 * AckSeq;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1427
                        if(d->transfers[line].offset > d->transfers[line].count) { /* Bad AckSeq reveived (too high) */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1428
					        MSG_ERR(0x1AA1, "SDO error : Received upload response with bad ackseq index 0x1200 + ",
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1429
							    CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1430
					        failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1431
					        return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1432
                        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1433
           			}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1434
                    else
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1435
					    MSG_WAR(0x3AA2, "Received SDO block START upload defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1436
                    d->transfers[line].lastblockoffset = d->transfers[line].offset;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1437
                    for(SeqNo = 1 ; SeqNo <= d->transfers[line].blksize ; SeqNo++) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1438
                        d->transfers[line].seqno = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1439
				        getSDOlineRestBytes(d, line, &nbBytes);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1440
                        if (nbBytes > 7) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1441
					        /* The segment to transfer is not the last one.*/
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1442
 					        data[0] = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1443
					        err = lineToSDO(d, line, 7, data + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1444
					        if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1445
						        failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1446
						        return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1447
					        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1448
					        MSG_WAR(0x3AA5, "SDO. Sending upload segment defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1449
					        sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1450
				        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1451
				        else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1452
					        /* Last segment is in this block */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1453
					        data[0] = 0x80 | SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1454
					        err = lineToSDO(d, line, nbBytes, data + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1455
					        if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1456
						        failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1457
						        return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1458
					        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1459
					        for (i = nbBytes + 1 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1460
						        data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1461
					        MSG_WAR(0x3AA5, "SDO. Sending last upload segment defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1462
					        sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1463
                            d->transfers[line].endfield = 7 - nbBytes;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1464
                            break;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1465
				        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1466
                    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1467
                }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1468
			}      /* end if SERVER */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1469
			else { /* if CLIENT (block download) */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1470
                if ((SubCommand == SDO_BSS_INITIATE_DOWNLOAD_RESPONSE) || (SubCommand == SDO_BSS_DOWNLOAD_RESPONSE)) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1471
                    /* We should find a line opened for this. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1472
                    if (!err)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1473
                        err = d->transfers[line].state != SDO_BLOCK_DOWNLOAD_IN_PROGRESS;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1474
                    if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1475
                        MSG_ERR(0x1AAA, "SDO error : Received response for unknown block download request from node id", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1476
                        failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1477
                        return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1478
                    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1479
                    /* Reset the watchdog */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1480
                    RestartSDO_TIMER(line)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1481
                    if (SubCommand == SDO_BSS_INITIATE_DOWNLOAD_RESPONSE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1482
                           index = d->transfers[line].index;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1483
                        subIndex = d->transfers[line].subIndex;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1484
                        d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1485
                        d->transfers[line].blksize = m->data[4];
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1486
                    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1487
                    else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1488
                    	d->transfers[line].blksize = m->data[2];
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1489
                        AckSeq = (m->data[1]) & 0x7f;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1490
                        getSDOlineRestBytes(d, line, &nbBytes);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1491
                        if((nbBytes == 0) && (AckSeq == d->transfers[line].seqno)){ /* Si tout est envoyé et confirmé reçu on envoi un block end download request */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1492
                            data[0] = (6 << 5) | ((d->transfers[line].endfield) << 2) | SDO_BCS_END_DOWNLOAD_REQUEST;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1493
                            for (i = 1 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1494
						        data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1495
					        MSG_WAR(0x3AA5, "SDO. Sending block END download request defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1496
					        sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1497
                            break;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1498
                        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1499
                        else
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1500
                            d->transfers[line].offset = d->transfers[line].lastblockoffset + 7 * AckSeq;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1501
                        if(d->transfers[line].offset > d->transfers[line].count) { /* Bad AckSeq reveived (too high) */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1502
					        MSG_ERR(0x1AA1, "SDO error : Received upload segment with bad ackseq index 0x1200 + ",
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1503
							    CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1504
					        failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1505
					        return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1506
                        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1507
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1508
                 	d->transfers[line].lastblockoffset = d->transfers[line].offset;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1509
                	for(SeqNo = 1 ; SeqNo <= d->transfers[line].blksize ; SeqNo++) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1510
                        d->transfers[line].seqno = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1511
				        getSDOlineRestBytes(d, line, &nbBytes);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1512
                        if (nbBytes > 7) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1513
					        /* The segment to transfer is not the last one.*/
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1514
 					        data[0] = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1515
					        err = lineToSDO(d, line, 7, data + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1516
					        if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1517
						        failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1518
						        return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1519
					        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1520
					        MSG_WAR(0x3AAB, "SDO. Sending download segment to node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1521
					        sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1522
				        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1523
				        else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1524
					        /* Last segment is in this block */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1525
					        data[0] = 0x80 | SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1526
					        err = lineToSDO(d, line, nbBytes, data + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1527
					        if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1528
						        failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1529
						        return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1530
					        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1531
					        for (i = nbBytes + 1 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1532
						        data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1533
					        MSG_WAR(0x3AAB, "SDO. Sending last download segment to node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1534
					        sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1535
                            d->transfers[line].endfield = 7 - nbBytes;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1536
                            break;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1537
				        }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1538
                    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1539
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1540
				else if (SubCommand == SDO_BSS_END_DOWNLOAD_RESPONSE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1541
					MSG_WAR(0x3AAC, "SDO End block download response from nodeId", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1542
					StopSDO_TIMER(line)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1543
					d->transfers[line].state = SDO_FINISHED;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1544
					if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1545
					return 0x00;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1546
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1547
				else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1548
			    	MSG_ERR(0x1AAB, "SDO error block download : Received wrong subcommand from nodeId", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1549
    				failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1550
	    			return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1551
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1552
			}      /* end if CLIENT */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1553
			break;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1554
		case 6: /* Command specifier for data reception - the client or server is the data consumer */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1555
			if (whoami == SDO_SERVER) { /* Server block download */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1556
				if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1557
					/* Nothing already started */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1558
					SubCommand = (m->data[0]) & 1;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1559
					if (SubCommand != SDO_BCS_INITIATE_DOWNLOAD_REQUEST) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1560
			    	    MSG_ERR(0x1AAC, "SDO error block download : Received wrong subcommand from node id", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1561
    				    failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1562
	    			    return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1563
				    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1564
					index = getSDOindex(m->data[1],m->data[2]);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1565
					subIndex = getSDOsubIndex(m->data[3]);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1566
					MSG_WAR(0x3A9B, "Received SDO block download initiate defined at index 0x1200 + ",
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1567
						CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1568
					MSG_WAR(0x3A9B, "Writing at index : ", index);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1569
					MSG_WAR(0x3A9B, "Writing at subIndex : ", subIndex);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1570
					/* Try to open a new line. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1571
					err = getSDOfreeLine( d, whoami, &line );
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1572
					if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1573
						MSG_ERR(0x1A89, "SDO error : No line free, too many SDO in progress. Aborted.", 0);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1574
						failedSDO(d, CliServNbr, whoami, index, subIndex, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1575
						return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1576
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1577
					initSDOline(d, line, CliServNbr, index, subIndex, SDO_BLOCK_DOWNLOAD_IN_PROGRESS);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1578
                    d->transfers[line].rxstep = RXSTEP_STARTED;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1579
                    d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1580
					if ((m->data[0]) & 2)	/* if data set size is indicated */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1581
                    	d->transfers[line].objsize = (UNS32)m->data[4] + (UNS32)m->data[5]*256 + (UNS32)m->data[6]*256*256 + (UNS32)m->data[7]*256*256*256;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1582
                    data[0] = (5 << 5) | SDO_BSS_INITIATE_DOWNLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1583
					data[1] = index;        /* LSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1584
					data[2] = index >> 8;   /* MSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1585
					data[3] = subIndex;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1586
					data[4] = SDO_BLOCK_SIZE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1587
					data[5] = data[6] = data[7] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1588
					MSG_WAR(0x3AAD, "SDO. Sending block download initiate response - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1589
					sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1590
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1591
				else if (d->transfers[line].rxstep == RXSTEP_STARTED) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1592
					MSG_WAR(0x3A9B, "Received SDO block download data segment - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1593
    		    	RestartSDO_TIMER(line)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1594
					SeqNo = m->data[0] & 0x7F;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1595
					if (m->data[0] & 0x80) {	/* Last segment ? */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1596
					    if(SeqNo == (d->transfers[line].seqno + 1)) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1597
							d->transfers[line].rxstep = RXSTEP_END;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1598
							d->transfers[line].seqno = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1599
							/* Store the data temporary because we don't know yet how many bytes do not contain data */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1600
							memcpy(d->transfers[line].tmpData, m->data, 8);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1601
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1602
						data[0] = (5 << 5) | SDO_BSS_DOWNLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1603
						data[1] = d->transfers[line].seqno;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1604
						data[2] = SDO_BLOCK_SIZE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1605
						data[3] = data[4] = data[5] = data[6] = data[7] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1606
						MSG_WAR(0x3AAE, "SDO. Sending block download response - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1607
						sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1608
                        d->transfers[line].seqno = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1609
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1610
					else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1611
					   	if (SeqNo == (d->transfers[line].seqno + 1)) {	
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1612
							d->transfers[line].seqno = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1613
							/* Store the data in the transfert structure. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1614
							err = SDOtoLine(d, line, 7, (*m).data + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1615
							if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1616
								failedSDO(d, CliServNbr, whoami, d->transfers[line].index,  d->transfers[line].subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1617
								return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1618
							}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1619
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1620
						if (SeqNo == SDO_BLOCK_SIZE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1621
							data[0] = (5 << 5) | SDO_BSS_DOWNLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1622
							data[1] = d->transfers[line].seqno;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1623
							data[2] = SDO_BLOCK_SIZE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1624
							data[3] = data[4] = data[5] = data[6] = data[7] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1625
							MSG_WAR(0x3AAE, "SDO. Sending block download response - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1626
							sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1627
                            d->transfers[line].seqno = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1628
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1629
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1630
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1631
				else if (d->transfers[line].rxstep == RXSTEP_END) { /* endphase */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1632
					MSG_WAR(0x3A9B, "Received SDO block download end request - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1633
					/* here store remaining bytes in tmpData to line, check size and confirm or abort */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1634
					if ((m->data[0] & 1) != SDO_BCS_END_DOWNLOAD_REQUEST) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1635
		    			MSG_ERR(0x1AAD, "SDO error block download : Received wrong subcommand - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1636
    					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1637
	    				return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1638
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1639
    		    	RestartSDO_TIMER(line)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1640
					NbBytesNoData = (m->data[0]>>2) & 0x07;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1641
					/* Store the data in the transfert structure. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1642
					err = SDOtoLine(d, line, 7-NbBytesNoData, d->transfers[line].tmpData + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1643
					if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1644
						failedSDO(d, CliServNbr, whoami, d->transfers[line].index,  d->transfers[line].subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1645
						return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1646
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1647
					if(d->transfers[line].objsize){ /* If size was indicated in the initiate request */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1648
						if (d->transfers[line].objsize != d->transfers[line].offset){
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1649
		    					MSG_ERR(0x1AAE, "SDO error block download : sizes do not match - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1650
    							failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1651
	    						return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1652
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1653
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1654
					data[0] = (5 << 5) | SDO_BSS_END_DOWNLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1655
					for (i = 1 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1656
						data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1657
					MSG_WAR(0x3AAF, "SDO. Sending block download end response - index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1658
					sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1659
					/* Transfering line data to object dictionary. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1660
					errorCode = SDOlineToObjdict(d, line);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1661
					if (errorCode) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1662
						MSG_ERR(0x1AAF, "SDO error : Unable to copy the data in the object dictionary", 0);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1663
						failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, errorCode);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1664
						return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1665
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1666
					/* Release of the line */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1667
					resetSDOline(d, line);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1668
					MSG_WAR(0x3AAF, "SDO. End of block download defined at index 0x1200 + ", CliServNbr);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1669
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1670
		    }      /* end if SERVER */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1671
		    else { /* if CLIENT (block upload) */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1672
				if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1673
       				/* Nothing already started */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1674
			    	MSG_ERR(0x1AAD, "SDO error block upload : no transmission started", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1675
    				failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1676
	    			return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1677
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1678
    			RestartSDO_TIMER(line)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1679
				if (d->transfers[line].rxstep == RXSTEP_INIT) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1680
				    if ((m->data[0] & 1) == SDO_BSS_INITIATE_UPLOAD_RESPONSE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1681
					    MSG_WAR(0x3A9C, "Received SDO block upload response from node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1682
						d->transfers[line].rxstep = RXSTEP_STARTED;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1683
                        d->transfers[line].peerCRCsupport = ((m->data[0])>>2) & 1;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1684
					    if ((m->data[0]) & 2)	/* if data set size is indicated */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1685
                    	    d->transfers[line].objsize = (UNS32)m->data[4] + (UNS32)m->data[5]*256 + (UNS32)m->data[6]*256*256 + (UNS32)m->data[7]*256*256*256;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1686
                        data[0] = (5 << 5) | SDO_BCS_START_UPLOAD;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1687
					    for (i = 1 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1688
						    data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1689
                        MSG_WAR(0x3AB6, "SDO. Sending block upload start to node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1690
					    sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1691
                    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1692
                }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1693
				else if (d->transfers[line].rxstep == RXSTEP_STARTED) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1694
					SeqNo = m->data[0] & 0x7F;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1695
					if (m->data[0] & 0x80) {	/* Last segment ? */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1696
					    if(SeqNo == (d->transfers[line].seqno + 1)) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1697
							d->transfers[line].rxstep = RXSTEP_END;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1698
							d->transfers[line].seqno = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1699
							/* Store the data temporary because we don't know yet how many bytes do not contain data */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1700
							memcpy(d->transfers[line].tmpData, m->data, 8);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1701
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1702
						data[0] = (5 << 5) | SDO_BCS_UPLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1703
						data[1] = d->transfers[line].seqno;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1704
						data[2] = SDO_BLOCK_SIZE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1705
						data[3] = data[4] = data[5] = data[6] = data[7] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1706
						MSG_WAR(0x3AB7, "SDO. Sending block upload response to node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1707
						sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1708
                        d->transfers[line].seqno = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1709
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1710
					else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1711
					   	if (SeqNo == (d->transfers[line].seqno + 1)) {	
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1712
							d->transfers[line].seqno = SeqNo;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1713
							/* Store the data in the transfert structure. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1714
							err = SDOtoLine(d, line, 7, (*m).data + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1715
							if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1716
								failedSDO(d, CliServNbr, whoami, d->transfers[line].index,  d->transfers[line].subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1717
								return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1718
							}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1719
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1720
						if (SeqNo == SDO_BLOCK_SIZE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1721
							data[0] = (5 << 5) | SDO_BCS_UPLOAD_RESPONSE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1722
							data[1] = d->transfers[line].seqno;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1723
							data[2] = SDO_BLOCK_SIZE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1724
							data[3] = data[4] = data[5] = data[6] = data[7] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1725
							MSG_WAR(0x3AAE, "SDO. Sending block upload response to node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1726
							sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1727
                            d->transfers[line].seqno = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1728
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1729
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1730
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1731
				else if (d->transfers[line].rxstep == RXSTEP_END) { /* endphase */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1732
					/* here store remaining bytes in tmpData to line, check size and confirm or abort */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1733
					if ((m->data[0] & 1) != SDO_BSS_END_UPLOAD_RESPONSE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1734
			    		MSG_ERR(0x1AAD, "SDO error block upload : Received wrong subcommand from node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1735
    					failedSDO(d, CliServNbr, whoami, 0, 0, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1736
	    				return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1737
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1738
					NbBytesNoData = (m->data[0]>>2) & 0x07;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1739
					/* Store the data in the transfert structure. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1740
					err = SDOtoLine(d, line, 7-NbBytesNoData, d->transfers[line].tmpData + 1);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1741
					if (err) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1742
						failedSDO(d, CliServNbr, whoami, d->transfers[line].index,  d->transfers[line].subIndex, SDOABT_GENERAL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1743
						return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1744
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1745
					if(d->transfers[line].objsize){ /* If size was indicated in the initiate request */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1746
						if (d->transfers[line].objsize != d->transfers[line].offset){
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1747
			    				MSG_ERR(0x1AAE, "SDO error block download : sizes do not match - from node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1748
    							failedSDO(d, CliServNbr, whoami, d->transfers[line].index, d->transfers[line].subIndex, SDOABT_LOCAL_CTRL_ERROR);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1749
	    						return 0xFF;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1750
						}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1751
					}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1752
					data[0] = (5 << 5) | SDO_BCS_END_UPLOAD_REQUEST;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1753
					for (i = 1 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1754
						data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1755
					MSG_WAR(0x3AAF, "SDO. Sending block upload end request to node id ", nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1756
					sendSDO(d, whoami, CliServNbr, data);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1757
					MSG_WAR(0x3AAF, "SDO. End of block upload request", 0);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1758
                    StopSDO_TIMER(line)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1759
					d->transfers[line].state = SDO_FINISHED;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1760
				    if(d->transfers[line].Callback) (*d->transfers[line].Callback)(d,nodeId);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1761
				}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1762
			}      /* end if CLIENT */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1763
			break;
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1764
		default:
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1765
			/* Error : Unknown cs */
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1766
			MSG_ERR(0x1AB2, "SDO. Received unknown command specifier : ", cs);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1767
			return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1768
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1769
	} /* End switch */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1770
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1771
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1772
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1773
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1774
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1775
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1776
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1777
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1778
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1779
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1780
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1781
 ** 	0xFF : No SDO client available
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1782
 **     0xFE : Not found
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1783
 **     otherwise : SDO client number
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1784
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1785
UNS8 GetSDOClientFromNodeId( CO_Data* d, UNS8 nodeId )
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1786
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1787
	UNS8 SDOfound = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1788
	UNS8 CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1789
	UNS16 lastIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1790
	UNS16 offset;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1791
	UNS8 nodeIdServer;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1792
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1793
	offset = d->firstIndex->SDO_CLT;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1794
	lastIndex = d->lastIndex->SDO_CLT;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1795
	if (offset == 0) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1796
		MSG_ERR(0x1AC6, "No SDO client index found for nodeId ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1797
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1798
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1799
	CliNbr = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1800
	while (offset <= lastIndex) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1801
		if (d->objdict[offset].bSubCount <= 3) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1802
			MSG_ERR(0x1AC8, "Subindex 3  not found at index ", 0x1280 + CliNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1803
			return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1804
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1805
		/* looking for the server nodeId */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1806
		nodeIdServer = *((UNS8*) d->objdict[offset].pSubindex[3].pObject);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1807
		MSG_WAR(0x1AD2, "index : ", 0x1280 + CliNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1808
		MSG_WAR(0x1AD3, "nodeIdServer : ", nodeIdServer);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1809
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1810
		if(nodeIdServer == nodeId) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1811
			SDOfound = 1;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1812
			break;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1813
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1814
		offset++;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1815
		CliNbr++;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1816
	} /* end while */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1817
	if (!SDOfound) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1818
		MSG_ERR(0x1AC9, "SDO. Error. No client found to communicate with node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1819
		return 0xFE;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1820
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1821
	MSG_WAR(0x3AD0,"        SDO client defined at index  : ", 0x1280 + CliNbr);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1822
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1823
	return CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1824
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1825
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1826
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1827
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1828
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1829
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1830
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1831
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1832
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1833
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1834
 ** @param count
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1835
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1836
 ** @param data
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1837
 ** @param Callback
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1838
 ** @param endianize
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1839
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1840
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1841
 **/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1842
INLINE UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1843
		UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize, UNS8 useBlockMode)
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1844
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1845
	UNS8 err;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1846
	UNS8 line;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1847
	UNS8 CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1848
	UNS32 j;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1849
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1850
	UNS8 buf[8];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1851
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1852
	MSG_WAR(0x3AC0, "Send SDO to write in the dictionary of node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1853
	MSG_WAR(0x3AC1, "                                   At index : ", index);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1854
	MSG_WAR(0x3AC2, "                                   subIndex : ", subIndex);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1855
	MSG_WAR(0x3AC3, "                                   nb bytes : ", count);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1856
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1857
	/* First let's find the corresponding SDO client in our OD  */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1858
	CliNbr = GetSDOClientFromNodeId( d, nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1859
	if(CliNbr >= 0xFE)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1860
		return CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1861
	/* Verify that there is no SDO communication yet. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1862
	err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1863
	if (!err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1864
		MSG_ERR(0x1AC4, "SDO error : Communication yet established. with node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1865
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1866
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1867
	/* Taking the line ... */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1868
	err = getSDOfreeLine( d, SDO_CLIENT, &line );
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1869
	if (err) {
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1870
		MSG_ERR(0x1AC5, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1871
		return (0xFF);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1872
	}
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1873
    if(useBlockMode) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1874
	    initSDOline(d, line, CliNbr, index, subIndex, SDO_BLOCK_DOWNLOAD_IN_PROGRESS);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1875
	    d->transfers[line].objsize = count;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1876
    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1877
    else 
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1878
	    initSDOline(d, line, CliNbr, index, subIndex, SDO_DOWNLOAD_IN_PROGRESS);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1879
	d->transfers[line].count = count;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1880
	d->transfers[line].dataType = dataType;
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1881
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1882
	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1883
		UNS8* lineData = d->transfers[line].data;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1884
		if (count > SDO_MAX_LENGTH_TRANSFERT)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1885
		{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1886
			d->transfers[line].dynamicData = (UNS8*) malloc(count);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1887
			d->transfers[line].dynamicDataSize = count;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1888
			if (d->transfers[line].dynamicData == NULL)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1889
			{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1890
				MSG_ERR(0x1AC9, "SDO. Error. Could not allocate enough bytes : ", count);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1891
				return 0xFE;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1892
			}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1893
			lineData = d->transfers[line].dynamicData;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1894
		}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1895
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1896
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1897
		/* Copy data to transfers structure. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1898
		for (j = 0 ; j < count ; j++) {
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1899
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1900
# ifdef CANOPEN_BIG_ENDIAN
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1901
			if (dataType == 0 && endianize)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1902
				lineData[count - 1 - j] = ((char *)data)[j];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1903
			else /* String of bytes. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1904
				lineData[j] = ((char *)data)[j];
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1905
#  else
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1906
			lineData[j] = ((char *)data)[j];
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1907
#  endif
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1908
		}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1909
#else //SDO_DYNAMIC_BUFFER_ALLOCATION
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1910
# ifdef CANOPEN_BIG_ENDIAN
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1911
		if (dataType == 0 && endianize)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1912
			d->transfers[line].data[count - 1 - j] = ((char *)data)[j];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1913
		else /* String of bytes. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1914
			d->transfers[line].data[j] = ((char *)data)[j];
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1915
#  else
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1916
		d->transfers[line].data[j] = ((char *)data)[j];
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  1917
#  endif
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  1918
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1919
	}
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1920
    if(useBlockMode) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1921
	    buf[0] = (6 << 5) | (1 << 1 );   /* CCS = 6 , CC = 0 , S = 1 , CS = 0 */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1922
 	    for (i = 0 ; i < 4 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1923
		    buf[i+4] = (UNS8)((count >> (i<<3))); /* i*8 */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1924
    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1925
    else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1926
	    /* Send the SDO to the server. Initiate download, cs=1. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1927
	    if (count <= 4) { /* Expedited transfert */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1928
		    buf[0] = (UNS8)((1 << 5) | ((4 - count) << 2) | 3);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1929
		    for (i = 4 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1930
			    buf[i] = d->transfers[line].data[i - 4];
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1931
		    d->transfers[line].offset = count;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1932
	    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1933
	    else { /** Normal transfert */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1934
		    buf[0] = (1 << 5) | 1;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1935
		    for (i = 0 ; i < 4 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1936
			    buf[i+4] = (UNS8)((count >> (i<<3))); /* i*8 */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1937
	    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1938
    }
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1939
	buf[1] = index & 0xFF;        /* LSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1940
	buf[2] = (index >> 8) & 0xFF; /* MSB */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1941
	buf[3] = subIndex;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1942
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1943
	d->transfers[line].Callback = Callback;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1944
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1945
	err = sendSDO(d, SDO_CLIENT, CliNbr, buf);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1946
	if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1947
		MSG_ERR(0x1AD1, "SDO. Error while sending SDO to node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1948
		/* release the line */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1949
		resetSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1950
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1951
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1952
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1953
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1954
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1955
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1956
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1957
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1958
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1959
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1960
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1961
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1962
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1963
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1964
 ** @param count
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1965
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1966
 ** @param data
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1967
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1968
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1969
 **/
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1970
UNS8 writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1971
		UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, UNS8 useBlockMode)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1972
{
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1973
	return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, NULL, 1, useBlockMode);
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1974
}
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  1975
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1976
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1977
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1978
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1979
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1980
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1981
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1982
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1983
 ** @param count
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1984
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1985
 ** @param data
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1986
 ** @param Callback
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1987
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1988
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  1989
 **/
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1990
UNS8 writeNetworkDictCallBack (CO_Data* d, UNS8 nodeId, UNS16 index,
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1991
		UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 useBlockMode)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1992
{
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1993
	return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, 1, useBlockMode);
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1994
}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1995
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1996
UNS8 writeNetworkDictCallBackAI (CO_Data* d, UNS8 nodeId, UNS16 index,
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  1997
		UNS8 subIndex, UNS32 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize, UNS8 useBlockMode)
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1998
{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  1999
	UNS8 ret;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2000
	UNS16 lastIndex;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2001
	UNS16 offset;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2002
	UNS8 nodeIdServer;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2003
	UNS8 i;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2004
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2005
	ret = _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, endianize, useBlockMode);
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2006
	if(ret == 0xFE)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2007
	{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2008
		offset = d->firstIndex->SDO_CLT;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2009
		lastIndex = d->lastIndex->SDO_CLT;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2010
		if (offset == 0)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2011
		{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2012
			MSG_ERR(0x1AC6, "writeNetworkDict : No SDO client index found", 0);
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2013
			return 0xFF;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2014
		}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2015
		i = 0;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2016
		while (offset <= lastIndex)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2017
		{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2018
			if (d->objdict[offset].bSubCount <= 3)
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2019
			{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2020
				MSG_ERR(0x1AC8, "Subindex 3  not found at index ", 0x1280 + i);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2021
				return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2022
			}
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2023
			nodeIdServer = *(UNS8*) d->objdict[offset].pSubindex[3].pObject;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2024
			if(nodeIdServer == 0)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2025
			{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2026
				*(UNS32*)d->objdict[offset].pSubindex[1].pObject = (UNS32)(0x600 + nodeId);
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2027
				*(UNS32*)d->objdict[offset].pSubindex[2].pObject = (UNS32)(0x580 + nodeId);
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2028
				*(UNS8*) d->objdict[offset].pSubindex[3].pObject = nodeId;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2029
				return _writeNetworkDict (d, nodeId, index, subIndex, count, dataType, data, Callback, 1, useBlockMode);
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2030
			}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2031
			offset++;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2032
		}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2033
		return 0xFF;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2034
	}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2035
	else if(ret == 0)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2036
	{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2037
		return 0;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2038
	}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2039
	else
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2040
	{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2041
		return 0xFF;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2042
	}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2043
}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2044
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2045
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2046
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2047
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2048
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2049
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2050
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2051
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2052
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2053
 ** @param Callback
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2054
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2055
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2056
 **/
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2057
INLINE UNS8 _readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  2058
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2059
	UNS8 err;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2060
	UNS8 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2061
	UNS8 CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2062
	UNS8 line;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2063
	UNS8 data[8];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2064
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2065
	MSG_WAR(0x3AD5, "Send SDO to read in the dictionary of node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2066
	MSG_WAR(0x3AD6, "                                  At index : ", index);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2067
	MSG_WAR(0x3AD7, "                                  subIndex : ", subIndex);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2068
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2069
	/* First let's find the corresponding SDO client in our OD  */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2070
	CliNbr = GetSDOClientFromNodeId( d, nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2071
	if(CliNbr >= 0xFE)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2072
		return CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2073
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2074
	/* Verify that there is no SDO communication yet. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2075
	err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2076
	if (!err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2077
		MSG_ERR(0x1AD8, "SDO error : Communication yet established. with node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2078
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2079
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2080
	/* Taking the line ... */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2081
	err = getSDOfreeLine( d, SDO_CLIENT, &line );
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2082
	if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2083
		MSG_ERR(0x1AD9, "SDO error : No line free, too many SDO in progress. Aborted for node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2084
		return (0xFF);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2085
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2086
	else
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2087
		MSG_WAR(0x3AE0, "Transmission on line : ", line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2088
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2089
    if(useBlockMode) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2090
	    initSDOline(d, line, CliNbr, index, subIndex, SDO_BLOCK_UPLOAD_IN_PROGRESS);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2091
	    /* Send the SDO to the server. Initiate block upload, cs=0. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2092
	    d->transfers[line].dataType = dataType;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2093
	    data[0] = (5 << 5) | SDO_BCS_INITIATE_UPLOAD_REQUEST;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2094
	    data[1] = index & 0xFF;        /* LSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2095
	    data[2] = (index >> 8) & 0xFF; /* MSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2096
	    data[3] = subIndex;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2097
	    data[4] = SDO_BLOCK_SIZE;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2098
	    for (i = 5 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2099
		    data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2100
    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2101
    else {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2102
	    initSDOline(d, line, CliNbr, index, subIndex, SDO_UPLOAD_IN_PROGRESS);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2103
	    /* Send the SDO to the server. Initiate upload, cs=2. */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2104
	    d->transfers[line].dataType = dataType;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2105
	    data[0] = (2 << 5);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2106
	    data[1] = index & 0xFF;        /* LSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2107
	    data[2] = (index >> 8) & 0xFF; /* MSB */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2108
	    data[3] = subIndex;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2109
	    for (i = 4 ; i < 8 ; i++)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2110
		    data[i] = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2111
    }
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2112
	d->transfers[line].Callback = Callback;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2113
	err = sendSDO(d, SDO_CLIENT, CliNbr, data);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2114
	if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2115
		MSG_ERR(0x1AE5, "SDO. Error while sending SDO to node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2116
		/* release the line */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2117
		resetSDOline(d, line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2118
		return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2119
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2120
	return 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2121
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2122
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2123
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2124
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2125
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2126
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2127
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2128
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2129
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2130
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2131
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2132
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2133
 **/
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2134
UNS8 readNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, UNS8 useBlockMode)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2135
{
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2136
	return _readNetworkDict (d, nodeId, index, subIndex, dataType, NULL, useBlockMode);
32
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  2137
}
8afa33692372 SDO callbacks.
etisserant
parents: 31
diff changeset
  2138
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2139
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2140
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2141
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2142
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2143
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2144
 ** @param index
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2145
 ** @param subIndex
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2146
 ** @param dataType
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2147
 ** @param Callback
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2148
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2149
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2150
 **/
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2151
UNS8 readNetworkDictCallback (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2152
{
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2153
	return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback, useBlockMode);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2154
}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2155
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2156
UNS8 readNetworkDictCallbackAI (CO_Data* d, UNS8 nodeId, UNS16 index, UNS8 subIndex, UNS8 dataType, SDOCallback_t Callback, UNS8 useBlockMode)
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2157
{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2158
	UNS8 ret;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2159
	UNS16 lastIndex;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2160
	UNS16 offset;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2161
	UNS8 nodeIdServer;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2162
	UNS8 i;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2163
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2164
	ret = _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback, useBlockMode);
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2165
	if(ret == 0xFE)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2166
	{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2167
		offset = d->firstIndex->SDO_CLT;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2168
		lastIndex = d->lastIndex->SDO_CLT;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2169
		if (offset == 0)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2170
		{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2171
			MSG_ERR(0x1AC6, "writeNetworkDict : No SDO client index found", 0);
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2172
			return 0xFF;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2173
		}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2174
		i = 0;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2175
		while (offset <= lastIndex)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2176
		{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2177
			if (d->objdict[offset].bSubCount <= 3)
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2178
			{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2179
				MSG_ERR(0x1AC8, "Subindex 3  not found at index ", 0x1280 + i);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2180
				return 0xFF;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2181
			}
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2182
			nodeIdServer = *(UNS8*) d->objdict[offset].pSubindex[3].pObject;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2183
			if(nodeIdServer == 0)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2184
			{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2185
				*(UNS32*)d->objdict[offset].pSubindex[1].pObject = (UNS32)(0x600 + nodeId);
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2186
				*(UNS32*)d->objdict[offset].pSubindex[2].pObject = (UNS32)(0x580 + nodeId);
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2187
				*(UNS8*) d->objdict[offset].pSubindex[3].pObject = nodeId;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2188
				return _readNetworkDict (d, nodeId, index, subIndex, dataType, Callback, useBlockMode);
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2189
			}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2190
			offset++;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2191
		}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2192
		return 0xFF;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2193
	}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2194
	else if(ret == 0)
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2195
	{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2196
		return 0;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2197
	}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2198
	else
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2199
	{
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2200
		return 0xFF;
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2201
	}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2202
}
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2203
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2204
/*!
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2205
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2206
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2207
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2208
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2209
 ** @param data
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2210
 ** @param size : *size MUST contain the size of *data buffer before calling
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2211
 **                     The function set it to the actual number of written bytes
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2212
 ** @param abortCode
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2213
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2214
 ** @return
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2215
 **    SDO_PROVIDED_BUFFER_TOO_SMALL if *data is not big enough
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2216
 **    or any transmission status value.
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2217
 **/
539
187058b4a4b8 Changed OD size from UNS8 to UNS32, and repercuted change to PDO and SDO. Thanks to Jari Kuusisto for patch.
etisserant
parents: 538
diff changeset
  2218
UNS8 getReadResultNetworkDict (CO_Data* d, UNS8 nodeId, void* data, UNS32 *size,
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2219
		UNS32 * abortCode)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2220
{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2221
	UNS32 i;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2222
	UNS8 err;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2223
	UNS8 CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2224
	UNS8 line;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2225
	* abortCode = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2226
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2227
	/* First let's find the corresponding SDO client in our OD  */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2228
	CliNbr = GetSDOClientFromNodeId(d, nodeId);
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2229
	if(CliNbr >= 0xFE) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2230
        *size = 0;
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2231
		return SDO_ABORTED_INTERNAL;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2232
    }
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2233
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2234
	/* Looking for the line tranfert. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2235
	err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2236
	if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2237
		MSG_ERR(0x1AF0, "SDO error : No line found for communication with node : ", nodeId);
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2238
        *size = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2239
        return SDO_ABORTED_INTERNAL;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2240
	}
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2241
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2242
    /* If transfert not finished just return, but if aborted set abort code and size to 0 */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2243
    if (d->transfers[line].state != SDO_FINISHED) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2244
	    if((d->transfers[line].state == SDO_ABORTED_RCV) || (d->transfers[line].state == SDO_ABORTED_INTERNAL)) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2245
            *abortCode = d->transfers[line].abortCode;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2246
            *size = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2247
        }
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2248
		return d->transfers[line].state;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2249
    }
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2250
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2251
	/* if SDO initiated with e=0 and s=0 count is null, offset carry effective size*/
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2252
	if( d->transfers[line].count == 0)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2253
		d->transfers[line].count = d->transfers[line].offset;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2254
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2255
    /* Check if the provided buffer is big enough */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2256
    if(*size < d->transfers[line].count) {
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2257
		*size = 0;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2258
		return SDO_PROVIDED_BUFFER_TOO_SMALL;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2259
    }
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2260
	
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2261
    /* Give back actual size */
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2262
    *size = d->transfers[line].count;
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2263
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2264
	/* Copy payload to data pointer */
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  2265
#ifdef SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2266
	{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2267
		UNS8 *lineData = d->transfers[line].data;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2268
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2269
		if (d->transfers[line].dynamicData && d->transfers[line].dynamicDataSize)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2270
		{
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2271
			lineData = d->transfers[line].dynamicData;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2272
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2273
		for  ( i = 0 ; i < *size ; i++) {
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  2274
# ifdef CANOPEN_BIG_ENDIAN
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2275
			if (d->transfers[line].dataType != visible_string)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2276
				( (char *) data)[*size - 1 - i] = lineData[i];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2277
			else /* String of bytes. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2278
				( (char *) data)[i] = lineData[i];
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  2279
# else
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2280
			( (char *) data)[i] = lineData[i];
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  2281
# endif
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2282
		}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2283
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  2284
#else //SDO_DYNAMIC_BUFFER_ALLOCATION
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2285
	for  ( i = 0 ; i < *size ; i++) {
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  2286
# ifdef CANOPEN_BIG_ENDIAN
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2287
		if (d->transfers[line].dataType != visible_string)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2288
			( (char *) data)[*size - 1 - i] = d->transfers[line].data[i];
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2289
		else /* String of bytes. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2290
			( (char *) data)[i] = d->transfers[line].data[i];
506
c17e2e17aca8 Patch from Jari K. implementing automatic SDO clien allocation, and add a new interface for (read/write)networkdict.
etisserant
parents: 503
diff changeset
  2291
# else
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2292
		( (char *) data)[i] = d->transfers[line].data[i];
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  2293
# endif
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2294
	}
636
033fe6f1ec3c ADDED: - dynamic memory allocation for sdo transfer using malloc and free
Christian Taedcke
parents: 627
diff changeset
  2295
#endif //SDO_DYNAMIC_BUFFER_ALLOCATION
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2296
    resetSDOline(d, line);
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2297
	return SDO_FINISHED;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2298
}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2299
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2300
/*!
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2301
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2302
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2303
 ** @param d
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2304
 ** @param nodeId
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2305
 ** @param abortCode
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2306
 **
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2307
 ** @return
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2308
 **/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  2309
UNS8 getWriteResultNetworkDict (CO_Data* d, UNS8 nodeId, UNS32 * abortCode)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
  2310
{
663
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2311
	UNS8 line = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2312
	UNS8 err;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2313
	UNS8 CliNbr;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2314
	* abortCode = 0;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2315
	
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2316
	/* First let's find the corresponding SDO client in our OD  */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2317
	CliNbr = GetSDOClientFromNodeId(d, nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2318
	if(CliNbr >= 0xFE)
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2319
		return SDO_ABORTED_INTERNAL;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2320
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2321
	/* Looking for the line tranfert. */
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2322
	err = getSDOlineOnUse(d, CliNbr, SDO_CLIENT, &line);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2323
	if (err) {
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2324
		MSG_ERR(0x1AF1, "SDO error : No line found for communication with node : ", nodeId);
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2325
		return SDO_ABORTED_INTERNAL;
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2326
	}
70fc3603e36f timers_unix.c : remove sigint and sigterm catch
fbeaulier
parents: 657
diff changeset
  2327
	* abortCode = d->transfers[line].abortCode;
664
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2328
    if (d->transfers[line].state != SDO_FINISHED)
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2329
	    return d->transfers[line].state;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2330
    resetSDOline(d, line);
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2331
	return SDO_FINISHED;
a03f0aa7d219 CHANGE: SDO block mode added, without CRC support
fbeaulier
parents: 663
diff changeset
  2332
}