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