Skip to content
Snippets Groups Projects
Commit ecc9a494 authored by Matteo Pignataro's avatar Matteo Pignataro
Browse files

[CanProtocolTypes] Added voltage sensor

parent 5ef06f85
Branches
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@
#include <actuators/Servo/ServoData.h>
#include <sensors/SensorData.h>
#include <sensors/analog/BatteryVoltageSensorData.h>
#include <sensors/analog/Pitot/PitotData.h>
#include <cstring>
......@@ -111,6 +112,21 @@ inline Canbus::CanMessage toCanMessage(const ServoData& data)
return message;
}
inline Canbus::CanMessage toCanMessage(const BatteryVoltageSensorData& data)
{
Canbus::CanMessage message;
uint32_t voltage;
memcpy(&voltage, &(data.batVoltage), sizeof(voltage));
message.id = -1;
message.length = 1;
message.payload[0] = (data.voltageTimestamp & ~0x3) << 30;
message.payload[0] |= voltage;
return message;
}
inline PitotData pitotDataFromCanMessage(const Canbus::CanMessage& msg)
{
PitotData data;
......@@ -174,4 +190,17 @@ inline ServoData servoDataFromCanMessage(const Canbus::CanMessage& msg)
return data;
}
inline BatteryVoltageSensorData voltageDataFromCanMessage(
const Canbus::CanMessage& msg)
{
BatteryVoltageSensorData data;
uint32_t voltage = msg.payload[0];
memcpy(&(data.batVoltage), &voltage, sizeof(data.batVoltage));
data.voltageTimestamp = (msg.payload[0] >> 30) & ~0x3;
return data;
}
} // namespace Boardcore
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment