Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove derived pointer alignment #301

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
Expand Down
10 changes: 5 additions & 5 deletions common/groundstation/groundstation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
#include <Arduino.h>
#endif

static void OnDataRx(RadioRecievedPacket_s *packet) {
hm_usbTransmit(FIRST_ID_USB_STD, (uint8_t *)packet, sizeof(*packet));
static void OnDataRx(RadioRecievedPacket_s* packet) {
hm_usbTransmit(FIRST_ID_USB_STD, (uint8_t*)packet, sizeof(*packet));
}

static void GroundstationParseCommand(GroundstationUsbCommand_s *command) {
static void GroundstationParseCommand(GroundstationUsbCommand_s* command) {
if (command->data[0] == CHANNEL_COMMAND_ID) {
uint8_t radioHw = command->data[1];
int8_t channel = command->data[2];
Expand Down Expand Up @@ -69,7 +69,7 @@ void Groundstation::runOnce() {
static uint8_t heartbeatArr[sizeof(RadioRecievedPacket_s)] = {0};
memset(heartbeatArr, 0, sizeof(heartbeatArr));
memcpy(heartbeatArr, &heartbeat, sizeof(heartbeat));
hm_usbTransmit(FIRST_ID_USB_STD, (uint8_t *)&heartbeatArr,
hm_usbTransmit(FIRST_ID_USB_STD, (uint8_t*)&heartbeatArr,
sizeof(heartbeatArr));
}

Expand All @@ -78,7 +78,7 @@ void Groundstation::runOnce() {
if (cb_count(buffer) > 3) {
static GroundstationUsbCommand_s command;
size_t count = min(cb_count(buffer), sizeof(command));
cb_peek(buffer, (uint8_t *)&command, &count);
cb_peek(buffer, (uint8_t*)&command, &count);

// If we got at least enough bytes for one message to be done
if (count >= static_cast<uint32_t>(command.len + 3)) {
Expand Down
2 changes: 1 addition & 1 deletion common/groundstation/groundstation.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Groundstation {
void runOnce();

protected:
CircularBuffer_s *buffer{};
CircularBuffer_s* buffer{};

uint32_t start = 0;
};
Expand Down
16 changes: 8 additions & 8 deletions common/system/expressions/binary_func_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include "hardware_manager.h"

BinaryFunctionWrapper::BinaryFunctionWrapper(const char *_stringRep,
BinaryFunction *function,
BinaryFunctionWrapper::BinaryFunctionWrapper(const char* _stringRep,
BinaryFunction* function,
ExpressionValueType_e _op1Type,
ExpressionValueType_e _op2Type,
ExpressionValueType_e _valueType) {
Expand All @@ -21,12 +21,12 @@ BinaryFunctionWrapper::BinaryFunctionWrapper(const char *_stringRep,
this->valueType = _valueType;
}

void BinaryFunctionWrapper::evaluate(Expression *expr, FilterData_s *filterData,
Expression *op1, Expression *op2) {
void BinaryFunctionWrapper::evaluate(Expression* expr, FilterData_s* filterData,
Expression* op1, Expression* op2) {
this->function(expr, filterData, op1, op2);
}

bool BinaryFunctionWrapper::matchesSlice(const StringSlice &slice) {
bool BinaryFunctionWrapper::matchesSlice(const StringSlice& slice) {
return slice == this->stringRep;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ BinaryFunctionWrapper binaryFunctionWrappers[NUM_BINARY_FUNCTION] = {
BinaryFunctionWrapper("/", divFunc, number, number, number)};

int BinaryFuncExpression::toString(
char *buffer, int n, ExpressionPtrCallback &expressionPtrCallback) const {
char* buffer, int n, ExpressionPtrCallback& expressionPtrCallback) const {
int selfLength = strlen(binaryFunctionWrappers[this->opcode].stringRep);
if (n == 0) {
return 0;
Expand Down Expand Up @@ -155,14 +155,14 @@ int BinaryFuncExpression::toString(
}

void BinaryFuncExpression::evaluate(
FilterData_s *filterData, ExpressionPtrCallback &expressionPtrCallback) {
FilterData_s* filterData, ExpressionPtrCallback& expressionPtrCallback) {
binaryFunctionWrappers[this->opcode].evaluate(
this, filterData, expressionPtrCallback(operand1ID),
expressionPtrCallback(operand2ID));
}

void BinaryFuncExpression::serializeInto(
SerializedExpression_s *serialized) const {
SerializedExpression_s* serialized) const {
serialized->triggerNum = this->triggerNum;
serialized->type = binaryFunc;
serialized->contents.binary.opcode = this->opcode;
Expand Down
24 changes: 12 additions & 12 deletions common/system/expressions/binary_func_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ typedef enum {
/**
* Lambda for a binary function.
*/
using BinaryFunction = void(Expression *expr, FilterData_s *filterData,
Expression *op1, Expression *op2);
using BinaryFunction = void(Expression* expr, FilterData_s* filterData,
Expression* op1, Expression* op2);

/**
* A wrapper class for a binary function lambda that makes it easier to use.
Expand All @@ -36,7 +36,7 @@ using BinaryFunction = void(Expression *expr, FilterData_s *filterData,
*/
class BinaryFunctionWrapper {
private:
BinaryFunction *function;
BinaryFunction* function;
ExpressionValueType_e op1Type;
ExpressionValueType_e op2Type;
uint16_t stringLen;
Expand All @@ -45,15 +45,15 @@ class BinaryFunctionWrapper {
char stringRep[10];
ExpressionValueType_e valueType;

BinaryFunctionWrapper(const char *stringRep, BinaryFunction *function,
BinaryFunctionWrapper(const char* stringRep, BinaryFunction* function,
ExpressionValueType_e op1Type,
ExpressionValueType_e op2Type,
ExpressionValueType_e valueType);

void evaluate(Expression *expr, FilterData_s *filterData, Expression *op1,
Expression *op2);
void evaluate(Expression* expr, FilterData_s* filterData, Expression* op1,
Expression* op2);

bool matchesSlice(const StringSlice &slice);
bool matchesSlice(const StringSlice& slice);

bool acceptsArgument1Type(ExpressionValueType_e type);

Expand Down Expand Up @@ -88,13 +88,13 @@ class BinaryFuncExpression : public Expression {
this->setTriggerNum(triggerNum);
}

void evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback);
void evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback);

int toString(char *buffer, int n,
ExpressionPtrCallback &expressionPtrCallback) const;
int toString(char* buffer, int n,
ExpressionPtrCallback& expressionPtrCallback) const;

void serializeInto(SerializedExpression_s *serialized) const;
void serializeInto(SerializedExpression_s* serialized) const;
};

#endif // COMMON_SYSTEM_EXPRESSIONS_BINARY_FUNC_EXPRESSION_H_
8 changes: 4 additions & 4 deletions common/system/expressions/const_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ ConstExpression::ConstExpression(uint16_t _triggerNum, int value) {
this->setTriggerNum(_triggerNum);
}

void ConstExpression::evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback) {
void ConstExpression::evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback) {
return;
}

int ConstExpression::toString(
char *buffer, int n, ExpressionPtrCallback &expressionPtrCallback) const {
char* buffer, int n, ExpressionPtrCallback& expressionPtrCallback) const {
static char floatBuf[10];
dtoa(floatBuf, 10, this->getNumberValue(), 2);
snprintf(buffer, n, "%s", floatBuf);
return strlen(buffer);
}

void ConstExpression::serializeInto(SerializedExpression_s *serialized) const {
void ConstExpression::serializeInto(SerializedExpression_s* serialized) const {
serialized->triggerNum = this->triggerNum;
serialized->type = constant;
serialized->contents.constant = this->getNumberValue();
Expand Down
10 changes: 5 additions & 5 deletions common/system/expressions/const_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class ConstExpression : public Expression {
*/
ConstExpression(uint16_t triggerNum, int value);

void evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback);
void evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback);

int toString(char *buffer, int n,
ExpressionPtrCallback &expressionPtrCallback) const;
int toString(char* buffer, int n,
ExpressionPtrCallback& expressionPtrCallback) const;

void serializeInto(SerializedExpression_s *serialized) const;
void serializeInto(SerializedExpression_s* serialized) const;
};

#endif // COMMON_SYSTEM_EXPRESSIONS_CONST_EXPRESSION_H_
8 changes: 4 additions & 4 deletions common/system/expressions/empty_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ EmptyExpression::EmptyExpression() {
bool EmptyExpression::isEmpty() const { return true; }

// Does nothing
void EmptyExpression::evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback) {
void EmptyExpression::evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback) {
return;
}

int EmptyExpression::toString(
char *buffer, int n, ExpressionPtrCallback &expressionPtrCallback) const {
char* buffer, int n, ExpressionPtrCallback& expressionPtrCallback) const {
strncpy(buffer, "empty", n);
return 5;
}

void EmptyExpression::serializeInto(SerializedExpression_s *serialized) const {
void EmptyExpression::serializeInto(SerializedExpression_s* serialized) const {
serialized->triggerNum = this->triggerNum;
serialized->type = empty;
}
10 changes: 5 additions & 5 deletions common/system/expressions/empty_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class EmptyExpression : public Expression {
bool isEmpty() const;

// Does nothing
void evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback);
void evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback);

int toString(char *buffer, int n,
ExpressionPtrCallback &expressionPtrCallback) const;
int toString(char* buffer, int n,
ExpressionPtrCallback& expressionPtrCallback) const;

void serializeInto(SerializedExpression_s *serialized) const;
void serializeInto(SerializedExpression_s* serialized) const;
};

#endif // COMMON_SYSTEM_EXPRESSIONS_EMPTY_EXPRESSION_H_
10 changes: 5 additions & 5 deletions common/system/expressions/event_expression.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include "event_expression.h"

const char *eventStrings[] = {"launch", "burnout", "apogee", "touchdown",
const char* eventStrings[] = {"launch", "burnout", "apogee", "touchdown",
"unclean_restart"};

EventExpression::EventExpression(uint16_t triggerNum, Event_e event) {
this->setTriggerNum(triggerNum);
this->event = event;
}

void EventExpression::evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback) {
void EventExpression::evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback) {
this->setBooleanValue(eventManager_getEventStatus(this->event));
}

int EventExpression::toString(
char *buffer, int n, ExpressionPtrCallback &expressionPtrCallback) const {
char* buffer, int n, ExpressionPtrCallback& expressionPtrCallback) const {
snprintf(buffer, n, eventStrings[this->event]);
return strlen(buffer);
}

void EventExpression::serializeInto(SerializedExpression_s *serialized) const {
void EventExpression::serializeInto(SerializedExpression_s* serialized) const {
serialized->triggerNum = this->triggerNum;
serialized->type = ExpressionType_e::event;
serialized->contents.event = this->event;
Expand Down
12 changes: 6 additions & 6 deletions common/system/expressions/event_expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include "event_manager.h"
#include "expression.h"
extern const char *eventStrings[];
extern const char* eventStrings[];

/**
* An event expression is an expression that evaluates directly to the status of
Expand All @@ -26,13 +26,13 @@ class EventExpression : public Expression {
*/
EventExpression(uint16_t triggerNum, Event_e event);

void evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback);
void evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback);

int toString(char *buffer, int n,
ExpressionPtrCallback &expressionPtrCallback) const;
int toString(char* buffer, int n,
ExpressionPtrCallback& expressionPtrCallback) const;

void serializeInto(SerializedExpression_s *serialized) const;
void serializeInto(SerializedExpression_s* serialized) const;
};

#endif // COMMON_SYSTEM_EXPRESSIONS_EVENT_EXPRESSION_H_
12 changes: 6 additions & 6 deletions common/system/expressions/expression.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Expression {
* ExpressionStore to fetch from.
* @return Pointer to that expression as the base class Expression.
*/
using ExpressionPtrCallback = std::function<Expression *(uint16_t)>;
using ExpressionPtrCallback = std::function<Expression*(uint16_t)>;
uint32_t firstTrue;
uint32_t trueSince;
uint16_t triggerNum;
Expand All @@ -54,8 +54,8 @@ class Expression {
* @param expressionPtrCallback ExpressionPtrCallback to get a pointer to a
* given child expression.
*/
virtual void evaluate(FilterData_s *filterData,
ExpressionPtrCallback &expressionPtrCallback) = 0;
virtual void evaluate(FilterData_s* filterData,
ExpressionPtrCallback& expressionPtrCallback) = 0;

/**
* If this is an empty expression.
Expand Down Expand Up @@ -105,14 +105,14 @@ class Expression {
* given child expression.
* @return Number of characters used by this expression in the buffer.
*/
virtual int toString(char *buffer, int n,
ExpressionPtrCallback &expressionPtrCallback) const = 0;
virtual int toString(char* buffer, int n,
ExpressionPtrCallback& expressionPtrCallback) const = 0;

/**
* Serialize this expression into a location.
* @param serialized Struct to serialize into.
*/
virtual void serializeInto(SerializedExpression_s *serialized) const = 0;
virtual void serializeInto(SerializedExpression_s* serialized) const = 0;
};

#endif // COMMON_SYSTEM_EXPRESSIONS_EXPRESSION_H_
Loading
Loading