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.
include/ObjectDictionary.h@4:2034b04c86d2, 2016-01-09 (annotated)
- Committer:
- ptpaterson
- Date:
- Sat Jan 09 17:15:29 2016 +0000
- Revision:
- 4:2034b04c86d2
- Parent:
- 2:c724ff3a4e4d
- Child:
- 5:22a337cdc0e3
echo ability
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ptpaterson | 2:c724ff3a4e4d | 1 | /** |
ptpaterson | 2:c724ff3a4e4d | 2 | ****************************************************************************** |
ptpaterson | 2:c724ff3a4e4d | 3 | * @file |
ptpaterson | 2:c724ff3a4e4d | 4 | * @author Paul Paterson |
ptpaterson | 2:c724ff3a4e4d | 5 | * @version |
ptpaterson | 2:c724ff3a4e4d | 6 | * @date 2015-12-14 |
ptpaterson | 2:c724ff3a4e4d | 7 | * @brief CANOpen implementation library |
ptpaterson | 2:c724ff3a4e4d | 8 | ****************************************************************************** |
ptpaterson | 2:c724ff3a4e4d | 9 | * @attention |
ptpaterson | 2:c724ff3a4e4d | 10 | * |
ptpaterson | 2:c724ff3a4e4d | 11 | * <h2><center>© COPYRIGHT(c) 2015 Paul Paterson |
ptpaterson | 2:c724ff3a4e4d | 12 | * |
ptpaterson | 2:c724ff3a4e4d | 13 | * All rights reserved. |
ptpaterson | 2:c724ff3a4e4d | 14 | |
ptpaterson | 2:c724ff3a4e4d | 15 | This program is free software: you can redistribute it and/or modify |
ptpaterson | 2:c724ff3a4e4d | 16 | it under the terms of the GNU General Public License as published by |
ptpaterson | 2:c724ff3a4e4d | 17 | the Free Software Foundation, either version 3 of the License, or |
ptpaterson | 2:c724ff3a4e4d | 18 | (at your option) any later version. |
ptpaterson | 2:c724ff3a4e4d | 19 | |
ptpaterson | 2:c724ff3a4e4d | 20 | This program is distributed in the hope that it will be useful, |
ptpaterson | 2:c724ff3a4e4d | 21 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
ptpaterson | 2:c724ff3a4e4d | 22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ptpaterson | 2:c724ff3a4e4d | 23 | GNU General Public License for more details. |
ptpaterson | 2:c724ff3a4e4d | 24 | |
ptpaterson | 2:c724ff3a4e4d | 25 | You should have received a copy of the GNU General Public License |
ptpaterson | 2:c724ff3a4e4d | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
ptpaterson | 2:c724ff3a4e4d | 27 | */ |
ptpaterson | 2:c724ff3a4e4d | 28 | |
ptpaterson | 2:c724ff3a4e4d | 29 | #ifndef PPCAN_OBJECT_DICTIONARY_H |
ptpaterson | 2:c724ff3a4e4d | 30 | #define PPCAN_OBJECT_DICTIONARY_H |
ptpaterson | 2:c724ff3a4e4d | 31 | |
ptpaterson | 2:c724ff3a4e4d | 32 | #include <stdint.h> |
ptpaterson | 2:c724ff3a4e4d | 33 | |
ptpaterson | 2:c724ff3a4e4d | 34 | namespace ppCANOpen |
ptpaterson | 2:c724ff3a4e4d | 35 | { |
ptpaterson | 2:c724ff3a4e4d | 36 | |
ptpaterson | 2:c724ff3a4e4d | 37 | /** Abstract Object Dictionary class to provide constants and virtual scan |
ptpaterson | 2:c724ff3a4e4d | 38 | * function. |
ptpaterson | 2:c724ff3a4e4d | 39 | */ |
ptpaterson | 2:c724ff3a4e4d | 40 | class ObjectDictionary |
ptpaterson | 2:c724ff3a4e4d | 41 | { |
ptpaterson | 2:c724ff3a4e4d | 42 | |
ptpaterson | 2:c724ff3a4e4d | 43 | public: |
ptpaterson | 2:c724ff3a4e4d | 44 | |
ptpaterson | 2:c724ff3a4e4d | 45 | /*========================================================================= |
ptpaterson | 2:c724ff3a4e4d | 46 | * Constants wrapped into the Object Dictionary to use with construction |
ptpaterson | 2:c724ff3a4e4d | 47 | *========================================================================= |
ptpaterson | 2:c724ff3a4e4d | 48 | */ |
ptpaterson | 2:c724ff3a4e4d | 49 | |
ptpaterson | 2:c724ff3a4e4d | 50 | /* Data value type constants ---------------------------------------------- |
ptpaterson | 2:c724ff3a4e4d | 51 | * Taken from the CANOpen Standard. they are part of the object dictionary |
ptpaterson | 2:c724ff3a4e4d | 52 | * at indices 0x0001 to 0x0023. Given to every Sub Index. |
ptpaterson | 2:c724ff3a4e4d | 53 | */ |
ptpaterson | 2:c724ff3a4e4d | 54 | |
ptpaterson | 2:c724ff3a4e4d | 55 | /** Data Type alias to provide context when defining the object library */ |
ptpaterson | 2:c724ff3a4e4d | 56 | typedef uint8_t DataType; |
ptpaterson | 2:c724ff3a4e4d | 57 | |
ptpaterson | 2:c724ff3a4e4d | 58 | static const DataType TYPE_BOOLEAN = 0x01; |
ptpaterson | 2:c724ff3a4e4d | 59 | static const DataType TYPE_INT8 = 0x02; |
ptpaterson | 2:c724ff3a4e4d | 60 | static const DataType TYPE_INT16 = 0x03; |
ptpaterson | 2:c724ff3a4e4d | 61 | static const DataType TYPE_INT32 = 0x04; |
ptpaterson | 2:c724ff3a4e4d | 62 | static const DataType TYPE_UINT8 = 0x05; |
ptpaterson | 2:c724ff3a4e4d | 63 | static const DataType TYPE_UINT16 = 0x06; |
ptpaterson | 2:c724ff3a4e4d | 64 | static const DataType TYPE_UINT32 = 0x07; |
ptpaterson | 2:c724ff3a4e4d | 65 | static const DataType TYPE_REAL32 = 0x08; |
ptpaterson | 2:c724ff3a4e4d | 66 | static const DataType TYPE_VISIBLE_STRING = 0x09; |
ptpaterson | 2:c724ff3a4e4d | 67 | static const DataType TYPE_OCTET_STRING = 0x0A; |
ptpaterson | 2:c724ff3a4e4d | 68 | static const DataType TYPE_UNICODE_STRING = 0x0B; |
ptpaterson | 2:c724ff3a4e4d | 69 | static const DataType TYPE_TIME_OF_DAY = 0x0C; |
ptpaterson | 2:c724ff3a4e4d | 70 | static const DataType TYPE_TIME_DIFFERENCE = 0x0D; |
ptpaterson | 2:c724ff3a4e4d | 71 | /* RESERVED */ |
ptpaterson | 2:c724ff3a4e4d | 72 | static const DataType TYPE_DOMAIN = 0x0F; |
ptpaterson | 2:c724ff3a4e4d | 73 | static const DataType TYPE_INT24 = 0x10; |
ptpaterson | 2:c724ff3a4e4d | 74 | static const DataType TYPE_REAL64 = 0x11; |
ptpaterson | 2:c724ff3a4e4d | 75 | static const DataType TYPE_INT40 = 0x12; |
ptpaterson | 2:c724ff3a4e4d | 76 | static const DataType TYPE_INT48 = 0x13; |
ptpaterson | 2:c724ff3a4e4d | 77 | static const DataType TYPE_INT56 = 0x14; |
ptpaterson | 2:c724ff3a4e4d | 78 | static const DataType TYPE_INT64 = 0x15; |
ptpaterson | 2:c724ff3a4e4d | 79 | static const DataType TYPE_UINT24 = 0x16; |
ptpaterson | 2:c724ff3a4e4d | 80 | /* RESERVED */ |
ptpaterson | 2:c724ff3a4e4d | 81 | static const DataType TYPE_UINT40 = 0x18; |
ptpaterson | 2:c724ff3a4e4d | 82 | static const DataType TYPE_UINT48 = 0x19; |
ptpaterson | 2:c724ff3a4e4d | 83 | static const DataType TYPE_UINT56 = 0x1A; |
ptpaterson | 2:c724ff3a4e4d | 84 | static const DataType TYPE_UINT64 = 0x1B; |
ptpaterson | 2:c724ff3a4e4d | 85 | /* RESERVED */ |
ptpaterson | 2:c724ff3a4e4d | 86 | static const DataType TYPE_PDO_COMMUNICATION_PARAMETER = 0x20; |
ptpaterson | 2:c724ff3a4e4d | 87 | static const DataType TYPE_PDO_MAPPING = 0x21; |
ptpaterson | 2:c724ff3a4e4d | 88 | static const DataType TYPE_SDO_COMMUNICATION_PARAMETER = 0x22; |
ptpaterson | 2:c724ff3a4e4d | 89 | static const DataType TYPE_IDENTITY = 0x23; |
ptpaterson | 2:c724ff3a4e4d | 90 | |
ptpaterson | 2:c724ff3a4e4d | 91 | |
ptpaterson | 2:c724ff3a4e4d | 92 | /* Data properties constants ---------------------------------------------- |
ptpaterson | 2:c724ff3a4e4d | 93 | * Read/Write priveledges, save on powerdown, etc. |
ptpaterson | 2:c724ff3a4e4d | 94 | * Can be strung together into a mask. |
ptpaterson | 2:c724ff3a4e4d | 95 | */ |
ptpaterson | 2:c724ff3a4e4d | 96 | |
ptpaterson | 2:c724ff3a4e4d | 97 | /** Data Property alias to provide context when defining the object library */ |
ptpaterson | 2:c724ff3a4e4d | 98 | typedef uint8_t DataProperty; |
ptpaterson | 2:c724ff3a4e4d | 99 | |
ptpaterson | 2:c724ff3a4e4d | 100 | static const DataProperty PROPERTY_READABLE = 0x01; |
ptpaterson | 2:c724ff3a4e4d | 101 | static const DataProperty PROPERTY_WRITEABLE = 0x02; |
ptpaterson | 2:c724ff3a4e4d | 102 | static const DataProperty PROPERTY_READ_WRITEABLE = 0x03; |
ptpaterson | 2:c724ff3a4e4d | 103 | /* static const uint8_t PROPERTY_STATIC = 0x04 *//* possible to save setting after powerdown */ |
ptpaterson | 2:c724ff3a4e4d | 104 | |
ptpaterson | 2:c724ff3a4e4d | 105 | |
ptpaterson | 2:c724ff3a4e4d | 106 | /* Index Constants -------------------------------------------------------- |
ptpaterson | 2:c724ff3a4e4d | 107 | */ |
ptpaterson | 2:c724ff3a4e4d | 108 | |
ptpaterson | 2:c724ff3a4e4d | 109 | /** Index alias to provide context when defining the object library */ |
ptpaterson | 2:c724ff3a4e4d | 110 | typedef uint8_t Index; |
ptpaterson | 2:c724ff3a4e4d | 111 | |
ptpaterson | 2:c724ff3a4e4d | 112 | |
ptpaterson | 2:c724ff3a4e4d | 113 | /*========================================================================= |
ptpaterson | 2:c724ff3a4e4d | 114 | * Internal structures |
ptpaterson | 2:c724ff3a4e4d | 115 | *========================================================================= |
ptpaterson | 2:c724ff3a4e4d | 116 | */ |
ptpaterson | 2:c724ff3a4e4d | 117 | |
ptpaterson | 2:c724ff3a4e4d | 118 | /** defines the data in a single entry of data (subindex) |
ptpaterson | 2:c724ff3a4e4d | 119 | */ |
ptpaterson | 2:c724ff3a4e4d | 120 | struct EntryData |
ptpaterson | 2:c724ff3a4e4d | 121 | { |
ptpaterson | 2:c724ff3a4e4d | 122 | void *pData; |
ptpaterson | 2:c724ff3a4e4d | 123 | uint16_t size; |
ptpaterson | 2:c724ff3a4e4d | 124 | DataType type; |
ptpaterson | 2:c724ff3a4e4d | 125 | DataProperty properties; |
ptpaterson | 2:c724ff3a4e4d | 126 | |
ptpaterson | 2:c724ff3a4e4d | 127 | EntryData(){} |
ptpaterson | 2:c724ff3a4e4d | 128 | |
ptpaterson | 2:c724ff3a4e4d | 129 | EntryData(void *d, uint16_t s, DataType t, DataProperty p) |
ptpaterson | 2:c724ff3a4e4d | 130 | : pData(d), size(s), type(t), properties(p) |
ptpaterson | 2:c724ff3a4e4d | 131 | {} |
ptpaterson | 2:c724ff3a4e4d | 132 | }; |
ptpaterson | 2:c724ff3a4e4d | 133 | |
ptpaterson | 2:c724ff3a4e4d | 134 | /** defines the data for a single index, including an array of subindices |
ptpaterson | 2:c724ff3a4e4d | 135 | */ |
ptpaterson | 2:c724ff3a4e4d | 136 | struct ObjectData |
ptpaterson | 2:c724ff3a4e4d | 137 | { |
ptpaterson | 2:c724ff3a4e4d | 138 | EntryData *entries; |
ptpaterson | 2:c724ff3a4e4d | 139 | uint16_t index; |
ptpaterson | 2:c724ff3a4e4d | 140 | uint16_t entryCount; |
ptpaterson | 2:c724ff3a4e4d | 141 | |
ptpaterson | 2:c724ff3a4e4d | 142 | ObjectData(){} |
ptpaterson | 2:c724ff3a4e4d | 143 | |
ptpaterson | 2:c724ff3a4e4d | 144 | ObjectData(EntryData *e, uint16_t i, uint16_t c) |
ptpaterson | 2:c724ff3a4e4d | 145 | : entries(e), index(i), entryCount(c) |
ptpaterson | 2:c724ff3a4e4d | 146 | {} |
ptpaterson | 2:c724ff3a4e4d | 147 | }; |
ptpaterson | 2:c724ff3a4e4d | 148 | |
ptpaterson | 2:c724ff3a4e4d | 149 | |
ptpaterson | 2:c724ff3a4e4d | 150 | /*========================================================================= |
ptpaterson | 2:c724ff3a4e4d | 151 | * Public Methods |
ptpaterson | 2:c724ff3a4e4d | 152 | *========================================================================= |
ptpaterson | 2:c724ff3a4e4d | 153 | */ |
ptpaterson | 2:c724ff3a4e4d | 154 | |
ptpaterson | 2:c724ff3a4e4d | 155 | /** Abstract method to give access to the object entries of derived |
ptpaterson | 2:c724ff3a4e4d | 156 | * classes |
ptpaterson | 2:c724ff3a4e4d | 157 | */ |
ptpaterson | 2:c724ff3a4e4d | 158 | virtual ObjectData * ScanIndex(int index) = 0; |
ptpaterson | 2:c724ff3a4e4d | 159 | |
ptpaterson | 2:c724ff3a4e4d | 160 | }; |
ptpaterson | 2:c724ff3a4e4d | 161 | |
ptpaterson | 2:c724ff3a4e4d | 162 | } /* namespace ppCANOpen */ |
ptpaterson | 2:c724ff3a4e4d | 163 | |
ptpaterson | 2:c724ff3a4e4d | 164 | #endif // PPCAN_OBJECT_DICTIONARY_H |