examples/TestMasterSlave/Master.c
changeset 0 4472ee7c6c3e
child 149 fe50ada8020b
equal deleted inserted replaced
-1:000000000000 0:4472ee7c6c3e
       
     1 /*
       
     2 This file is part of CanFestival, a library implementing CanOpen Stack. 
       
     3 
       
     4 Copyright (C): Edouard TISSERANT and Francis DUPIN
       
     5 
       
     6 See COPYING file for copyrights details.
       
     7 
       
     8 This library is free software; you can redistribute it and/or
       
     9 modify it under the terms of the GNU Lesser General Public
       
    10 License as published by the Free Software Foundation; either
       
    11 version 2.1 of the License, or (at your option) any later version.
       
    12 
       
    13 This library is distributed in the hope that it will be useful,
       
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    16 Lesser General Public License for more details.
       
    17 
       
    18 You should have received a copy of the GNU Lesser General Public
       
    19 License along with this library; if not, write to the Free Software
       
    20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    21 */
       
    22 
       
    23 #include "Master.h"
       
    24 #include "Slave.h"
       
    25 #include "TestMasterSlave.h"
       
    26 
       
    27 /*****************************************************************************/
       
    28 void TestMaster_heartbeatError(UNS8 heartbeatID)
       
    29 {
       
    30 	eprintf("TestMaster_heartbeatError %d\n", heartbeatID);
       
    31 }
       
    32 
       
    33 /*****************************************************************************/
       
    34 void TestMaster_SDOtimeoutError (UNS8 line)
       
    35 {
       
    36 	eprintf("TestMaster_SDOtimeoutError %d\n", line);
       
    37 }
       
    38 
       
    39 /*****************************************************************************/
       
    40 // CanSend store message in a FIFO, for Slave
       
    41 UNS8 TestMaster_canSend(Message *m)
       
    42 {
       
    43 	eprintf("M->S ");
       
    44 	print_message(m);
       
    45 	canSend(MasterCanHandle, m);
       
    46 	return 0;
       
    47 }
       
    48 
       
    49 void TestMaster_initialisation()
       
    50 {
       
    51 	eprintf("TestMaster_initialisation\n");
       
    52 }
       
    53 
       
    54 void TestMaster_preOperational()
       
    55 {
       
    56 	eprintf("TestMaster_preOperational\n");
       
    57 }
       
    58 
       
    59 void TestMaster_operational()
       
    60 {
       
    61 	eprintf("TestMaster_operational\n");
       
    62 }
       
    63 
       
    64 void TestMaster_stopped()
       
    65 {
       
    66 	eprintf("TestMaster_stopped\n");
       
    67 }
       
    68 
       
    69 void TestMaster_post_sync()
       
    70 {
       
    71 	eprintf("TestMaster_post_sync\n");
       
    72 	eprintf("Master: %d %d %d %d\n",MasterMap1, MasterMap2, MasterMap3, MasterMap4);
       
    73 }
       
    74 
       
    75 char query_result = 0;
       
    76 char waiting_answer = 0;
       
    77 
       
    78 void TestMaster_post_TPDO()
       
    79 {
       
    80 	eprintf("TestMaster_post_TPDO\n");
       
    81 
       
    82 //	{
       
    83 //		char zero = 0;
       
    84 //		if(MasterMap4 > 0x80){
       
    85 //			writeNetworkDict (
       
    86 //				&TestMaster_Data,
       
    87 //				TestSlave_Data->bDeviceNodeId,
       
    88 //				0x2002,
       
    89 //				0x00,
       
    90 //				1,
       
    91 //				0,
       
    92 //				&zero); 
       
    93 //		}
       
    94 //	}
       
    95 
       
    96 	if(waiting_answer){
       
    97 		UNS32 abortCode;			
       
    98 		UNS8 size;			
       
    99 		switch(getReadResultNetworkDict (
       
   100 			&TestMaster_Data, 
       
   101 			*TestSlave_Data.bDeviceNodeId,
       
   102 			&query_result,
       
   103 			&size,
       
   104 			&abortCode))
       
   105 		{
       
   106 			case SDO_FINISHED:
       
   107 				/* Do something with result here !!*/
       
   108 				eprintf("Got SDO answer (0x2002, 0x00), %d %d\n",query_result,size);
       
   109 			case SDO_ABORTED_RCV:
       
   110 			case SDO_ABORTED_INTERNAL:
       
   111 			case SDO_RESET:
       
   112 				waiting_answer = 0;
       
   113 				closeSDOtransfer(
       
   114 					&TestMaster_Data,
       
   115 					*TestSlave_Data.	bDeviceNodeId,
       
   116 					SDO_CLIENT);
       
   117 			break;
       
   118 			case SDO_DOWNLOAD_IN_PROGRESS:
       
   119 			case SDO_UPLOAD_IN_PROGRESS:
       
   120 			break;
       
   121 		}
       
   122 	}else if(MasterMap1 % 10 == 0){
       
   123 		readNetworkDict (
       
   124 			&TestMaster_Data,
       
   125 			*TestSlave_Data.bDeviceNodeId,
       
   126 			0x2002,
       
   127 			0x00,
       
   128 			0);
       
   129 		waiting_answer = 1;
       
   130 	}
       
   131 		
       
   132 }