Added generic sync functions

This commit is contained in:
Pascal Serrarens 2024-01-11 14:51:07 +01:00
parent df8bb6a722
commit 89e0bf6f77
2 changed files with 25 additions and 0 deletions

20
NetworkSync.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "NetworkSync.h"
void NetworkSync::SendVector3(unsigned char *data, int startIndex, Vector3 v) {
SendFloat100(data, startIndex, v.x);
SendFloat100(data, startIndex + 4, v.y);
SendFloat100(data, startIndex + 8, v.z);
}
void NetworkSync::SendFloat100(unsigned char *data, int startIndex,
float value) {
// Sends a float with truncated 2 decimal precision
#ifdef ARDUINO_AVR_UNO
long intValue = value * 100;
#else
int intValue = value * 100;
#endif
for (unsigned char ix = 0; ix < 4; ix++) {
data[startIndex + ix] = ((unsigned char *)&intValue)[ix];
}
}

View File

@ -30,6 +30,11 @@ public:
/// @brief A bit pattern for the pose, stating that this message contains an
/// angular velocity in world coordinates
static const char Pose_AngularVelocity = 0x08;
static const char DestroyMsg = 0x20;
void SendVector3(unsigned char *data, int startIndex, Vector3 v);
void SendFloat100(unsigned char *data, int startIndex, float value);
};
} // namespace RoboidControl