]> rtime.felk.cvut.cz Git - CanFestival-3.git/blobdiff - examples/TestMasterSlave/Master.c
*** empty log message ***
[CanFestival-3.git] / examples / TestMasterSlave / Master.c
index 1677438dc1b6ce0634cc2f9889997858f65bdc49..6967a622bee2e8514b7c65814b4285143a1b875f 100644 (file)
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include "Slave.h"
 #include "TestMasterSlave.h"
 
+extern s_BOARD MasterBoard;
 /*****************************************************************************/
 void TestMaster_heartbeatError(CO_Data* d, UNS8 heartbeatID)
 {
@@ -61,11 +62,11 @@ void TestMaster_initialisation(CO_Data* d)
                        &PDO2_COBID, /*void * pSourceData,*/ 
                        &size, /* UNS8 * pExpectedSize*/
                        RW);  /* UNS8 checkAccess */
-                       
+                                       
 }
 
 // Step counts number of times ConfigureSlaveNode is called
-static init_step = 0;
+static int init_step = 0;
 
 /*Froward declaration*/
 static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId);
@@ -85,8 +86,8 @@ static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
 
 /********************************************************
  * ConfigureSlaveNode is responsible to
- *  - setup slave TPDO 1 transmit time
- *  - setup slave TPDO 2 transmit time
+ *  - setup slave TPDO 1 transmit type
+ *  - setup slave TPDO 2 transmit type
  *  - switch to operational mode
  *  - send NMT to slave
  ********************************************************
@@ -94,7 +95,7 @@ static void CheckSDOAndContinue(CO_Data* d, UNS8 nodeId)
  * Network Dictionary Access (SDO) with Callback 
  * Slave node state change request (NMT) 
  ********************************************************
- * This is called first by TestMaster_preOperational
+ * This is called first by TestMaster_post_SlaveBootup
  * then it called again each time a SDO exchange is
  * finished.
  ********************************************************/
@@ -146,212 +147,10 @@ static void ConfigureSlaveNode(CO_Data* d, UNS8 nodeId)
        }
 }
 
