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.
Diff: include/ServiceProvider.h
- Revision:
- 5:22a337cdc0e3
- Parent:
- 4:2034b04c86d2
--- a/include/ServiceProvider.h Sat Jan 09 17:15:29 2016 +0000
+++ b/include/ServiceProvider.h Sat Feb 13 20:22:59 2016 +0000
@@ -51,65 +51,117 @@
{
public:
-
-
ServiceProvider (void);
~ServiceProvider (void);
+ /* ========================================================================
+ * Public Methods
+ * ========================================================================
+ */
+
+ /* Main application -----------------------------------------------------*/
/** Main loop */
void Run (void);
- /** Register a node to get messages and get update calls
- * @note
- * @param
- * @retval
- */
+ /** Iterate through Nodes and update */
+ void UpdateNodes(void);
+
+ /** C helper function to pass to API */
+ static void UpdateNodes_CWrapper(void *pServiceObject);
+
+ /* Node Management ------------------------------------------------------*/
+ /** Register a node to get messages and get update calls */
int AddNode (Node * node);
- /** Register a node to get messages and get update calls
- * @note
- * @param
- * @retval
- */
+ // TODO: remove node (swap pointers to fill in nicely
+
- /** Add a message to the message queue outbox
- * @note
- * @param
+ /* CanMessage Transmission ----------------------------------------------*/
+ /** Add a message to the message queue outbox */
+ void PostMessage (int nodeId, CanOpenMessage * msg);
+
+ /** quick way to create and send an NMT Control message
+ * @note Make posting a message easier!
*/
- void PostMessage (CanOpenMessage * msg);
+ void PostNmtControl (char targetNodeId, NmtCommandSpecifier cs);
+
+ /* Elapsed Time ---------------------------------------------------------*/
+ /** A way for the the Nodes to get elapsed time when they want it */
+ uint32_t GetTime(void);
- // TODO: remove node (swap pointers to fill in nicely
private:
+ /* ========================================================================
+ * Private Constants
+ * ========================================================================
+ */
- /** define size of arrays in one place */
+ /** Define size of arrays in one place */
static const int SERVICE_MAX_NODES = 8;
/* ========================================================================
- * Private Members
+ * Private Methods
* ========================================================================
*/
- /** array of messages in a queue
- * @note twice number of max nodes is a bit arbitrary. Will need at
- * least max nodes, but not sure how much more to be safe.
+ /* CanMessage Reading ---------------------------------------------------*/
+ /** Function to be called on every CAN read interrupt */
+ void ReadIT(void);
+
+ /** C helper function used to pass ReadIT() to API */
+ static void ReadIT_CWrapper(void *pServiceObject);
+
+ /** Helper function that utilizes backup message inbox when the main one
+ * is locked by the application.
*/
- std::queue<CanOpenMessage> outbox;
- //CanOpenMessage outbox[SERVICE_MAX_NODES * 2];
- //int messageCount;
+ void ReadIT_clearBuffer(void);
- /** array of nodes to cycle through.
- * @note
+ /* Elapsed Time ---------------------------------------------------------*/
+ /** Synchronize elapsed time*/
+ void HandleTimeMessage(CanOpenMessage *canOpenMsg);
+
+
+ /* ========================================================================
+ * Private Member Variables
+ * ========================================================================
*/
+
+ /* Node Management -------------------------------------------------------*/
+ /** array of nodes to cycle through. */
Node * nodes[SERVICE_MAX_NODES];
- /** Keeps count of current number of nodes.
- * @note
+ /** Keeps count of current number of nodes. */
+ int nodeCount;
+
+ /* CanMessage Reading ---------------------------------------------------*/
+ /** array of messages in a queue */
+ std::queue<CanOpenMessage> inbox;
+
+ /** Extra buffer only handled by ISR. Used if inbox is locked */
+ std::queue<CanOpenMessage> inboxBuffer;
+
+ /** boolean to lock and unlock inbox */
+ int bInboxUnlocked;
+
+ /** Data to keep track of internal messages. Node ID allows SP to avoid
+ * dispatching message to the one who sent it
*/
- int nodeCount;
+ struct InternalMessage {
+ int nodeId;
+ CanOpenMessage message;
+
+ InternalMessage(uint8_t n, CanOpenMessage m):
+ nodeId(n),
+ message(m)
+ {}
+ };
+
+ /** array of messages in a queue */
+ std::queue<InternalMessage> outbox;
- /** stores handle for can open api */
- CanOpenHandle * hCanOpen;
-
+ /* Elapsed Time ---------------------------------------------------------*/
+ /** Elapsed time offset used for synchronization*/
+ int32_t elapsedTimeOffset;
+
};
} /* namspace ppCANOpen */
