src/pdo.c
author etisserant
Mon, 14 May 2007 22:46:20 +0200
changeset 200 930be51ddc24
parent 149 fe50ada8020b
child 201 2966cd34162a
permissions -rw-r--r--
Big Endian fixes.
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
/*
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
Copyright (C): Edouard TISSERANT and Francis DUPIN
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
#include "pdo.h"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
#include "objacces.h"
149
fe50ada8020b Changes in the API:
etisserant
parents: 90
diff changeset
    24
#include "canfestival.h"
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
/****************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
UNS8 sendPDO(CO_Data* d, s_PDO pdo, UNS8 req)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
  if( d->nodeState == Operational ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
    Message m;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
    /* Message copy for sending */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    34
    m.cob_id.w = pdo.cobId & 0x7FF; /* Because the cobId is 11 bytes length */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
    if ( req == NOT_A_REQUEST ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
      UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
      m.rtr = NOT_A_REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
      m.len = pdo.len;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    39
      /* memcpy(&m.data, &pdo.data, m.len); */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    40
      /* This Memcpy depends on packing structure. Avoid */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
      for (i = 0 ; i < pdo.len ; i++)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
	m.data[i] = pdo.data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
    else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
      m.rtr = REQUEST;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
      m.len = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
    MSG_WAR(0x3901, "sendPDO cobId :", m.cob_id.w);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
    MSG_WAR(0x3902,  "     Nb octets  : ",  m.len);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
    for (i = 0 ; i < m.len ; i++) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
      MSG_WAR(0x3903,"           data : ", m.data[i]);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
		  
149
fe50ada8020b Changes in the API:
etisserant
parents: 90
diff changeset
    55
    return canSend(d->canHandle,&m);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    56
  } /* end if */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
