diff --git a/NetworkSync.cpp b/NetworkSync.cpp new file mode 100644 index 0000000..f1e962f --- /dev/null +++ b/NetworkSync.cpp @@ -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]; + } +} \ No newline at end of file diff --git a/NetworkSync.h b/NetworkSync.h index b3c4012..dcffaad 100644 --- a/NetworkSync.h +++ b/NetworkSync.h @@ -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