-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCANPower.c
50 lines (46 loc) · 1.83 KB
/
CANPower.c
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
/* File: CANPower.c
* Authors: Jaden Bottemiller, Benton Kwong, Dylan Tomberlin.
* Organization: Husky Robotics Team
*
* This file includes fuction implementations for the power boards CAN Communication
* using the Hindsight CAN Communication standard.
* Documentation: https://huskyroboticsteam.slite.com/app/channels/iU0BryG7M9/collections/aXvWTcIR6c/notes/4otlSFsSp2
*/
#include "CANPower.h"
#include "CANPacket.h"
//Power Rail Set State
void AssemblePowerRailsSetPacket(CANPacket *packetToAssemble,
uint8_t targetDeviceGroup,
uint8_t targetDeviceSerialNumber,
uint8_t state)
{
packetToAssemble->id = ConstructCANID(PACKET_PRIORITY_NORMAL, targetDeviceGroup, targetDeviceSerialNumber);
packetToAssemble->dlc = DLC_POWER_RAIL_SET;
int nextByte = WriteSenderSerialAndPacketID(packetToAssemble->data, ID_POWER_RAIL_SET);
packetToAssemble->data[nextByte] = state;
}
uint8_t GetPowerRailsStateFromPacket(CANPacket *packet)
{
return packet->data[2];
}
//Power Set Over Current Limit
void AssembleOverCurrentPacket(CANPacket *packetToAssemble,
uint8_t targetDeviceGroup,
uint8_t targetDeviceSerialNumber,
uint8_t railNumber,
uint32_t currentLim)
{
packetToAssemble->id = ConstructCANID(PRIO_POWER_CURRENT_LIM_SET, targetDeviceGroup, targetDeviceSerialNumber);
packetToAssemble->dlc = DLC_POWER_CURRENT_LIM_SET;
int nextByte = WriteSenderSerialAndPacketID(packetToAssemble->data, ID_POWER_CURRENT_LIM_SET);
packetToAssemble->data[nextByte] = railNumber;
PackIntIntoDataMSBFirst(packetToAssemble->data, currentLim, nextByte + 1);
}
uint8_t GetOverCurrentRailNumFromPacket(CANPacket *packetToAssemble)
{
return packetToAssemble->data[2];
}
uint8_t GetOverCurrentLimitFromPacket(CANPacket *packetToAssemble)
{
return DecodeBytesToIntMSBFirst(packetToAssemble->data, 3, 6);
}