/***************************************************************************/
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    61
UNS8 PDOmGR(CO_Data* d, UNS32 cobId) /* PDO Manager */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
{
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
  UNS8 res;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
  UNS8 i;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
  s_PDO pdo;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
  MSG_WAR(0x3905, "PDOmGR",0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
  /* if PDO is waiting for transmission,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
     preparation of the message to send */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
    pdo.cobId = cobId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
    pdo.len =  d->process_var.count;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    73
    /* memcpy(&(pdo.data), &(process_var.data), pdo.len); */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    74
    /* Ce memcpy devrait être portable */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    75
    for ( i = 0 ; i < pdo.len ; i++) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76
      pdo.data[i] = d->process_var.data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    77
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    78
    res = sendPDO(d, pdo, NOT_A_REQUEST);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    79
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    80
    return res;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    81
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    82
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    83
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    84
UNS8 buildPDO(CO_Data* d, UNS16 index)
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    85
{ /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails. */	
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    86
  UNS16 ind;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    87
  UNS8      subInd;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    88
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    89
  UNS8 *     pMappingCount = NULL;      /* count of mapped objects... */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    90
  /* pointer to the var which is mapped to a pdo */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    91
/*  void *     pMappedAppObject = NULL;  */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
    92
  /* pointer fo the var which holds the mapping parameter of an mapping entry  */ 
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    93
  UNS32 *    pMappingParameter = NULL;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    94
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    95
  UNS8      Size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    96
  UNS8      dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    97
  UNS8      offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    98
  UNS16     offsetObjdict;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    99
  UNS16     offsetObjdictPrm;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   100
  UNS32     objDict;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   101
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   102
  subInd=(UNS8)0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   103
  offset = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   104
  ind = index - 0x1800;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   105
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   106
  MSG_WAR(0x3910,"Prepare PDO to send index :", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   107
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   108
  /* only operational state allows PDO transmission */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   109
  if( d->nodeState != Operational ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   110
    MSG_WAR(0x2911, "Unable to send the PDO (node not in OPERATIONAL mode). Node : ", index);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   111
    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   112
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   113
  offsetObjdictPrm = d->firstIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   114
  offsetObjdict = d->firstIndex->PDO_TRS_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   115
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   116
  if (offsetObjdictPrm && offsetObjdict)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   117
  {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   118
	  /* get mapped objects number to transmit with this PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   119
	  pMappingCount = (d->objdict + offsetObjdict + ind)->pSubindex[0].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   120
	  MSG_WAR(0x3912, "Nb maped objects : ",* pMappingCount);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   121
	  MSG_WAR(0x3913, "        at index : ", 0x1A00 + ind);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   122
	  while (subInd < *pMappingCount) { /* Loop on mapped variables */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   123
	    /* get mapping parameters */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   124
	    pMappingParameter = (d->objdict + offsetObjdict + ind)->pSubindex[subInd + 1].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   125
	    MSG_WAR(0x3914, "Get the mapping      at index : ", (UNS16)0x1A00 + ind);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   126
	    MSG_WAR(0x3915, "                     subIndex : ", subInd + 1);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   127
	    MSG_WAR(0x3916, "                     value    : ", *(UNS32 *)pMappingParameter);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   128
	    /* Get the mapped variable */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   129
	     Size = ((UNS8)(((*pMappingParameter) & 0xFF) >> 3));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   130
	     objDict = getODentry(d, (UNS16)((*pMappingParameter) >> 16),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   131
				    (UNS8)(((*pMappingParameter) >> 8 ) & 0x000000FF),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   132
				    (void *)&d->process_var.data[offset], &Size, &dataType, 0 ); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   133
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   134
	     if (objDict != OD_SUCCESSFUL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   135
	        MSG_WAR(0x2919, "error accessing to the mapped var : ", subInd + 1);  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   136
		MSG_WAR(0x2920, "         Mapped at index : ", (*pMappingParameter) >> 16);
90
7df322d86ae1 copy/paste error
frdupin
parents: 71
diff changeset
   137
		MSG_WAR(0x2921, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   138
		return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   139
	     } 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   140
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   141
	      offset += Size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   142
	      d->process_var.count = offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   143
	      subInd++;					
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   144
	}/* end Loop on mapped variables  */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   145
  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   146
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   147
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   148
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   149
/**************************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   150
UNS8 sendPDOrequest( CO_Data* d, UNS32 cobId )
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   151
{		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   152
  UNS32 *	 pwCobId;	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   153
  UNS16          offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   154
  UNS16          lastIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   155
  UNS8           err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   156
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   157
  MSG_WAR(0x3930, "sendPDOrequest ",0);  
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   158
  /* Sending the request only if the cobid have been found on the PDO receive */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   159
  /* part dictionary */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   160
  offset = d->firstIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   161
  lastIndex = d->lastIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   162
  if (offset)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   163
	  while (offset <= lastIndex) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   164
	    /*get the CobId*/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   165
	    pwCobId = d->objdict[offset].pSubindex[1].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   166
	      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   167
	    if ( *pwCobId  == cobId ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   168
	      s_PDO pdo;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   169
	      pdo.cobId = *pwCobId;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   170
	      pdo.len = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   171
	      err  = sendPDO(d, pdo, REQUEST);	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   172
	      return err;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   173
	    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   174
	    offset++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   175
	  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   176
  MSG_WAR(0x1931, "sendPDOrequest : COBID not found : ", cobId); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   177
  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   178
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   179
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   180
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   181
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   182
/***********************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   183
UNS8 proceedPDO(CO_Data* d, Message *m)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   184
{		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   185
  UNS8   numPdo;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   186
  UNS8   numMap;  /* Number of the mapped varable */                      
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   187
  UNS8 i;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   188
  UNS8 *     pMappingCount = NULL;    /* count of mapped objects... */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   189
  /* pointer to the var which is mapped to a pdo... */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   190
/*  void *     pMappedAppObject = NULL;   */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   191
  /* pointer fo the var which holds the mapping parameter of an mapping entry */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   192
  UNS32 *    pMappingParameter = NULL;  
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   193
  UNS8  *    pTransmissionType = NULL; /* pointer to the transmission type */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   194
  UNS32 *    pwCobId = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   195
  UNS8       Size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   196
  UNS8       dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   197
  UNS8       offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   198
  UNS8       status;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   199
  UNS32      objDict;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   200
  UNS16      offsetObjdict;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   201
  UNS16      lastIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   202
  status = state1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   203
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   204
  MSG_WAR(0x3935, "proceedPDO, cobID : ", ((*m).cob_id.w & 0x7ff)); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   205
  offset = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   206
  numPdo = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   207
  numMap = 0;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   208
  if((*m).rtr == NOT_A_REQUEST ) { /* The PDO received is not a request. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   209
    offsetObjdict = d->firstIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   210
    lastIndex = d->lastIndex->PDO_RCV;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   211
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   212
    /* study of all the PDO stored in the dictionary */   
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   213
    if(offsetObjdict)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   214
	    while (offsetObjdict <= lastIndex) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   215
					
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   216
	      switch( status ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   217
						
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   218
	        case state1:	/* data are stored in process_var array */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   219
		  /* memcpy(&(process_var.data), &m->data, (*m).len); */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   220
		  /* Ce memcpy devrait être portable. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   221
		  for ( i = 0 ; i < m->len ; i++) 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   222
		    d->process_var.data[i] = m->data[i];
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   223
		  d->process_var.count = (*m).len;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   224
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   225
		  status = state2; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   226
		  break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   227
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   228
		case state2:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   229
		  /* get CobId of the dictionary correspondant to the received PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   230
	          pwCobId = d->objdict[offsetObjdict].pSubindex[1].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   231
		  /* check the CobId coherance */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   232
		  /*pwCobId is the cobId read in the dictionary at the state 3 */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   233
		  if ( *pwCobId == (*m).cob_id.w ){
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   234
		    /* The cobId is recognized */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   235
		    status = state4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   236
		    MSG_WAR(0x3936, "cobId found at index ", 0x1400 + numPdo);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   237
		    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   238
		  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   239
		  else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   240
		    /* cobId received does not match with those write in the dictionnary */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   241
		    numPdo++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   242
		    offsetObjdict++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   243
		    status = state2;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   244
		    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   245
		  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   246
	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   247
		case state4:	/* get mapped objects number */
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   248
		  /* The cobId of the message received has been found in the dictionnary. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   249
		  offsetObjdict = d->firstIndex->PDO_RCV_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   250
		  lastIndex = d->lastIndex->PDO_RCV_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   251
		  pMappingCount = (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject;	  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   252
		  numMap = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   253
		  while (numMap < *pMappingCount) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   254
		    pMappingParameter = (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   255
		    if (pMappingParameter == NULL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   256
		      MSG_ERR(0x1937, "Couldn't get mapping parameter : ", numMap + 1); 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   257
		      return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   258
		    }
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   259
		    /* Get the addresse of the mapped variable. */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   260
		    /* detail of *pMappingParameter : */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   261
	            /* The 16 hight bits contains the index, the medium 8 bits contains the subindex, */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   262
		    /* and the lower 8 bits contains the size of the mapped variable. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   263
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   264
		    Size = ((UNS8)(((*pMappingParameter) & 0xFF) >> 3));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   265
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   266
		    objDict = setODentry(d, (UNS16)((*pMappingParameter) >> 16),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   267
				            (UNS8)(((*pMappingParameter) >> 8 ) & 0xFF),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   268
					    (void *)&d->process_var.data[offset], &Size, 0 );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   269
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   270
		    if(objDict != OD_SUCCESSFUL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   271
		      MSG_ERR(0x1938, "error accessing to the mapped var : ", numMap + 1);  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   272
		      MSG_WAR(0x2939, "         Mapped at index : ", (*pMappingParameter) >> 16);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   273
		      MSG_WAR(0x2940, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   274
		      return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   275
		    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   276
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   277
		    MSG_WAR(0x3942, "Variable updated with value received by PDO cobid : ", m->cob_id.w);  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   278
		    MSG_WAR(0x3943, "         Mapped at index : ", (*pMappingParameter) >> 16);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   279
		    MSG_WAR(0x3944, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   280
		    /* MSG_WAR(0x3945, "                data : ",*((UNS32 *)pMappedAppObject)); */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   281
		    offset += Size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   282
		    numMap++;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   283
		  } /* end loop while on mapped variables */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   284
		  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   285
		  offset=0x00;		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   286
		  numMap = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   287
		  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   288
		  
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   289
	      }/* end switch status	*/	 
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   290
	    }/* end while	*/
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   291
  }/* end if Donnees */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   292
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   293
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   294
  else if ((*m).rtr == REQUEST ){  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   295
      MSG_WAR(0x3946, "Receive a PDO request cobId : ", m->cob_id.w);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   296
      status = state1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   297
      offsetObjdict = d->firstIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   298
      lastIndex = d->lastIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   299
      if(offsetObjdict) while( offsetObjdict  <= lastIndex ){ 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   300
	/* study of all PDO stored in the objects dictionary */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   301
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   302
	switch( status ){
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   303
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   304
	case state1:	/* check the CobId */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   305
			/* get CobId of the dictionary which match to the received PDO */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   306
	  pwCobId = (d->objdict + offsetObjdict)->pSubindex[1].pObject;	  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   307
	  if ( *pwCobId == (*m).cob_id.w ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   308
	    status = state4;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   309
	    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   310
	  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   311
	  else {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   312
	    numPdo++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   313
	    offsetObjdict++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   314
	  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   315
	  status = state1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   316
	  break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   317
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   318
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   319
	case state4:	/* check transmission type (after request?) */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   320
	  pTransmissionType = d->objdict[offsetObjdict].pSubindex[2].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   321
	  if ( (*pTransmissionType == TRANS_RTR) || (*pTransmissionType == TRANS_RTR_SYNC ) || (*pTransmissionType == TRANS_EVENT) ) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   322
	    status = state5;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   323
	    break;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   324
	  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   325
	  else {
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   326
	    /* The requested PDO is not to send on request. So, does nothing. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   327
	    MSG_WAR(0x2947, "PDO is not to send on request : ", m->cob_id.w);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   328
	    return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   329
	  }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   330
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   331
	case state5:	/* get mapped objects number */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   332
	  offsetObjdict = d->firstIndex->PDO_TRS_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   333
	  lastIndex = d->lastIndex->PDO_TRS_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   334
	  pMappingCount = (d->objdict + offsetObjdict + numPdo)->pSubindex[0].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   335
	  numMap = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   336
	  while (numMap < *pMappingCount) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   337
	    pMappingParameter = (d->objdict + offsetObjdict + numPdo)->pSubindex[numMap + 1].pObject;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   338
	    /* Get the mapped variable */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   339
	    Size = ((UNS8)(((*pMappingParameter) & 0xFF) >> 3));
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   340
	    objDict = getODentry( d, (UNS16)((*pMappingParameter) >> (UNS8)16), 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   341
				     (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & 0xFF),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   342
				     (void *)&d->process_var.data[offset], &Size, &dataType, 0 );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   343
	    if (objDict != OD_SUCCESSFUL) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   344
	      MSG_ERR(0x1948, "error accessing to the mapped var : ", numMap + 1);  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   345
	      MSG_WAR(0x2949, "         Mapped at index : ", (*pMappingParameter) >> 16);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   346
	      MSG_WAR(0x2950, "                subindex : ", ((*pMappingParameter) >> 8 ) & 0xFF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   347
	      return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   348
	    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   349
	    offset += (UNS8) (((*pMappingParameter) & 0xFF) >> 3);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   350
	    d->process_var.count = offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   351
	    numMap++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   352
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   353
	  } /* end while */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   354
	  PDOmGR( d, *pwCobId ); /* Transmit the PDO */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   355
	  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   356
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   357
	}/* end switch status */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   358
      }/* end while	 */			
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   359
    }/* end if Requete */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   360
		
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   361
  return 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   362
}
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   363
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   364
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   365
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   366
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   367
#if 0
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   368
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   369
/*********************************************************************/
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   370
/* TODO : reimplement this using CallBacks                           */
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   371
/*********************************************************************/
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   372
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   373
UNS8 sendPDOevent( CO_Data* d, void * variable )
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   374
{ /* DO NOT USE MSG_ERR because the macro may send a PDO -> infinite loop if it fails.	*/
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   375
  UNS32           objDict = 0;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   376
  UNS8            ind, sub_ind;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   377
  UNS8            status; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   378
  UNS8            offset;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   379
  UNS8 *     pMappingCount = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   380
  UNS32 *    pMappingParameter = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   381
  void *     pMappedAppObject = NULL;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   382
  UNS8 *     pTransmissionType = NULL; /* pointer to the transmission type */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   383
  UNS32 *    pwCobId = NULL;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   384
  UNS8 *     pSize;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   385
  UNS8       size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   386
  UNS8       dataType;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   387
  UNS16      offsetObjdict;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   388
  UNS16      offsetObjdictPrm;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   389
  UNS16      lastIndex;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   390
  UNS8       numMap;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   391
  ind     = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   392
  sub_ind = 1; 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   393
  offset  = 0x00;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   394
  pSize   = &size;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   395
  status  = state1;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   396
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   397
  /* look for the index and subindex where the variable is mapped */
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   398
  /* Then, send the pdo which contains the variable. */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   399
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   400
  MSG_WAR (0x3960, "sendPDOevent", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   401
  offsetObjdictPrm = d->firstIndex->PDO_TRS;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   402
  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   403
  offsetObjdict = d->firstIndex->PDO_TRS_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   404
  lastIndex = d->lastIndex->PDO_TRS_MAP;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   405
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   406
  if (offsetObjdictPrm && offsetObjdict) 
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   407
	  /* Loop on PDO Transmit */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   408
	  while(offsetObjdict <= lastIndex){
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   409
	    /* Check the transmission mode */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   410
	    pTransmissionType = d->objdict[offsetObjdictPrm].pSubindex[2].pObject;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   411
	    if (*pTransmissionType != TRANS_EVENT) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   412
	      ind++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   413
	      offsetObjdict++;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   414
	      offsetObjdictPrm++;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   415
	      continue;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   416
	    }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   417
	    pMappingCount = d->objdict[offsetObjdict].pSubindex[0].pObject;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   418
	    numMap = 1; /* mapped variable */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   419
	    while (numMap <= *pMappingCount) {
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   420
	      pMappingParameter = d->objdict[offsetObjdict].pSubindex[numMap].pObject;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   421
	      /* Get the variable */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   422
	      objDict = getODentry( d,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   423
	                            (UNS16)((*pMappingParameter) >> 16), 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   424
				    (UNS8)(( (*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF),
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   425
				    (void * *)&pMappedAppObject, pSize, &dataType, 0 );
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   426
	      if( objDict != OD_SUCCESSFUL ) {  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   427
		MSG_WAR(0x2961, "Error in dict. at index : ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   428
			(*pMappingParameter) >> (UNS8)16);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   429
	      
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   430
		MSG_WAR(0x2962, "               subindex : ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   431
			((*pMappingParameter) >> (UNS8)8 ) & (UNS32)0x000000FF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   432
		return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   433
	      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   434
	      if (pMappedAppObject == variable) { // Variable found !
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   435
		MSG_WAR(0x3963, "Variable to send found at index : ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   436
			(*pMappingParameter) >> 16);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   437
		MSG_WAR(0x3964, "                       subIndex : ", 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   438
			((*pMappingParameter) >> 8 ) & 0x000000FF);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   439
		buildPDO(d, 0x1800 + ind);
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   440
		/* Get the cobId */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   441
		pwCobId = d->objdict[offsetObjdictPrm].pSubindex[1].pObject;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   442
		PDOmGR( d, *pwCobId ); /* Send the PDO */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   443
		return 0;	    
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   444
	      }
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   445
	      numMap++;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   446
	    } /* End loop on mapped variable */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   447
	    ind++;	
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   448
	    offsetObjdict++;  
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   449
	    offsetObjdictPrm++;
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   450
	  } /* End loop while on PDO */
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   451
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   452
  MSG_WAR(0x2965, "Variable not found in a PDO to send on event", 0);
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   453
  return 0xFF;
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   454
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
   455
}
71
95cd3376cc9f compilator compatitibility
frdupin
parents: 0
diff changeset
   456
#endif