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