library for C++ CANOpen implementation. mbed independant, but is easy to attach into with mbed.
Dependents: ppCANOpen_Example DISCO-F746NG_rtos_test
Example:
Import programppCANOpen_Example
I am no longer actively working on the ppCANOpen library, however, I want to publish this project so that anyone who wants to pick up any of the pieces can have a good example. This is a a project I was working on using the ppCANOpen library. It has a pretty in deep use of the object dictionary structure. And a number of functions to control high voltage pinball drivers, if you're into that sort of thing.
source/Node.cpp
- Committer:
- ptpaterson
- Date:
- 2016-01-04
- Revision:
- 3:12b3c25bdeba
- Parent:
- 2:c724ff3a4e4d
- Child:
- 4:2034b04c86d2
File content as of revision 3:12b3c25bdeba:
/** ****************************************************************************** * @file * @author Paul Paterson * @version * @date 2015-12-14 * @brief CANOpen implementation library ****************************************************************************** * @attention * * <h2><center>© COPYRIGHT(c) 2015 Paul Paterson * * All rights reserved. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include "Node.h" #include "ServiceProvider.h" #include "ObjectDictionary.h" namespace ppCANOpen { Node::Node (ServiceProvider * provider) { provider->AddNode(this); } /*============================================================================= * Methods to handle message indication and confirmation *============================================================================= */ int Node::DispatchMessage(CanOpenMessage *canOpenMsg) { int command = MESSAGE_GET_COMMAND(canOpenMsg->id); int nodeId = MESSAGE_GET_NODEID(canOpenMsg->id); switch (command) { case CANOPEN_FUNCTION_CODE_NMT: if (canOpenMsg->data[0] == nodeId) { HandleNodeControl ((int)canOpenMsg->data[1]); } break; default: break; } return 1; } /*============================================================================= * Methods to handle message indication and confirmation *============================================================================= */ int Node::ConsumePdo (const int pdoNum, char *const data) { return 0; } int Node::HandlePdoReadRequest (const int pdoNum) { return 0; } int Node::ConsumeEmergency (void) { return 0; } int Node::HandleNodeControl (int commandSpecifier) { int result = 0; switch (commandSpecifier) { case NMT_CS_START: if (state.nmtState != NMT_STATE_INITIALIZED) { state.nmtState = NMT_STATE_OPERATIONAL; state.bBoot = 0; state.bSDO = 1; state.bEmergency = 1; state.bSYNC = 1; state.bLifeGuard = 1; state.bPDO = 1; state.bLSS = 0; OnOperational(); result = 1; } break; case NMT_CS_STOP: if (state.nmtState != NMT_STATE_INITIALIZED) { state.nmtState = NMT_STATE_STOPPED; state.bBoot = 0; state.bSDO = 0; state.bEmergency = 0; state.bSYNC = 0; state.bLifeGuard = 1; state.bPDO = 0; state.bLSS = 1; } OnStopped(); result = 1; break; case NMT_CS_ENTER_PREOP: state.nmtState = NMT_STATE_PREOPERATIONAL; state.bBoot = 0; state.bSDO = 1; state.bEmergency = 1; state.bSYNC = 1; state.bLifeGuard = 1; state.bPDO = 0; state.bLSS = 1; OnPreoperational(); result = 1; break; case NMT_CS_RESET_NODE: case NMT_CS_RESET_COM: state.nmtState = NMT_STATE_INITIALIZED; state.bBoot = 1; state.bSDO = 0; state.bEmergency = 0; state.bSYNC = 0; state.bLifeGuard = 0; state.bPDO = 0; state.bLSS = 0; OnInitialize(); result = 1; break; default: break; } return result; } int Node::HandleNodeGuardRequest (const int masterId) { return 0; } int Node::ConsumeHeartbeat (const int producerId) { return 0; } /*============================================================================= * Methods to handle operation of node device *============================================================================= */ void Node::Update (void) { if (NMT_STATE_OPERATIONAL == state.nmtState) { OnUpdate(); } } /*============================================================================= * Methods to implement node control in derived classes *============================================================================= */ /*============================================================================= * Local functions *============================================================================= */ } /* namspace ppCANOpen */