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.

Revision:
3:12b3c25bdeba
Parent:
2:c724ff3a4e4d
Child:
4:2034b04c86d2
--- a/source/Node.cpp	Wed Dec 30 13:33:41 2015 +0000
+++ b/source/Node.cpp	Mon Jan 04 06:10:49 2016 +0000
@@ -27,12 +27,39 @@
  */
 
 #include "Node.h"
+#include "ServiceProvider.h"
 #include "ObjectDictionary.h"
 
 namespace ppCANOpen
 {
 
-Node::Node (void) {}
+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
@@ -54,9 +81,73 @@
     return 0;
 }
 
-int Node::HandleNodeControl (void)
+int Node::HandleNodeControl (int commandSpecifier)
 {
-    return 0;
+    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)
@@ -76,7 +167,9 @@
  
 void Node::Update (void)
 {
-     
+     if (NMT_STATE_OPERATIONAL == state.nmtState) {
+        OnUpdate();
+     }
 }
 
 /*=============================================================================
@@ -84,11 +177,6 @@
  *=============================================================================
  */
 
-void Node::OnInitialize (void){}
-void Node::OnPreoperational (void){}
-void Node::OnOperational (void){}
-void Node::OnStopped (void){}
-
 /*=============================================================================
  * Local functions
  *=============================================================================