This repository has been archived by the owner on Dec 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CanOpenPdo.cpp
65 lines (55 loc) · 1.95 KB
/
CanOpenPdo.cpp
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
// Copyright (c) 2018 Formula Slug. All Rights Reserved.
#include "CanOpenPdo.h"
#include <cstring>
// TODO: Make COB-ID naming match CANOpen convention
HeartbeatMessage::HeartbeatMessage(uint16_t data) {
IDE = CAN_IDE_EXT;
EID = kSysIdFs | kNodeIdPrimary | kFuncIdHeartbeat;
RTR = CAN_RTR_DATA;
DLC = 2;
data8[0] = (data >> 8) & 0xFF; // MSB (32's 3rd byte)
data8[1] = data & 0xFF; // LSB (32's 4th byte)
}
// ThrottleMessage::ThrottleMessage(uint16_t throttleVoltage, bool
// forwardSwitch) {
// IDE = CAN_IDE_EXT;
// EID = kCobIdTPDO5;
// RTR = CAN_RTR_DATA;
// DLC = 8;
//
// TPDO5 tpdo5;
// tpdo5.throttleInputVoltage = throttleVoltage;
// tpdo5.maxBatteryDischargeCurrent = 400;
// tpdo5.maxBatteryRechargeCurrent = 400;
// tpdo5.forwardSwitch = forwardSwitch;
// tpdo5.driveSelect1Switch = false;
// tpdo5.driveSelect2Switch = false;
// tpdo5.reverseSwitch = false;
//
// std::memcpy(data8, &tpdo5, sizeof(TPDO5));
// }
ThrottleMessage::ThrottleMessage(uint16_t throttleVoltage) {
IDE = CAN_IDE_EXT;
// EID = kSysIdFs | kNodeIdPrimary | kFuncIdThrottleValue; //kCobIdTPDO5;
EID = 0x908; // kCobIdTPDO5; // used to be 204
RTR = CAN_RTR_DATA;
DLC = 2;
// data8[0] = 0xFF; // MSB (32's 3rd byte) (left most byte in DVT)
// data8[1] = (throttleVoltage >> 8) & 0xFF; // LSB (32's 4th byte) (right
// most byte in DVT)
data8[0] =
throttleVoltage & 0xFF; // MSB (32's 3rd byte) (left most byte in DVT)
data8[1] = (throttleVoltage >> 8) &
0xFF; // LSB (32's 4th byte) (right most byte in DVT)
// data8[2] = 0xFF;
// data8[3] = 0xFF;
// TPDO5 tpdo5;
// tpdo5.throttleInputVoltage = throttleVoltage;
// tpdo5.maxBatteryDischargeCurrent = 400;
// tpdo5.maxBatteryRechargeCurrent = 400;
// tpdo5.forwardSwitch = forwardSwitch;
// tpdo5.driveSelect1Switch = false;
// tpdo5.driveSelect2Switch = false;
// tpdo5.reverseSwitch = false;
// std::memcpy(data8, &tpdo5, sizeof(TPDO5));
}