src/sdo.c
author Robert Lehmann <robert.lehmann@sitec-systems.de>
Tue, 28 Jul 2015 16:36:55 +0200
changeset 793 72e9e1064432
parent 719 438a979fda5d
permissions -rw-r--r--
timers_unix: Fix termination problem of WaitReceiveTaskEnd

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