-#ifdef CO_ENABLE_LSS
-static void ConfigureLSSNode(CO_Data* d);
-// Step counts number of times ConfigureLSSNode is called
-UNS8 init_step_LSS=1;
-
-static void CheckLSSAndContinue(CO_Data* d, UNS8 command)
-{
-       UNS32 dat1;
-       UNS8 dat2;
-       printf("CheckLSS->");
-       if(getConfigResultNetworkNode (d, command, &dat1, &dat2) != LSS_FINISHED){
-               if(command==LSS_IDENT_REMOTE_NON_CONF){
-                       eprintf("Master : There are not no-configured slaves in the net\n", command);
-                       return;
-               }
-               else{
-                       eprintf("Master : Failed in LSS comand %d.  Trying again\n", command);
-               }
-       }
-       else
-       {
-               init_step_LSS++;
-       
-               switch(command){
-               case LSS_CONF_NODE_ID:
-                       switch(dat1){
-                               case 0: printf("Node ID change succesful\n");break;
-                               case 1: printf("Node ID change error:out of range\n");break;
-                               case 0xFF:printf("Node ID change error:specific error\n");break;
-                               default:break;
-                       }
-                       break;
-               case LSS_CONF_BIT_TIMING:
-                       switch(dat1){
-                               case 0: printf("Baud rate change succesful\n");break;
-                               case 1: printf("Baud rate change error: change baud rate not supported\n");break;
-                               case 0xFF:printf("Baud rate change error:specific error\n");break;
-                               default:break;
-                       }
-                       break;
-               case LSS_CONF_STORE:
-                       switch(dat1){
-                               case 0: printf("Store configuration succesful\n");break;
-                               case 1: printf("Store configuration error:not supported\n");break;
-                               case 0xFF:printf("Store configuration error:specific error\n");break;
-                               default:break;
-                       }
-                       break;
-               case LSS_SM_SELECTIVE_SERIAL:
-                       printf("Slave in CONFIGURATION mode\n");
-                       break;
-               case LSS_IDENT_REMOTE_SERIAL_HIGH:
-                       printf("node identified\n");
-                       break;
-               case LSS_IDENT_REMOTE_NON_CONF:
-                       printf("non-configured remote slave in the net\n");
-                       break;
-               case LSS_INQ_VENDOR_ID:
-                       printf("Slave VendorID %x\n", dat1);
-                       break;
-               case LSS_INQ_PRODUCT_CODE:
-                       printf("Slave Product Code %x\n", dat1);
-                       break;
-               case LSS_INQ_REV_NUMBER:
-                       printf("Slave Revision Number %x\n", dat1);
-                       break;
-               case LSS_INQ_SERIAL_NUMBER:
-                       printf("Slave Serial Number %x\n", dat1);
-                       break;
-               case LSS_INQ_NODE_ID:
-                       printf("Slave nodeid %x\n", dat1);
-                       break;
-#ifdef CO_ENABLE_LSS_FS
-               case LSS_IDENT_FASTSCAN:
-                       if(dat1==0)
-                               printf("Slave node identified with FastScan\n");
-                       else
-                       {
-                               printf("There is not unconfigured node in the net\n");
-                               return;
-                       }       
-                       init_step_LSS++;
-                       break;
-#endif         
-               }
-       }
-
-       printf("\n");
-       ConfigureLSSNode(d);
-}
-
-
-/* First ask if there is a node with an invalid nodeID.
- * If FastScan is activated it is used to put the node in the state â\80\9cconfigurationâ\80?.
- * If FastScan is not activated, identification services are used to identify the node.
- * Then  switch mode service is used to put it in configuration state.
- * Next all the inquire and configuration services are used.
- * Finally, the node LSS state is restored to â\80\9cwaitingâ\80? and all the process is repeated 
- * again until there isn't any node with a invalid nodeID.
- * */
-static void ConfigureLSSNode(CO_Data* d)
-{
-       UNS32 Vendor_ID=0x12345678;
-       UNS32 Product_Code=0x90123456;
-       UNS32 Revision_Number=0x78901234;
-       UNS32 Serial_Number=0x56789012;
-       UNS32 Revision_Number_high=0x78901240;
-       UNS32 Revision_Number_low=0x78901230;
-       UNS32 Serial_Number_high=0x56789020;
-       UNS32 Serial_Number_low=0x56789010;
-       UNS8 NodeID=0x02;
-       UNS8 Baud_Table=0;
-       UNS8 Baud_BitTiming=3;
-       UNS16 Switch_delay=1;
-       UNS8 LSS_mode=LSS_WAITING_MODE;
-       UNS8 res;
-       eprintf("ConfigureLSSNode -> ",0);
-
-       switch(init_step_LSS){
-               case 1: /* LSS=>identify non-configured remote slave */
-                       eprintf("LSS=>identify non-configured remote slave\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_NON_CONF,0,0,CheckLSSAndContinue);
-                       break;
-#ifdef CO_ENABLE_LSS_FS
-               case 2: /* LSS=>FastScan */
-                       eprintf("LSS=>FastScan\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_FASTSCAN,0,0,CheckLSSAndContinue);
-                       break;
-#else
-               case 2: /* LSS=>identify node */
-                       eprintf("LSS=>identify node\n");
-                       res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_VENDOR,&Vendor_ID,0);
-                       res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_PRODUCT,&Product_Code,0);
-                       res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_LOW,&Revision_Number_low,0);
-                       res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_REV_HIGH,&Revision_Number_high,0);
-                       res=configNetworkNode(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_LOW,&Serial_Number_low,0);
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_SERIAL_HIGH,&Serial_Number_high,0,CheckLSSAndContinue);
-                       break;
-               case 3: /*LSS=>put in configuration mode*/
-                       eprintf("LSS=>put in configuration mode\n");
-                       res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_VENDOR,&Vendor_ID,0);
-                       res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_PRODUCT,&Product_Code,0);
-                       res=configNetworkNode(&TestMaster_Data,LSS_SM_SELECTIVE_REVISION,&Revision_Number,0);
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_SM_SELECTIVE_SERIAL,&Serial_Number,0,CheckLSSAndContinue);
-                       break;
-#endif
-               case 4: /* LSS=>inquire nodeID */
-                       eprintf("LSS=>inquire nodeID\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_NODE_ID,0,0,CheckLSSAndContinue);
-                       break;
-               case 5: /* LSS=>inquire VendorID */
-                       eprintf("LSS=>inquire VendorID\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_VENDOR_ID,0,0,CheckLSSAndContinue);
-                       break;
-               case 6: /* LSS=>inquire Product code */
-                       eprintf("LSS=>inquire Product code\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_PRODUCT_CODE,0,0,CheckLSSAndContinue);
-                       break;
-               case 7: /* LSS=>inquire Revision Number */
-                       eprintf("LSS=>inquire Revision Number\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_REV_NUMBER,0,0,CheckLSSAndContinue);
-                       break;
-               case 8: /* LSS=>inquire Serial Number */
-                       eprintf("LSS=>inquire Serial Number\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_INQ_SERIAL_NUMBER,0,0,CheckLSSAndContinue);
-                       break;
-               case 9: /* LSS=>change the nodeID */
-                       eprintf("LSS=>change the nodeId\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_CONF_NODE_ID,&NodeID,0,CheckLSSAndContinue);
-                       break;
-               case 10:        /* LSS=>change the Baud rate */
-                       eprintf("LSS=>change the Baud rate\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_CONF_BIT_TIMING,&Baud_Table,&Baud_BitTiming,CheckLSSAndContinue);
-                       break;
-               case 11:
-                       eprintf("LSS=>Activate Bit Timing\n");
-                       res=configNetworkNode(&TestMaster_Data,LSS_CONF_ACT_BIT_TIMING,&Switch_delay,0);
-                       /*no break;*/
-                       init_step_LSS++;
-               case 12:
-                       /*LSS=>store configuration*/
-                       /* It will fail the first time (time out) due to the switch delay */
-                       /* It will fail the second time because it is not implemented in the slave */
-                       eprintf("LSS=>store configuration\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_CONF_STORE,0,0,CheckLSSAndContinue);
-                       break;
-               case 13: /* LSS=>put in operation mod */
-                       eprintf("LSS=>put in operation mode\n");
-                       res=configNetworkNode(&TestMaster_Data,LSS_SM_GLOBAL,&LSS_mode,0);
-                       /* Search again for not-configured slaves*/
-                       eprintf("LSS=>identify not-configured remote slave\n");
-                       res=configNetworkNodeCallBack(&TestMaster_Data,LSS_IDENT_REMOTE_NON_CONF,0,0,CheckLSSAndContinue);
-                       init_step_LSS=1;
-                       break;
-       }
-}
-#endif
 
 void TestMaster_preOperational(CO_Data* d)
 {
        eprintf("TestMaster_preOperational\n");
-#ifdef CO_ENABLE_LSS
-       /* Ask slave node to go in stop mode */
-       masterSendNMTstateChange (&TestMaster_Data, 0, NMT_Stop_Node);
-       ConfigureLSSNode(&TestMaster_Data);
-#endif
 }
 
 void TestMaster_operational(CO_Data* d)
@@ -424,7 +223,7 @@ void TestMaster_post_TPDO(CO_Data* d)
 #if 0
        if(waiting_answer){
                UNS32 abortCode;                        
-               UNS8 size;                      
+               UNS8 size = 1;                  
                switch(getReadResultNetworkDict (
                        &TestMaster_Data, 
                        0x02,
@@ -494,6 +293,5 @@ void TestMaster_post_SlaveBootup(CO_Data* d, UNS8 nodeid)
 {
        eprintf("TestMaster_post_SlaveBootup %x\n", nodeid);
        
-       ConfigureSlaveNode(&TestMaster_Data, nodeid);
+       ConfigureSlaveNode(d, nodeid);
 }
-