2 Copyright (C): Giuseppe Massimo BERTANI
3 gmbertani@users.sourceforge.net
6 See COPYING file for copyrights details.
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.
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.
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
28 * This file is part of SillySlave demo for CANfestival
29 * open source CANopen stack.
32 #include "SillySlave.h"
37 static UNS8 slaveNode = 0;
39 void InitNode(CO_Data* d, UNS32 id)
41 /* Defining the node Id */
42 setNodeId(&SillySlave_Data, slaveNode);
44 setState(&SillySlave_Data, Initialisation);
47 void Exit(CO_Data* d, UNS32 id)
50 setState(&SillySlave_Data, Stopped);
53 INTEGER8 InitCANdevice( UNS8 bus, UNS32 baudrate, UNS8 node )
59 sprintf(busName, "%u", bus);
60 sprintf(baudRate, "%u", baudrate);
61 board.busname = busName;
62 board.baudrate = baudRate;
66 SillySlave_Data.heartbeatError = SillySlave_heartbeatError;
67 SillySlave_Data.initialisation = SillySlave_initialisation;
68 SillySlave_Data.preOperational = SillySlave_preOperational;
69 SillySlave_Data.operational = SillySlave_operational;
70 SillySlave_Data.stopped = SillySlave_stopped;
71 SillySlave_Data.post_sync = SillySlave_post_sync;
72 SillySlave_Data.post_TPDO = SillySlave_post_TPDO;
73 SillySlave_Data.storeODSubIndex = SillySlave_storeODSubIndex;
74 SillySlave_Data.post_emcy = SillySlave_post_emcy;
76 if(!canOpen(&board, &SillySlave_Data))
78 printf("\n\aInitCANdevice() CAN bus %s opening error, baudrate=%s\n",board.busname, board.baudrate);
83 printf("\nInitCANdevice(), canOpen() OK, starting timer loop...\n");
85 /* Start timer thread */
86 StartTimerLoop(&InitNode);
90 printf("\nFinishing.\n");
92 /* Stop timer thread */
97 void SillySlave_heartbeatError(CO_Data* d, UNS8 heartbeatID)
99 printf("SillySlave_heartbeatError %d\n", heartbeatID);
102 void SillySlave_initialisation(CO_Data* d )
104 UNS32 PDO1_COBID = 0x0180 + NODE_MASTER;
105 UNS8 size = sizeof(PDO1_COBID);
107 printf("SillySlave_initialisation\n");
109 /* sets TXPDO1 COB-ID to match master node ID */
111 &SillySlave_Data, /*CO_Data* d*/
112 0x1800, /*UNS16 index*/
113 0x01, /*UNS8 subind*/
114 &PDO1_COBID, /*void * pSourceData,*/
115 &size, /* UNS8 * pExpectedSize*/
116 RW); /* UNS8 checkAccess */
118 /* value sent to master at each SYNC received */
122 void SillySlave_preOperational(CO_Data* d)
124 printf("SillySlave_preOperational\n");
127 void SillySlave_operational(CO_Data* d)
129 printf("SillySlave_operational\n");
132 void SillySlave_stopped(CO_Data* d)
134 printf("SillySlave_stopped\n");
137 void SillySlave_post_sync(CO_Data* d)
139 printf("SillySlave_post_sync: \n");
143 void SillySlave_post_TPDO(CO_Data* d)
145 printf("SillySlave_post_TPDO: \n");
146 printf("LifeSignal = %u\n", LifeSignal);
149 void SillySlave_storeODSubIndex(CO_Data* d, UNS16 wIndex, UNS8 bSubindex)
152 * - call getODEntry for index and subindex,
153 * - save content to file, database, flash, nvram, ...
155 * To ease flash organisation, index of variable to store
156 * can be established by scanning d->objdict[d->ObjdictSize]
157 * for variables to store.
160 printf("SillySlave_storeODSubIndex : %4.4x %2.2xh\n", wIndex, bSubindex);
163 void SillySlave_post_emcy(CO_Data* d, UNS8 nodeID, UNS16 errCode, UNS8 errReg)
165 printf("Slave received EMCY message. Node: %2.2xh ErrorCode: %4.4x ErrorRegister: %2.2xh\n", nodeID, errCode, errReg);