diff -r 6efc85c5493e -r 1c1e3599d66a doc/doxygen/html/Master_8c-source.html --- a/doc/doxygen/html/Master_8c-source.html Mon Feb 11 11:00:12 2008 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ - - -CanFestival: examples/TestMasterSlave/Master.c Source File - - - - -
-
-
-
- -

Master.c

Go to the documentation of this file.
00001 /*
-00002 This file is part of CanFestival, a library implementing CanOpen Stack. 
-00003 
-00004 Copyright (C): Edouard TISSERANT and Francis DUPIN
-00005 
-00006 See COPYING file for copyrights details.
-00007 
-00008 This library is free software; you can redistribute it and/or
-00009 modify it under the terms of the GNU Lesser General Public
-00010 License as published by the Free Software Foundation; either
-00011 version 2.1 of the License, or (at your option) any later version.
-00012 
-00013 This library is distributed in the hope that it will be useful,
-00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
-00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-00016 Lesser General Public License for more details.
-00017 
-00018 You should have received a copy of the GNU Lesser General Public
-00019 License along with this library; if not, write to the Free Software
-00020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-00021 */
-00022 
-00023 #include "Master.h"
-00024 #include "Slave.h"
-00025 #include "TestMasterSlave.h"
-00026 
-00027 /*****************************************************************************/
-00028 void TestMaster_heartbeatError(UNS8 heartbeatID)
-00029 {
-00030         eprintf("TestMaster_heartbeatError %d\n", heartbeatID);
-00031 }
-00032 
-00033 /********************************************************
-00034  * ConfigureSlaveNode is responsible to
-00035  *  - setup master RPDO 1 to receive TPDO 1 from id 2
-00036  *  - setup master RPDO 2 to receive TPDO 2 from id 2
-00037  ********************************************************/
-00038 void TestMaster_initialisation()
-00039 {
-00040         UNS32 PDO1_COBID = 0x0182; 
-00041         UNS32 PDO2_COBID = 0x0282;
-00042         UNS8 size = sizeof(UNS32); 
-00043         
-00044         eprintf("TestMaster_initialisation\n");
-00045 
-00046         /*****************************************
-00047          * Define RPDOs to match slave ID=2 TPDOs*
-00048          *****************************************/
-00049         writeLocalDict( &TestMaster_Data, /*CO_Data* d*/
-00050                         0x1400, /*UNS16 index*/
-00051                         0x01, /*UNS8 subind*/ 
-00052                         &PDO1_COBID, /*void * pSourceData,*/ 
-00053                         &size, /* UNS8 * pExpectedSize*/
-00054                         RW);  /* UNS8 checkAccess */
-00055                         
-00056         writeLocalDict( &TestMaster_Data, /*CO_Data* d*/
-00057                         0x1401, /*UNS16 index*/
-00058                         0x01, /*UNS8 subind*/ 
-00059                         &PDO2_COBID, /*void * pSourceData,*/ 
-00060                         &size, /* UNS8 * pExpectedSize*/
-00061                         RW);  /* UNS8 checkAccess */
-00062 }
-00063 
-00064 // Step counts number of times ConfigureSlaveNode is called
-00065 static init_step = 0;
-00066 
-00067 /*Froward declaration*/
-00068 static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId);
-00069 
-00070 
-00071 static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
-00072 {
-00073         UNS32 abortCode;        
-00074         if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
-00075                 eprintf("Master : Failed in initializing slave %2.2x, step %d, AbortCode :%4.4x \n", nodeId, init_step, abortCode);
-00076 
-00077         /* Finalise last SDO transfer with this node */
-00078         closeSDOtransfer(&TestMaster_Data, nodeId, SDO_CLIENT);
-00079 
-00080         ConfigureSlaveNode(d, nodeId);
-00081 }
-00082 
-00083 /********************************************************
-00084  * ConfigureSlaveNode is responsible to
-00085  *  - setup slave TPDO 1 transmit time
-00086  *  - setup slave TPDO 2 transmit time
-00087  *  - switch to operational mode
-00088  *  - send NMT to slave
-00089  ********************************************************
-00090  * This an example of :
-00091  * Network Dictionary Access (SDO) with Callback 
-00092  * Slave node state change request (NMT) 
-00093  ********************************************************
-00094  * This is called first by TestMaster_preOperational
-00095  * then it called again each time a SDO exchange is
-00096  * finished.
-00097  ********************************************************/
-00098  
-00099 static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId)
-00100 {
-00101         /* Master configure heartbeat producer time at 1000 ms 
-00102          * for slave node-id 0x02 by DCF concise */
-00103          
-00104         UNS8 Transmission_Type = 0x01;
-00105         UNS32 abortCode;
-00106         UNS8 res;
-00107         eprintf("Master : ConfigureSlaveNode %2.2x\n", nodeId);
-00108 
-00109         switch(++init_step){
-00110                 case 1: /*First step : setup Slave's TPDO 1 to be transmitted on SYNC*/
-00111                         eprintf("Master : set slave %2.2x TPDO 1 transmit type\n", nodeId);
-00112                         res = writeNetworkDictCallBack (d, /*CO_Data* d*/
-00113                                         nodeId, /*UNS8 nodeId*/
-00114                                         0x1800, /*UNS16 index*/
-00115                                         0x02, /*UNS8 subindex*/
-00116                                         1, /*UNS8 count*/
-00117                                         0, /*UNS8 dataType*/
-00118                                         &Transmission_Type,/*void *data*/
-00119                                         CheckSDOAndContinue); /*SDOCallback_t Callback*/
-00120                                         break;
-00121                 
-00122                 case 2: /*Second step*/
-00123                         eprintf("Master : set slave %2.2x TPDO 2 transmit type\n", nodeId);
-00124                         writeNetworkDictCallBack (d, /*CO_Data* d*/
-00125                                         nodeId, /*UNS8 nodeId*/
-00126                                         0x1801, /*UNS16 index*/
-00127                                         0x02, /*UNS16 index*/
-00128                                         1, /*UNS8 count*/
-00129                                         0, /*UNS8 dataType*/
-00130                                         &Transmission_Type,/*void *data*/
-00131                                         CheckSDOAndContinue); /*SDOCallback_t Callback*/
-00132                                         break;
-00133                 case 3: 
-00134                 
-00135                 /****************************** START *******************************/
-00136                 
-00137                         /* Put the master in operational mode */
-00138                         setState(d, Operational);
-00139                  
-00140                         /* Ask slave node to go in operational mode */
-00141                         masterSendNMTstateChange (d, nodeId, NMT_Start_Node);
-00142                         
-00143         }
-00144 }
-00145 
-00146 void TestMaster_preOperational()
-00147 {
-00148 
-00149         eprintf("TestMaster_preOperational\n");
-00150         ConfigureSlaveNode(&TestMaster_Data, 0x02);
-00151         
-00152 }
-00153 
-00154 void TestMaster_operational()
-00155 {
-00156         eprintf("TestMaster_operational\n");
-00157 }
-00158 
-00159 void TestMaster_stopped()
-00160 {
-00161         eprintf("TestMaster_stopped\n");
-00162 }
-00163 
-00164 void TestMaster_post_sync()
-00165 {
-00166         eprintf("TestMaster_post_sync\n");
-00167         eprintf("Master: %d %d %d %d %d %d %d %d %d %x %x %d %d\n",
-00168                 MasterMap1,
-00169                 MasterMap2,
-00170                 MasterMap3, 
-00171                 MasterMap4,
-00172                 MasterMap5,
-00173                 MasterMap6,
-00174                 MasterMap7,
-00175                 MasterMap8,
-00176                 MasterMap9,
-00177                 MasterMap10,
-00178                 MasterMap11,
-00179                 MasterMap12,
-00180                 MasterMap13);
-00181 }
-00182 
-00183 char query_result = 0;
-00184 char waiting_answer = 0;
-00185 
-00186 
-00187 static void CheckSDO(CO_Data* d, UNS8 nodeId)
-00188 {
-00189         UNS32 abortCode;        
-00190         if(getWriteResultNetworkDict (d, nodeId, &abortCode) != SDO_FINISHED)
-00191                 eprintf("Master : Failed in changing Slave's transmit type AbortCode :%4.4x \n", abortCode);
-00192 
-00193         /* Finalise last SDO transfer with this node */
-00194         closeSDOtransfer(&TestMaster_Data, nodeId, SDO_CLIENT);
-00195 }
-00196 
-00197 
-00198 static int MasterSyncCount = 0;
-00199 void TestMaster_post_TPDO()
-00200 {
-00201         eprintf("TestMaster_post_TPDO MasterSyncCount = %d \n", MasterSyncCount);
-00202 //
-00203 //      {
-00204 //              char zero = 0;
-00205 //              if(MasterMap4 > 0x80){
-00206 //                      writeNetworkDict (
-00207 //                              &TestMaster_Data,
-00208 //                              TestSlave_Data->bDeviceNodeId,
-00209 //                              0x2002,
-00210 //                              0x00,
-00211 //                              1,
-00212 //                              0,
-00213 //                              &zero); 
-00214 //              }
-00215 //      }
-00216 
-00217 #if 0
-00218         if(waiting_answer){
-00219                 UNS32 abortCode;                        
-00220                 UNS8 size;                      
-00221                 switch(getReadResultNetworkDict (
-00222                         &TestMaster_Data, 
-00223                         0x02,
-00224                         &query_result,
-00225                         &size,
-00226                         &abortCode))
-00227                 {
-00228                         case SDO_FINISHED:
-00229                                 /* Do something with result here !!*/
-00230                                 eprintf("Got SDO answer (0x2002, 0x00), %d %d\n",query_result,size);
-00231                         case SDO_ABORTED_RCV:
-00232                         case SDO_ABORTED_INTERNAL:
-00233                         case SDO_RESET:
-00234                                 waiting_answer = 0;
-00235                                 closeSDOtransfer(
-00236                                         &TestMaster_Data,
-00237                                         0x02,
-00238                                         SDO_CLIENT);
-00239                         break;
-00240                         case SDO_DOWNLOAD_IN_PROGRESS:
-00241                         case SDO_UPLOAD_IN_PROGRESS:
-00242                         break;
-00243                 }
-00244         }else if(MasterSyncCount % 10 == 0){
-00245                 readNetworkDict (
-00246                         &TestMaster_Data,
-00247                         0x02,
-00248                         0x2002,
-00249                         0x00,
-00250                         0);
-00251                 waiting_answer = 1;
-00252         }
-00253 #endif  
-00254         if(MasterSyncCount % 17 == 0){
-00255                 eprintf("Master : Ask RTR PDO (0x1402)\n");
-00256                 sendPDOrequest(&TestMaster_Data, 0x1402 );
-00257                 sendPDOrequest(&TestMaster_Data, 0x1403 );
-00258         }
-00259         if(MasterSyncCount % 50 == 0){
-00260                 eprintf("Master : Change slave's transmit type to 0xFF\n");
-00261                 UNS8 transmitiontype = 0xFF;
-00262                 writeNetworkDictCallBack (&TestMaster_Data, /*CO_Data* d*/
-00263                                         2, /*UNS8 nodeId*/
-00264                                         0x1802, /*UNS16 index*/
-00265                                         0x02, /*UNS16 index*/
-00266                                         1, /*UNS8 count*/
-00267                                         0, /*UNS8 dataType*/
-00268                                         &transmitiontype,/*void *data*/
-00269                                         CheckSDO); /*SDOCallback_t Callback*/
-00270         }
-00271         if(MasterSyncCount % 50 == 25){
-00272                 eprintf("Master : Change slave's transmit type to 0x00\n");
-00273                 UNS8 transmitiontype = 0x00;
-00274                 writeNetworkDictCallBack (&TestMaster_Data, /*CO_Data* d*/
-00275                                         2, /*UNS8 nodeId*/
-00276                                         0x1802, /*UNS16 index*/
-00277                                         0x02, /*UNS16 index*/
-00278                                         1, /*UNS8 count*/
-00279                                         0, /*UNS8 dataType*/
-00280                                         &transmitiontype,/*void *data*/
-00281                                         CheckSDO); /*SDOCallback_t Callback*/
-00282         }
-00283         MasterSyncCount++;
-00284 }
-

Generated on Mon Jul 2 19:10:16 2007 for CanFestival by  - -doxygen 1.5.1
- -