diff --git a/groundStation/src/backend/bitwise.h b/groundStation/src/backend/bitwise.h index 9d630707e95f7b6e15fba74d188c18119b7bc489..fec707046ee9a16bccebf479c0ac289269c5ff3d 100644 --- a/groundStation/src/backend/bitwise.h +++ b/groundStation/src/backend/bitwise.h @@ -2,28 +2,28 @@ #define _bitwise_h /* Bit shifting for endianness of 16-bit numbers */ -#define LSByte16(x) (x & 0xff) -#define MSByte16(x) ((x >> 8) & 0xff) +#define LSByte16(x) ((x) & 0xff) +#define MSByte16(x) (((x) >> 8) & 0xff) /* Build a 16-bit integer out of two bytes */ -#define BytesTo16(lsb, msb) ((lsb & 0xff) | ((msb << 8) & 0xff)) +#define BytesTo16(lsb, msb) (((lsb) & 0xff) | (((msb) << 8) & 0xff)) /* Break apart a float. Sadly this is UB, but the "correct" way * to do this involves actually implementing * IEEE 754 in software to do so */ -#define FloatByte1(x) (((char *) x)[0]) -#define FloatByte2(x) (((char *) x)[1]) -#define FloatByte3(x) (((char *) x)[2]) -#define FloatByte4(x) (((char *) x)[3]) +#define FloatByte1(x) (((char *) &(x))[0]) +#define FloatByte2(x) (((char *) &(x))[1]) +#define FloatByte3(x) (((char *) &(x))[2]) +#define FloatByte4(x) (((char *) &(x))[3]) /* This is so much UB it hurts to write */ #define BytesToFloat(f, b1, b2, b3, b4) \ do { \ - ((char *) f)[0] = b1; \ - ((char *) f)[1] = b2; \ - ((char *) f)[2] = b3; \ - ((char *) f)[3] = b4; \ + ((char *) &(f))[0] = (b1); \ + ((char *) &(f))[1] = (b2); \ + ((char *) &(f))[2] = (b3); \ + ((char *) &(f))[3] = (b4); \ } while (0); #endif diff --git a/groundStation/src/backend/common/common.txt b/groundStation/src/backend/common/common.txt new file mode 100644 index 0000000000000000000000000000000000000000..cfc7835508714bcbc03e48f3af52c4b69e172a2a --- /dev/null +++ b/groundStation/src/backend/common/common.txt @@ -0,0 +1,7 @@ +The common files are: + - packet.h + - packet.c + - setcontrol.h + - setcontrol.c + - bitwise.h + - controller.h diff --git a/groundStation/src/backend/common_examples.txt b/groundStation/src/backend/common/examples.c similarity index 100% rename from groundStation/src/backend/common_examples.txt rename to groundStation/src/backend/common/examples.c diff --git a/groundStation/src/backend/controller.h b/groundStation/src/backend/controller.h index 8c88147c29fe01613b65bd053a5ae351e2cd7301..50de090ccfa7639275ce33d39ad1fc28088d027c 100644 --- a/groundStation/src/backend/controller.h +++ b/groundStation/src/backend/controller.h @@ -1,6 +1,10 @@ #ifndef _controller_h #define _controller_h + +/* For now, the enums come from commands.h */ +#include "commands.h" +#if 0 enum ControllerID { ROLL_ID, // 00 - Roll PID PITCH_ID, // 01 - Pitch PID @@ -19,6 +23,7 @@ enum ControllerValueID{ KD_ID, // 02 - D constant SP_ID, // 03 - Setpoint value }; +#endif struct controller_message { enum ControllerID id; diff --git a/groundStation/src/backend/packet.c b/groundStation/src/backend/packet.c index 3d3c78cd3677eed25c8c30dedde2c2cd8d19122a..50432eab7c8fa5ddb65457291b1bebb35a07d9f9 100644 --- a/groundStation/src/backend/packet.c +++ b/groundStation/src/backend/packet.c @@ -84,7 +84,12 @@ ssize_t DecodePacket( memcpy(data, &packet[HDR_SIZE], m->data_len); /* Validate checksum */ - // TODO - // + /* TODO */ return m->data_len; } + +uint8_t PacketChecksum(const uint8_t * packet, size_t packet_size) +{ + /* TODO implement */ + return 42; +} diff --git a/groundStation/src/backend/setcontrol.c b/groundStation/src/backend/setcontrol.c index 0cbe22d570bb3580c4d6ab78fff564bf15f16d04..536c69001e131e2af5bdfc7009c337e080c0ee9c 100644 --- a/groundStation/src/backend/setcontrol.c +++ b/groundStation/src/backend/setcontrol.c @@ -1,5 +1,6 @@ #include "setcontrol.h" -#include "../commands.h" +#include "commands.h" +#include "bitwise.h" #include <sys/types.h>