Added generic sync functions
This commit is contained in:
parent
df8bb6a722
commit
89e0bf6f77
20
NetworkSync.cpp
Normal file
20
NetworkSync.cpp
Normal 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];
|
||||
}
|
||||
}
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user