etisserant@0: /* etisserant@0: This file is part of CanFestival, a library implementing CanOpen Stack. etisserant@0: etisserant@0: Copyright (C): Edouard TISSERANT and Francis DUPIN etisserant@0: etisserant@0: See COPYING file for copyrights details. etisserant@0: etisserant@0: This library is free software; you can redistribute it and/or etisserant@0: modify it under the terms of the GNU Lesser General Public etisserant@0: License as published by the Free Software Foundation; either etisserant@0: version 2.1 of the License, or (at your option) any later version. etisserant@0: etisserant@0: This library is distributed in the hope that it will be useful, etisserant@0: but WITHOUT ANY WARRANTY; without even the implied warranty of etisserant@0: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU etisserant@0: Lesser General Public License for more details. etisserant@0: etisserant@0: You should have received a copy of the GNU Lesser General Public etisserant@0: License along with this library; if not, write to the Free Software etisserant@0: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA etisserant@0: */ etisserant@0: greg@528: /** @defgroup statemachine State Machine greg@528: * @ingroup userapi greg@528: */ greg@528: etisserant@0: #ifndef __states_h__ etisserant@0: #define __states_h__ etisserant@0: etisserant@0: #include etisserant@0: frdupin@71: /* The nodes states frdupin@71: * ----------------- frdupin@71: * values are choosen so, that they can be sent directly frdupin@71: * for heartbeat messages... frdupin@71: * Must be coded on 7 bits only frdupin@71: * */ etisserant@0: /* Should not be modified */ etisserant@0: enum enum_nodeState { etisserant@0: Initialisation = 0x00, etisserant@0: Disconnected = 0x01, etisserant@0: Connecting = 0x02, etisserant@0: Preparing = 0x02, etisserant@0: Stopped = 0x04, etisserant@0: Operational = 0x05, etisserant@0: Pre_operational = 0x7F, etisserant@357: Unknown_state = 0x0F etisserant@0: }; etisserant@0: etisserant@0: typedef enum enum_nodeState e_nodeState; etisserant@0: etisserant@0: typedef struct etisserant@0: { etisserant@291: INTEGER8 csBoot_Up; etisserant@291: INTEGER8 csSDO; etisserant@291: INTEGER8 csEmergency; etisserant@291: INTEGER8 csSYNC; mwildbolz@750: INTEGER8 csLifeGuard; etisserant@291: INTEGER8 csPDO; etisserant@343: INTEGER8 csLSS; etisserant@0: } s_state_communication; etisserant@0: greg@528: /** greg@528: * @brief Function that user app can overload greg@529: * @ingroup statemachine etisserant@0: */ etisserant@378: typedef void (*initialisation_t)(CO_Data*); etisserant@378: typedef void (*preOperational_t)(CO_Data*); etisserant@378: typedef void (*operational_t)(CO_Data*); etisserant@378: typedef void (*stopped_t)(CO_Data*); etisserant@0: greg@528: /** greg@530: * @ingroup statemachine greg@528: * @brief Function that user app can overload greg@528: * @param *d Pointer on a CAN object data structure greg@528: */ greg@528: void _initialisation(CO_Data* d); greg@528: greg@528: /** greg@530: * @ingroup statemachine greg@528: * @brief Function that user app can overload greg@528: * @param *d Pointer on a CAN object data structure greg@528: */ greg@528: void _preOperational(CO_Data* d); greg@528: greg@530: /** greg@530: * @ingroup statemachine greg@528: * @brief Function that user app can overload greg@528: * @param *d Pointer on a CAN object data structure greg@528: */ greg@528: void _operational(CO_Data* d); greg@528: greg@528: /** greg@530: * @ingroup statemachine greg@528: * @brief Function that user app can overload greg@528: * @param *d Pointer on a CAN object data structure greg@528: */ greg@528: void _stopped(CO_Data* d); etisserant@149: etisserant@0: #include "data.h" etisserant@0: etisserant@0: /************************* prototypes ******************************/ etisserant@0: greg@528: /** greg@528: * @brief Called by driver/app when receiving messages greg@528: * @param *d Pointer on a CAN object data structure greg@528: * @param *m Pointer on a CAN message structure greg@528: */ etisserant@0: void canDispatch(CO_Data* d, Message *m); etisserant@0: greg@528: /** greg@528: * @ingroup statemachine greg@528: * @brief Returns the state of the node greg@528: * @param *d Pointer on a CAN object data structure greg@528: * @return The node state greg@528: */ etisserant@0: e_nodeState getState (CO_Data* d); etisserant@0: greg@528: /** greg@528: * @ingroup statemachine greg@528: * @brief Change the state of the node greg@528: * @param *d Pointer on a CAN object data structure greg@528: * @param newState The state to assign greg@528: * @return greg@528: */ etisserant@0: UNS8 setState (CO_Data* d, e_nodeState newState); etisserant@0: greg@528: /** greg@528: * @ingroup statemachine greg@528: * @brief Returns the nodId greg@528: * @param *d Pointer on a CAN object data structure greg@528: * @return greg@528: */ etisserant@0: UNS8 getNodeId (CO_Data* d); etisserant@0: greg@528: /** greg@528: * @ingroup statemachine greg@528: * @brief Define the node ID. Initialize the object dictionary greg@528: * @param *d Pointer on a CAN object data structure greg@528: * @param nodeId The node ID to assign greg@528: */ etisserant@0: void setNodeId (CO_Data* d, UNS8 nodeId); etisserant@0: greg@528: /** greg@528: * @brief Some stuff to do when the node enter in pre-operational mode greg@528: * @param *d Pointer on a CAN object data structure etisserant@0: */ etisserant@0: void initPreOperationalMode (CO_Data* d); etisserant@0: etisserant@0: #endif