Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: msg.cpp
- Revision:
- 0:544925185af9
- Child:
- 1:605fa4405e4f
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/msg.cpp Thu Jan 24 16:27:29 2019 +0000
@@ -0,0 +1,25 @@
+#include "msg.h"
+
+#define UINT8_MAX 255;
+
+void Msg::construct_data_msg(uint8_t sensor_id, int data, uint8_t *buffer, int buffer_len) {
+ if (buffer_len < 5)
+ return;
+
+ buffer[0] = sensor_id;
+ for (int i = 4; i > 0; i--) {
+ buffer[i] = data % UINT8_MAX;
+ data /= UINT8_MAX;
+ }
+}
+
+void Msg::deconstruct_data_msg(uint8_t *sensor_id, int *data, uint8_t *buffer, int buffer_len) {
+ if (buffer_len < 5)
+ return;
+
+ *sensor_id = buffer[0];
+ *data = 0;
+ for (int i = 1; i < 5; i++) {
+ *data = *data * UINT8_MAX + buffer[i];
+ }
+}