CANopen library
Fork of CANopen_Node by
CANopen.cpp@1:a5e0bd1f1c93, 2016-05-30 (annotated)
- Committer:
- kkoichy
- Date:
- Mon May 30 11:38:02 2016 +0000
- Revision:
- 1:a5e0bd1f1c93
- Parent:
- 0:0f99b1d63054
V1.1; Changed some code in the Initiate SDO Upload Command
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kkoichy | 0:0f99b1d63054 | 1 | #include "CANopen.h" |
kkoichy | 0:0f99b1d63054 | 2 | |
kkoichy | 0:0f99b1d63054 | 3 | |
kkoichy | 0:0f99b1d63054 | 4 | namespace mbed { |
kkoichy | 0:0f99b1d63054 | 5 | |
kkoichy | 0:0f99b1d63054 | 6 | CANopen::CANopen(short _id, CAN * _can) |
kkoichy | 0:0f99b1d63054 | 7 | { |
kkoichy | 0:0f99b1d63054 | 8 | can = _can; |
kkoichy | 0:0f99b1d63054 | 9 | node_id = _id; |
kkoichy | 0:0f99b1d63054 | 10 | |
kkoichy | 0:0f99b1d63054 | 11 | } |
kkoichy | 0:0f99b1d63054 | 12 | CANopen::CANopen(short _id, CAN * _can, int _baud) |
kkoichy | 0:0f99b1d63054 | 13 | { |
kkoichy | 0:0f99b1d63054 | 14 | can = _can; |
kkoichy | 0:0f99b1d63054 | 15 | node_id = _id; |
kkoichy | 0:0f99b1d63054 | 16 | can->frequency(_baud); |
kkoichy | 0:0f99b1d63054 | 17 | |
kkoichy | 0:0f99b1d63054 | 18 | } |
kkoichy | 0:0f99b1d63054 | 19 | int CANopen::Send_Initiate_SDO_Download(short index, short subindex, long data) |
kkoichy | 0:0f99b1d63054 | 20 | { |
kkoichy | 0:0f99b1d63054 | 21 | char _data[8]; |
kkoichy | 0:0f99b1d63054 | 22 | _data[0] = 0x22; |
kkoichy | 0:0f99b1d63054 | 23 | _data[1] = index; |
kkoichy | 0:0f99b1d63054 | 24 | _data[2] = index >> 8; |
kkoichy | 0:0f99b1d63054 | 25 | _data[3] = subindex; |
kkoichy | 0:0f99b1d63054 | 26 | _data[4] = data >> 0; |
kkoichy | 0:0f99b1d63054 | 27 | _data[5] = data >> 8; |
kkoichy | 0:0f99b1d63054 | 28 | _data[6] = data >> 16; |
kkoichy | 0:0f99b1d63054 | 29 | _data[7] = data >> 24; |
kkoichy | 0:0f99b1d63054 | 30 | return can->write(CANMessage(0x600 + node_id, _data, 8)); |
kkoichy | 0:0f99b1d63054 | 31 | |
kkoichy | 0:0f99b1d63054 | 32 | } |
kkoichy | 0:0f99b1d63054 | 33 | int32_t CANopen::Send_Initiate_SDO_Upload(short index, short subindex) |
kkoichy | 0:0f99b1d63054 | 34 | { |
kkoichy | 0:0f99b1d63054 | 35 | char _data[8]; |
kkoichy | 0:0f99b1d63054 | 36 | _data[0] = 0x60; |
kkoichy | 0:0f99b1d63054 | 37 | _data[1] = index; |
kkoichy | 0:0f99b1d63054 | 38 | _data[2] = index >> 8; |
kkoichy | 0:0f99b1d63054 | 39 | _data[3] = subindex; |
kkoichy | 0:0f99b1d63054 | 40 | _data[4] = 0; |
kkoichy | 0:0f99b1d63054 | 41 | _data[5] = 0; |
kkoichy | 0:0f99b1d63054 | 42 | _data[6] = 0; |
kkoichy | 0:0f99b1d63054 | 43 | _data[7] = 0; |
kkoichy | 1:a5e0bd1f1c93 | 44 | CANMessage _message(0x600 + node_id, _data, 8); |
kkoichy | 0:0f99b1d63054 | 45 | can->write(_message); |
kkoichy | 1:a5e0bd1f1c93 | 46 | can->read(_message); |
kkoichy | 0:0f99b1d63054 | 47 | return (_message.data[4] | _message.data[5] << 8 | _message.data[6] << 16 | _message.data[7] << 24); |
kkoichy | 0:0f99b1d63054 | 48 | |
kkoichy | 0:0f99b1d63054 | 49 | } |
kkoichy | 0:0f99b1d63054 | 50 | short CANopen::GetNodeID(void) |
kkoichy | 0:0f99b1d63054 | 51 | { |
kkoichy | 0:0f99b1d63054 | 52 | return node_id; |
kkoichy | 0:0f99b1d63054 | 53 | |
kkoichy | 0:0f99b1d63054 | 54 | } |
kkoichy | 0:0f99b1d63054 | 55 | void CANopen::SetNodeID(short _id) |
kkoichy | 0:0f99b1d63054 | 56 | { |
kkoichy | 0:0f99b1d63054 | 57 | node_id = _id; |
kkoichy | 0:0f99b1d63054 | 58 | |
kkoichy | 0:0f99b1d63054 | 59 | } |
kkoichy | 0:0f99b1d63054 | 60 | |
kkoichy | 0:0f99b1d63054 | 61 | |
kkoichy | 0:0f99b1d63054 | 62 | |
kkoichy | 0:0f99b1d63054 | 63 | |
kkoichy | 0:0f99b1d63054 | 64 | }//end namespace |