]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - include/states.h
fixed : deprecation warning with the module "sets" when using python 2.6
[CanFestival-3.git] / include / states.h
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 /** @defgroup statemachine State Machine
24  *  @ingroup userapi
25  */
26  
27 #ifndef __states_h__
28 #define __states_h__
29
30 #include <applicfg.h>
31
32 /* The nodes states 
33  * -----------------
34  * values are choosen so, that they can be sent directly
35  * for heartbeat messages...
36  * Must be coded on 7 bits only
37  * */
38 /* Should not be modified */
39 enum enum_nodeState {
40   Initialisation  = 0x00, 
41   Disconnected    = 0x01,
42   Connecting      = 0x02,
43   Preparing       = 0x02,
44   Stopped         = 0x04,
45   Operational     = 0x05,
46   Pre_operational = 0x7F,
47   Unknown_state   = 0x0F
48 };
49
50 typedef enum enum_nodeState e_nodeState;
51
52 typedef struct
53 {
54         INTEGER8 csBoot_Up;
55         INTEGER8 csSDO;
56         INTEGER8 csEmergency;
57         INTEGER8 csSYNC;
58         INTEGER8 csHeartbeat;
59         INTEGER8 csPDO;
60         INTEGER8 csLSS;
61 } s_state_communication;
62
63 /** 
64  * @brief Function that user app can overload
65  * @ingroup statemachine
66  */
67 typedef void (*initialisation_t)(CO_Data*);
68 typedef void (*preOperational_t)(CO_Data*);
69 typedef void (*operational_t)(CO_Data*);
70 typedef void (*stopped_t)(CO_Data*);
71
72 /** 
73  * @ingroup statemachine
74  * @brief Function that user app can overload
75  * @param *d Pointer on a CAN object data structure
76  */
77 void _initialisation(CO_Data* d);
78
79 /** 
80  * @ingroup statemachine
81  * @brief Function that user app can overload
82  * @param *d Pointer on a CAN object data structure
83  */
84 void _preOperational(CO_Data* d);
85
86 /**
87  * @ingroup statemachine 
88  * @brief Function that user app can overload
89  * @param *d Pointer on a CAN object data structure
90  */
91 void _operational(CO_Data* d);
92
93 /** 
94  * @ingroup statemachine
95  * @brief Function that user app can overload
96  * @param *d Pointer on a CAN object data structure
97  */
98 void _stopped(CO_Data* d);
99
100 #include "data.h"
101
102 /************************* prototypes ******************************/
103
104 /** 
105  * @brief Called by driver/app when receiving messages
106  * @param *d Pointer on a CAN object data structure
107  * @param *m Pointer on a CAN message structure
108  */
109 void canDispatch(CO_Data* d, Message *m);
110
111 /** 
112  * @ingroup statemachine
113  * @brief Returns the state of the node
114  * @param *d Pointer on a CAN object data structure
115  * @return The node state
116  */
117 e_nodeState getState (CO_Data* d);
118
119 /** 
120  * @ingroup statemachine
121  * @brief Change the state of the node 
122  * @param *d Pointer on a CAN object data structure
123  * @param newState The state to assign
124  * @return 
125  */
126 UNS8 setState (CO_Data* d, e_nodeState newState);
127
128 /**
129  * @ingroup statemachine 
130  * @brief Returns the nodId 
131  * @param *d Pointer on a CAN object data structure
132  * @return
133  */
134 UNS8 getNodeId (CO_Data* d);
135
136 /** 
137  * @ingroup statemachine
138  * @brief Define the node ID. Initialize the object dictionary
139  * @param *d Pointer on a CAN object data structure
140  * @param nodeId The node ID to assign
141  */
142 void setNodeId (CO_Data* d, UNS8 nodeId);
143
144 /** 
145  * @brief Some stuff to do when the node enter in pre-operational mode
146  * @param *d Pointer on a CAN object data structure
147  */
148 void initPreOperationalMode (CO_Data* d);
149
150 #endif