fixed layout assertions and added namespaces

This commit is contained in:
2021-06-28 10:23:39 +02:00
parent 28052f8625
commit 7f90b2b882
3 changed files with 40 additions and 22 deletions

View File

@ -3,7 +3,9 @@
#include <cstdint>
namespace bobbycar {
namespace protocol {
namespace can {
template<bool isBack, bool isRight>
class MotorController
{
@ -196,5 +198,7 @@ inline const char *bobbycarCanIdDesc(uint16_t id)
}
return "Unknown";
}
}
}
} // namespace can
} // namespace protocol
} // namespace bobbycar

View File

@ -2,6 +2,9 @@
#include <stdint.h>
namespace bobbycar {
namespace protocol {
enum class ControlType : uint8_t {
Commutation,
Sinusoidal,
@ -14,3 +17,6 @@ enum class ControlMode : uint8_t {
Speed, // Only with FieldOrientedControl
Torque // Only with FieldOrientedControl
};
} // namespace protocol
} // namespace bobbycar

View File

@ -4,6 +4,10 @@
#include "bobbycar-common.h"
namespace bobbycar {
namespace protocol {
namespace serial {
struct MotorState {
bool enable = false;
int16_t pwm = 0;
@ -111,8 +115,8 @@ inline uint16_t calculateChecksum(Feedback feedback) {
}
#define ASSERT_LAYOUT(st, memb, off) //\
//static_assert(offsetof(st, memb) == off, "struct layout wrong");
#define ASSERT_LAYOUT(st, memb, off) \
static_assert(offsetof(st, memb) == off, "struct layout wrong");
ASSERT_LAYOUT(Feedback, start, 0);
ASSERT_LAYOUT(Feedback, left, 2);
@ -125,26 +129,26 @@ ASSERT_LAYOUT(Feedback, left.dcPhaB, 12);
ASSERT_LAYOUT(Feedback, left.dcPhaC, 14);
ASSERT_LAYOUT(Feedback, left.chops, 16);
ASSERT_LAYOUT(Feedback, left.hallA, 18);
ASSERT_LAYOUT(Feedback, left.hallB, 20);
ASSERT_LAYOUT(Feedback, left.hallC, 22);
ASSERT_LAYOUT(Feedback, left.hallB, 19);
ASSERT_LAYOUT(Feedback, left.hallC, 20);
ASSERT_LAYOUT(Feedback, right, 24);
ASSERT_LAYOUT(Feedback, right.angle, 26);
ASSERT_LAYOUT(Feedback, right.speed, 28);
ASSERT_LAYOUT(Feedback, right.error, 30);
ASSERT_LAYOUT(Feedback, right.dcLink, 32);
ASSERT_LAYOUT(Feedback, right.dcPhaA, 34);
ASSERT_LAYOUT(Feedback, right.dcPhaB, 36);
ASSERT_LAYOUT(Feedback, right.dcPhaC, 38);
ASSERT_LAYOUT(Feedback, right.chops, 40);
ASSERT_LAYOUT(Feedback, right.hallA, 42);
ASSERT_LAYOUT(Feedback, right.hallB, 44);
ASSERT_LAYOUT(Feedback, right.hallC, 48);
ASSERT_LAYOUT(Feedback, right, 22);
ASSERT_LAYOUT(Feedback, right.angle, 22);
ASSERT_LAYOUT(Feedback, right.speed, 24);
ASSERT_LAYOUT(Feedback, right.error, 26);
ASSERT_LAYOUT(Feedback, right.dcLink, 28);
ASSERT_LAYOUT(Feedback, right.dcPhaA, 30);
ASSERT_LAYOUT(Feedback, right.dcPhaB, 32);
ASSERT_LAYOUT(Feedback, right.dcPhaC, 34);
ASSERT_LAYOUT(Feedback, right.chops, 36);
ASSERT_LAYOUT(Feedback, right.hallA, 38);
ASSERT_LAYOUT(Feedback, right.hallB, 39);
ASSERT_LAYOUT(Feedback, right.hallC, 40);
ASSERT_LAYOUT(Feedback, batVoltage, 30);
ASSERT_LAYOUT(Feedback, boardTemp, 32);
ASSERT_LAYOUT(Feedback, timeoutCntSerial, 34);
ASSERT_LAYOUT(Feedback, checksum, 36);
ASSERT_LAYOUT(Feedback, batVoltage, 42);
ASSERT_LAYOUT(Feedback, boardTemp, 44);
ASSERT_LAYOUT(Feedback, timeoutCntSerial, 46);
ASSERT_LAYOUT(Feedback, checksum, 48);
static_assert(sizeof(Command) == 32, "sizeof(Command) wrong");
@ -178,3 +182,7 @@ ASSERT_LAYOUT(Command, buzzer.pattern, 27);
ASSERT_LAYOUT(Command, poweroff, 28);
ASSERT_LAYOUT(Command, led, 29);
ASSERT_LAYOUT(Command, checksum, 30);
} // namespace serial
} // namespace protocol
} // namespace bobbycar