]> rtime.felk.cvut.cz Git - CanFestival-3.git/commitdiff
Add concise DCF support
authorgreg <greg>
Fri, 4 May 2007 10:26:46 +0000 (10:26 +0000)
committergreg <greg>
Fri, 4 May 2007 10:26:46 +0000 (10:26 +0000)
doc/manual/en/manual.odt
include/data.h
include/dcf.h [new file with mode: 0644]
src/Makefile.in
src/dcf.c [new file with mode: 0644]
src/states.c

index 226fce97b58091997a9e3255a72c947d47f814be..e196fd3867df53d87b4595c44a37c411e5ac98cf 100644 (file)
Binary files a/doc/manual/en/manual.odt and b/doc/manual/en/manual.odt differ
index cdc64f70e928efef13060066ddb26b468c3caa7f..dd08ade23fe69314b74d33a29378529caa8fdd5c 100644 (file)
@@ -90,6 +90,11 @@ struct struct_CO_Data {
        CAN_HANDLE canHandle;   
        scanIndexOD_t scanIndexOD;
        storeODSubIndex_t storeODSubIndex; 
+       
+       /* DCF concise */
+       void* dcf_cursor;
+       UNS32 dcf_count_targets;
+       
 };
 
 #define NMTable_Initializer Unknown_state,
@@ -173,7 +178,9 @@ struct struct_CO_Data {
        0,                                         /* toggle */\
        NULL,                   /* canSend */\
        NODE_PREFIX ## _scanIndexOD,                /* scanIndexOD */\
-       _storeODSubIndex                /* storeODSubIndex */\
+       _storeODSubIndex,                /* storeODSubIndex */\
+       NULL,           /*dcf_cursor*/\
+       1               /*dcf_count_targets*/\
 }
 
 #endif /* __data_h__ */
diff --git a/include/dcf.h b/include/dcf.h
new file mode 100644 (file)
index 0000000..ee722cd
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+This file is part of CanFestival, a library implementing CanOpen Stack. 
+
+Copyright (C): Edouard TISSERANT and Francis DUPIN
+
+See COPYING file for copyrights details.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+
+UNS32 decompo_dcf(CO_Data* d, UNS8 nodeId);
index 10b9d8798d9d910ea9d349be3ebfa916721791f4..c93c7f1f779fc20afcb841fde90611779cbfa05f 100644 (file)
@@ -34,7 +34,7 @@ TIMERS_DRIVER = SUB_TIMERS_DRIVER
 INCLUDES = -I../include -I../include/$(TARGET) -I../include/$(CAN_DRIVER) -I../include/$(TIMERS_DRIVER) -I../drivers/$(TARGET)
 
 OBJS = $(TARGET)_objacces.o $(TARGET)_lifegrd.o $(TARGET)_sdo.o\
-           $(TARGET)_pdo.o $(TARGET)_sync.o $(TARGET)_nmtSlave.o $(TARGET)_nmtMaster.o $(TARGET)_states.o $(TARGET)_timer.o
+           $(TARGET)_pdo.o $(TARGET)_sync.o $(TARGET)_nmtSlave.o $(TARGET)_nmtMaster.o $(TARGET)_states.o $(TARGET)_timer.o $(TARGET)_dcf.o
 
 # # # # Target specific paramters # # # #
 
