src/dcf.c
author lbessard
Tue, 05 Jun 2007 17:34:33 +0200
changeset 209 2cb34a4ac65a
parent 208 05d95c45b388
child 210 6b5a4c21e061
permissions -rw-r--r--
Bug on RefreshStatusBar corrected
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     1
/*
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
     2
  This file is part of CanFestival, a library implementing CanOpen
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
     3
  Stack.
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     4
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
     5
  Copyright (C): Edouard TISSERANT and Francis DUPIN
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     6
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
     7
  See COPYING file for copyrights details.
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
     8
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
     9
  This library is free software; you can redistribute it and/or
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    10
  modify it under the terms of the GNU Lesser General Public
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    11
  License as published by the Free Software Foundation; either
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    12
  version 2.1 of the License, or (at your option) any later version.
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    13
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    14
  This library is distributed in the hope that it will be useful,
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    15
  but WITHOUT ANY WARRANTY; without even the implied warranty of
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    16
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    17
  Lesser General Public License for more details.
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    18
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    19
  You should have received a copy of the GNU Lesser General Public
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    20
  License along with this library; if not, write to the Free Software
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    21
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    22
  USA
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    23
*/
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    24
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    25
/**
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    26
** @file   dcf.c
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    27
** @author Edouard TISSERANT and Francis DUPIN
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    28
** @date   Mon Jun  4 17:06:12 2007
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    29
**
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    30
** @brief EXEMPLE OF SOMMARY
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    31
**
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    32
**
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    33
*/
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    34
#include "objacces.h"
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    35
#include "sdo.h"
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    36
#include "dcf.h"
200
930be51ddc24 Big Endian fixes.
etisserant
parents: 191
diff changeset
    37
#include "sysdep.h"
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    38
204
44ce74232ccb Some fixes for visual studio C compiler compatiblity.
etisserant
parents: 202
diff changeset
    39
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    40
/**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    41
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    42
**
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    43
** @param d fuck fuck fuck
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    44
** @param nodeId
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    45
** @param index
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    46
** @param subIndex
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    47
** @param count
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    48
** @param dataType
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    49
** @param data
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    50
** @param Callback
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    51
** @param endianize
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    52
*/
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    53
extern UNS8 _writeNetworkDict (CO_Data* d, UNS8 nodeId, UNS16 index,
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    54
                               UNS8 subIndex, UNS8 count, UNS8 dataType, void *data, SDOCallback_t Callback, UNS8 endianize);
204
44ce74232ccb Some fixes for visual studio C compiler compatiblity.
etisserant
parents: 202
diff changeset
    55
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    56
const indextable *ptrTable;
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    57
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    58
/**
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    59
**
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    60
**
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    61
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    62
** @param nodeId
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    63
*/
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    64
static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    65
{
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    66
  UNS32 abortCode;
191
1e6e3d261b8f CleanUp and minor fixes
etisserant
parents: 178
diff changeset
    67
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    68
  if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    69
    {
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    70
      MSG_ERR(0x1A01, "SDO error in consise DCF", abortCode);
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    71
      MSG_WAR(0x2A02, "server node : ", nodeId);
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    72
    }
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    73
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    74
  closeSDOtransfer(d, nodeId, SDO_CLIENT);
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    75
  decompo_dcf(d,nodeId);
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    76
}
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    77
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    78
/**
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    79
**
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    80
**
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    81
** @param d
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    82
** @param nodeId
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    83
**
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    84
** @return
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
    85
*/
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    86
UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    87
{
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    88
  UNS32 errorCode;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    89
  UNS16 target_Index;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    90
  UNS8 target_Subindex;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    91
  UNS32 target_Size;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    92
  UNS32 res;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    93
  ODCallback_t *Callback;
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
    94
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    95
  ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    96
  if (errorCode != OD_SUCCESSFUL)
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    97
    {
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    98
      return errorCode;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
    99
    }
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   100
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   101
  /** Loop on all Nodes supported in DCF subindexes*/
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   102
  while (nodeId < ptrTable->bSubCount){
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   103
    UNS32 nb_targets;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   104
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   105
    UNS8 szData = ptrTable->pSubindex[nodeId].size;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   106
    UNS8* dcfend;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   107
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   108
    {
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   109
      UNS8* dcf = *((UNS8**)ptrTable->pSubindex[nodeId].pObject);
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   110
      dcfend = dcf + szData;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   111
      if (!d->dcf_cursor){
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   112
        d->dcf_cursor = (UNS8*)dcf + 4;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   113
        d->dcf_count_targets = 0;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   114
      }
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   115
      nb_targets = UNS32_LE(*((UNS32*)dcf));
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   116
    }
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   117
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   118
    /** condition on consise DCF string for NodeID, if big enough */
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   119
    if((UNS8*)d->dcf_cursor + 7 < (UNS8*)dcfend && d->dcf_count_targets < nb_targets)
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   120
      {
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   121
        /** pointer to the DCF string for NodeID */
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   122
        target_Index = UNS16_LE(*((UNS16*)(d->dcf_cursor))); d->dcf_cursor += 2;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   123
        target_Subindex = *((UNS8*)(((UNS8*)d->dcf_cursor)++));
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   124
        target_Size = UNS32_LE(*((UNS32*)(d->dcf_cursor))); d->dcf_cursor += 4;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   125
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   126
        /* printf("Master : ConfigureSlaveNode %2.2x (Concise
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   127
          DCF)\n",nodeId);*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   128
        res = _writeNetworkDict(d, /** CO_Data* d*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   129
                                nodeId, /** UNS8 nodeId*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   130
                                target_Index, /** UNS16 index*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   131
                                target_Subindex, /** UNS8 subindex*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   132
                                target_Size, /** UNS8 count*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   133
                                0, /** UNS8 dataType*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   134
                                d->dcf_cursor,/** void *data*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   135
                                CheckSDOAndContinue,/** SDOCallback_t
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   136
                                                      Callback*/
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   137
                                0); /** no endianize*/
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   138
        /** Push d->dcf_cursor to the end of data*/
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   139
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   140
        d->dcf_cursor += target_Size;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   141
        d->dcf_count_targets++;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   142
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   143
        return ;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   144
      }
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   145
    nodeId++;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   146
    d->dcf_cursor = NULL;
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   147
  }
208
05d95c45b388 Manual convertion -> latex -> pdf
nico
parents: 207
diff changeset
   148
  /**  Switch Master to preOperational state */
207
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   149
  (*d->preOperational)();
b6572d0336c3 First doxygen implementation
nico
parents: 204
diff changeset
   150
178
01d81faa3350 Add concise DCF support
greg
parents:
diff changeset
   151
}