-
Notifications
You must be signed in to change notification settings - Fork 2
/
nmt_messages.hpp
50 lines (35 loc) · 1.03 KB
/
nmt_messages.hpp
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
#pragma once
#include "mbed.h"
#include <stdint.h>
namespace nmt_messages {
/* NMT objects
Function code + NODE_ID = 0x000
Identifier 0, 2 bytes
| 0 | 1 | Byte#
| CS | Node-ID | Name
| --- | --- |
| 0x80 | 0 (all) | All CANOpen will enter Pre-Operational
| 0x82 | 0 | Reset Communication
| 0x81 | 0 | Reset Node
| 0x01 | 0 | Start - Enter Operational
| 0x02 | 0 | Stop - Enter Stopped
*Node-ID - 0 for all, n for ID
*/
enum transition : uint8_t {
PreOperational = 0x80,
ResetCommunication = 0x82,
ResetNode = 0x83,
Operational = 0x01,
Stopped = 0x02,
};
inline CANMessage construct (transition t) {
const uint8_t nmt_Template[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
CANMessage msg;
msg.format = CANStandard; // Standard format - 11bits
msg.id = 0x000;
memcpy(msg.data, &nmt_Template, 8);
memcpy(msg.data, &t, 1);
msg.len = 8;
return msg;
}
}