Skip to content
Snippets Groups Projects
Unverified Commit 5683f8ac authored by Jake Drahos's avatar Jake Drahos
Browse files

Implemented setcontrol and packet

parent 7ee85352
No related branches found
No related tags found
No related merge requests found
......@@ -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
The common files are:
- packet.h
- packet.c
- setcontrol.h
- setcontrol.c
- bitwise.h
- controller.h
#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;
......
......@@ -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;
}
#include "setcontrol.h"
#include "../commands.h"
#include "commands.h"
#include "bitwise.h"
#include <sys/types.h>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment