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/CanOpenMessage.h
- Revision:
- 5:22a337cdc0e3
- Parent:
- 4:2034b04c86d2
--- a/include/CanOpenMessage.h Sat Jan 09 17:15:29 2016 +0000 +++ b/include/CanOpenMessage.h Sat Feb 13 20:22:59 2016 +0000 @@ -29,6 +29,8 @@ #ifndef PPCAN_CANOPEN_MESSAGE_H #define PPCAN_CANOPEN_MESSAGE_H +#include "stdint.h" + #ifdef __cplusplus extern "C" { #endif @@ -54,13 +56,91 @@ /** CANOpen Message */ typedef struct CanOpenMessage { - unsigned int id; - char data[8]; + uint32_t id; + uint8_t data[8]; CanOpenFormat format; CanOpenType type; - unsigned char dataCount; + uint8_t dataCount; } CanOpenMessage; + +/*========================================================================= + * CANOpen Function Codes + *========================================================================= + */ + +/** CANOpen Function Codes */ +typedef enum { + CANOPEN_FUNCTION_CODE_NMT = 0x00, + CANOPEN_FUNCTION_CODE_SYNC = 0x01, + CANOPEN_FUNCTION_CODE_TIME = 0x02, + CANOPEN_FUNCTION_CODE_PDO1T = 0x03, + CANOPEN_FUNCTION_CODE_PDO1R = 0x04, + CANOPEN_FUNCTION_CODE_PDO2T = 0x05, + CANOPEN_FUNCTION_CODE_PDO2R = 0x06, + CANOPEN_FUNCTION_CODE_PDO3T = 0x07, + CANOPEN_FUNCTION_CODE_PDO3R = 0x08, + CANOPEN_FUNCTION_CODE_PDO4T = 0x09, + CANOPEN_FUNCTION_CODE_PDO4R = 0x0A, + CANOPEN_FUNCTION_CODE_SDOT = 0x0B, + CANOPEN_FUNCTION_CODE_SDOR = 0x0C, + CANOPEN_FUNCTION_CODE_NODE_GUARD = 0x0E, + CANOPEN_FUNCTION_CODE_LSS = 0x0F +} CanOpenFunctionCodes; + +/* Message Constants */ +#define MESSAGE_NODEID_BITS 0b00001111111 +#define MESSAGE_COMMAND_BITS 0b11110000000 + +/* Message Macros -----------------------------------------------------------*/ +#define MESSAGE_GET_NODEID(cobId) (cobId & MESSAGE_NODEID_BITS) +#define MESSAGE_GET_COMMAND(cobId) ((cobId & MESSAGE_COMMAND_BITS) >> 7) + +/*========================================================================= + * SDO MESSAGE PARAMETERS + *========================================================================= + */ + +/** SDO initiate protocol command specifiers */ +typedef enum { + SDO_CCS_DOWNLOAD_SEGMENT_REQUEST = 0x00, + SDO_CCS_INITIATE_DOWNLOAD_REQUEST = 0x01, + SDO_CCS_INITIATE_UPLOAD_REQUEST = 0x02, +} SdoClientCommandSpecifier; + +/** SDO segment protocol command specifiers */ +typedef enum { + SDO_SCS_DOWNLOAD_SEGMENT_RESPONSE = 0x01, + SDO_SCS_INITIATE_UPLOAD_RESPONSE = 0x02, + SDO_SCS_INITIATE_DOWNLOAD_RESPONSE = 0x03, +} SdoServerCommandSpecifier; + +/* SDO constants --------------------------------------------------------*/ +#define SDO_SIZE_INDICATOR_BIT 0b00000001 +#define SDO_TRANSFER_TYPE_BIT 0b00000010 +#define SDO_DATA_COUNT_BITS 0b00001100 +#define SDO_TOGGLE_BIT 0b00010000 +#define SDO_CS_BITS 0b11100000 + +/* SDO macros -----------------------------------------------------------*/ +#define SDO_GET_CS(data0) ((data0 & SDO_CS_BITS) >> 5) +#define SDO_GET_DATA_COUNT(data0) ((data0 & SDO_DATA_COUNT_BITS) >> 2) + + +/*========================================================================= + * NMT MESSAGE PARAMETERS + *========================================================================= + */ + +/** NMT node control protocol command specifiers */ +typedef enum { + NMT_CS_START = 0x01, + NMT_CS_STOP = 0x02, + NMT_CS_ENTER_PREOP = 0x80, + NMT_CS_RESET_NODE = 0x81, + NMT_CS_RESET_COM = 0x82 +} NmtCommandSpecifier; + #ifdef __cplusplus }; #endif