diff --git a/src/dcf.c b/src/dcf.c
new file mode 100644 (file)
index 0000000..dc11cb3
--- /dev/null
+++ b/src/dcf.c
@@ -0,0 +1,118 @@
+/*
+This file is part of CanFestival, a library implementing CanOpen Stack. 
+
+Copyright (C): Edouard TISSERANT and Francis DUPIN
+
+See COPYING file for copyrights details.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+#include "objacces.h"
+#include "sdo.h"
+#include "dcf.h"
+
+const indextable *ptrTable;
+
+static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
+{
+       UNS32 res;
+       UNS8 line;
+       UNS8 err;
+       UNS16 Index;
+       UNS8 SubIndex;
+       UNS32 abortCode;
+       
+       if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
+               printf("Master : Failed in initializing slave %2.2x, AbortCode :%4.4x \n", nodeId, abortCode);
+       
+       closeSDOtransfer(d, nodeId, SDO_CLIENT);
+       res = decompo_dcf(d,nodeId);
+}
+
+UNS32 decompo_dcf(CO_Data* d,UNS8 nodeId)
+{
+               UNS32 errorCode;
+               UNS16 target_Index;
+               UNS8 target_Subindex;
+               UNS32 target_Size;
+               void* target_data = NULL;
+               UNS32 res;
+               ODCallback_t *Callback;
+
+               ptrTable = (*d->scanIndexOD)(0x1F22, &errorCode, &Callback);
+               if (errorCode != OD_SUCCESSFUL)
+               {
+               return errorCode;
+               }
+
+               /*Loop on all Nodes supported in DCF subindexes*/
+               while (nodeId < ptrTable->bSubCount){
+                       UNS32 nb_targets;
+                       
+                       UNS8 szData = ptrTable->pSubindex[nodeId].size;
+                       void* dcfend;
+                       
+                       {
+                               void* dcf = *((void**)ptrTable->pSubindex[nodeId].pObject);
+                               dcfend = dcf + szData;
+                               if (!d->dcf_cursor)     {
+                                       d->dcf_cursor = dcf + 4;
+                                       d->dcf_count_targets = 0;
+                               }
+       #ifdef CANOPEN_BIG_ENDIAN
+                               nb_targets = ((UNS8*)d->dcf++) | ((UNS8*)d->dcf++) << 8 | ((UNS8*)d->dcf++) << 16 | ((UNS8*)d->dcf++) << 24;
+       #else
+                               nb_targets = *((UNS32*)dcf);
+       #endif
+                       }
+                       
+                       // condition on consise DCF string for NodeID, if big enough
+                       if(d->dcf_cursor + 7 < dcfend && d->dcf_count_targets < nb_targets)
+                       {
+                               // pointer to the DCF string for NodeID
+       #ifdef CANOPEN_BIG_ENDIAN
+                               target_Index = ((UNS8*)d->dcf_cursor++) | ((UNS8*)d->dcf_cursor++) << 8;
+                               target_Subindex = ((UNS8*)d->dcf_cursor++);
+                               target_Size = ((UNS8*)d->dcf_cursor++) | ((UNS8*)d->dcf_cursor++) << 8 | ((UNS8*)d->dcf_cursor++) << 16 | ((UNS8*)d->dcf_cursor++) << 24;
+       #else
+                               target_Index = *((UNS16*)(d->dcf_cursor)); d->dcf_cursor += 2;
+                               target_Subindex = *((UNS8*)(d->dcf_cursor++));
+                               target_Size = *((UNS32*)(d->dcf_cursor)); d->dcf_cursor += 4;
+       #endif
+                               
+                                       printf("Master : ConfigureSlaveNode %2.2x (Concise DCF)\n",nodeId);
+                                       res = writeNetworkDictCallBack(d, /*CO_Data* d*/
+                                                       nodeId, /*UNS8 nodeId*/
+                                                       target_Index, /*UNS16 index*/
+                                                       target_Subindex, /*UNS8 subindex*/
+                                                       target_Size, /*UNS8 count*/
+                                                       0, /*UNS8 dataType*/
+                                                       d->dcf_cursor,/*void *data*/
+                                                       CheckSDOAndContinue); /*SDOCallback_t Callback*/                                        
+                                       /*Push d->dcf_cursor to the end of data*/
+                                       
+                                       d->dcf_cursor += target_Size;
+                                       d->dcf_count_targets++;
+                                       
+                                       return ;
+                       }                       
+                               nodeId++;
+                               d->dcf_cursor = NULL;
+               }
+               /* Switch Master to preOperational state */
+               (*d->preOperational)();
+               
+}
index dd7bb585f9ef3dd21768e1baadad02bbb15d21c3..c2c2cbc723d2c0426941808da7c2a7b16d8be64c 100644 (file)
@@ -110,16 +110,26 @@ UNS8 setState(CO_Data* d, e_nodeState newState)
                                switchCommunicationState(d, &newCommunicationState);
                                /* call user app related state func. */
                                (*d->initialisation)();
+                               
                        }
                        break;
                                                                
                        case Pre_operational:
                        {
+                               
                                s_state_communication newCommunicationState = {0, 1, 1, 1, 1, 0};
                                d->nodeState = Pre_operational;
                                newState = Pre_operational;
                                switchCommunicationState(d, &newCommunicationState);
-                               (*d->preOperational)();
+                               if (!(*(d->iam_a_slave)))
+                               {
+                                       UNS32 res;
+                                       res = decompo_dcf(d,0x01);
+                               }
+                               else 
+                               {
+                                       (*d->preOperational)();
+                               }
                        }
                        break;