58 lines
924 B
C++
58 lines
924 B
C++
#include "mbed.h"
|
|
|
|
#pragma once
|
|
|
|
|
|
namespace serialization {
|
|
|
|
//! Receive commands from the Touch OSC layout through a NodeMCU
|
|
class RCProtocol
|
|
{
|
|
|
|
public:
|
|
|
|
struct Packet {
|
|
|
|
int16_t Throttle;
|
|
int16_t Steering;
|
|
|
|
int16_t Kp;
|
|
int16_t Ki;
|
|
int16_t Kd;
|
|
|
|
bool Enabled;
|
|
|
|
uint8_t Checksum;
|
|
|
|
Packet()
|
|
: Throttle(0.0f)
|
|
, Steering(0.0f)
|
|
, Kp(0.0f)
|
|
, Ki(0.0f)
|
|
, Kd(0.0f)
|
|
, Enabled(false)
|
|
{
|
|
}
|
|
|
|
} __attribute__ ((__packed__));
|
|
|
|
RCProtocol();
|
|
|
|
//! Read the latest package
|
|
RCProtocol::Packet read();
|
|
|
|
//! Append a byte until we have a package to read.
|
|
//! Returns true when a hole package is available
|
|
bool appendByte(uint8_t newByte);
|
|
|
|
//Semaphore m_semaphore;
|
|
|
|
const static uint32_t MAGIC_WORD = 0xDEC0DED;
|
|
|
|
private:
|
|
|
|
RCProtocol::Packet m_packet;
|
|
|
|
};
|
|
|
|
} |