-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSDOCanNode.hpp
More file actions
141 lines (123 loc) · 3.91 KB
/
Copy pathSDOCanNode.hpp
File metadata and controls
141 lines (123 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <cstdint>
#include <core/utils/log.hpp>
#include <co_core.h>
#include <co_csdo.h>
#include <core/io/CANDevice.hpp>
#include <core/io/CANOpenMacros.hpp>
#include <core/io/CANOpen.hpp>
/**
* Representation of the CAN node. Handles constructing the object
* dictionary and other baseline settings. The idea is that each "board"
* will have a specific object dictionary associated with it. The object
* dictionary itself will also need to have information on "data of interest".
* For example, a temperature management system may to expose water pump
* flow rate in the object dictionary.
*/
namespace log = core::log;
class SDOCanNode : public CANDevice {
public:
SDOCanNode();
/**
* Update Object Dictionary entry
*
* @param node[in] The canopen node to write to
*/
void SDO_Transfer(CO_NODE &node);
/**
* Read Object Dictionary entry
*
* @param node[in] The canopen node to read from
*/
void SDO_Receive(CO_NODE &node);
/**
* Get the contained sample data
*
* @return The value of the sample data
*/
uint8_t getSampleDataA();
uint16_t getSampleDataB();
/**
* increments counters up
*/
void update();
/**
* Get a pointer to the start of the object dictionary
*
* @return Pointer to the start of the object dictionary
*/
CO_OBJ_T* getObjectDictionary() override;
/**
* Get the number of elements in the object dictionary.
*
* @return The number of elements in the object dictionary
*/
uint8_t getNumElements() override;
/**
* Get the device's node ID
*
* @return The node ID of the can device.
*/
uint8_t getNodeID() override;
/**
* Get the device's node ID
*
* @return The node ID of the can device.
*/
static constexpr uint8_t NODE_ID = 2;
private:
/**
* This sample data will be exposed over CAN through the object
* dictionary. The address of the variable will be included in the
* object dictionary and can be updated via SDO via a CANopen client.
* This device will then broadcast the value via a triggered PDO.
*/
uint8_t sampleDataA;
uint16_t sampleDataB;
uint8_t sampleDataArray[2] = {0, 0};
/**
* Have to know the size of the object dictionary for initialization
* process.
*/
static constexpr uint8_t OBJECT_DICTIONARY_SIZE = 24;
/**
* The object dictionary itself. Will be populated by this object during
* construction.
*
* The plus one is for the special "end of dictionary" marker.
*/
CO_OBJ_T objectDictionary[OBJECT_DICTIONARY_SIZE + 1] = {
MANDATORY_IDENTIFICATION_ENTRIES_1000_1014,
HEARTBEAT_PRODUCER_1017(2000),
IDENTITY_OBJECT_1018,
SDO_CONFIGURATION_1200,
{
/* Communication Object SDO Server */
.Key = CO_KEY(0x1280, 0x00, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED32,
.Data = (CO_DATA) 0x03,
},
{
/* SDO Server Request COBID */
.Key = CO_KEY(0x1280, 0x01, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED32,
.Data = (CO_DATA) CO_COBID_SDO_REQUEST(),
},
{ /* SDO Server Response COBID */
.Key = CO_KEY(0x1280, 0x02, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED32,
.Data = (CO_DATA) CO_COBID_SDO_RESPONSE(),
},
{
.Key = CO_KEY(0x1280, 0x03, CO_OBJ_D___R_),
.Type = CO_TUNSIGNED8,
.Data = (CO_DATA) 1,
},
// User defined data, this will be where we put elements that can be
// accessed via SDO and depending on configuration PDO
DATA_LINK_START_KEY_21XX(0, 0x02),
DATA_LINK_21XX(0x00, 0x01, CO_TUNSIGNED8, &sampleDataA),
DATA_LINK_21XX(0x00, 0x02, CO_TUNSIGNED16, &sampleDataB),
// End of dictionary marker
CO_OBJ_DICT_ENDMARK,
};
};