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

Change std:vectors to etl::vectors #38

Open
wants to merge 4 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 catch_tests/ecs/StandECSTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ TEST_CASE("Stand ECS on redlines/watchdog", "[unit]"){
ECSState state{"state", {}, command, command};
StandECS ecs{comm, phys, watchdog, sequencer, state};

std::vector<std::unique_ptr<IRedline>> redlines{};
etl::vector<std::unique_ptr<IRedline>, 45> redlines{};
redlines.emplace_back(std::make_unique<FakeRedline>("redline", ECSRedLineResponse::ABORT));

watchdog.updateRedlines(std::move(redlines));
Expand Down
22 changes: 22 additions & 0 deletions catch_tests/logger/LoggerTests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Created by Alex Poulin on 10/2/2023
//
// To test capabilities of the Logger function

#include "../catch.hpp"
#include "logger/Logger.h"

//TODO test file is created
//TODO test file name?
//TODO test location?
//TODO test the actual loggability

TEST_CASE("Logger tests", "[unit]"){
...;

REQUIRE(...);
SECTION("Creation of Logger File"){
...
}
}

2 changes: 1 addition & 1 deletion catch_tests/utils-and-constants/ECSUtilsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace {
}

TEST_CASE("make_vector_unique", "[unit]") {
std::vector<std::unique_ptr<Foo>> result = make_vector_unique<Foo>(std::make_unique<Foo>(21312),
etl::vector<std::unique_ptr<Foo>, 45> result = make_vector_unique<Foo>(std::make_unique<Foo>(21312),
std::make_unique<Foo>(45342),
std::make_unique<Foo>(7654),
std::make_unique<Foo>(345),
Expand Down
13 changes: 7 additions & 6 deletions catch_tests/watchdog/FakeWatchDogTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "watchdog/FakeWatchDog.h"
#include "watchdog/redlines/FakeRedline.h"
#include "utility"
#include <etl/vector.h>

TEST_CASE("FakeWatchDog constructors", "[unit]") {
SensorData data;
Expand All @@ -16,22 +17,22 @@ TEST_CASE("FakeWatchDog constructors", "[unit]") {
}

SECTION("Constructor stores list of redlines"){
std::vector<std::unique_ptr<IRedline>> redlines;
etl::vector<std::unique_ptr<IRedline>, 45> redlines;
redlines.emplace_back(std::make_unique<FakeRedline>("bruh", ECSRedLineResponse::WARN));

FakeWatchDog dog{std::move(redlines)};
REQUIRE(dog.stepRedlines(data).size() == 1);
}
SECTION("Constructor filters null pointers"){
std::vector<std::unique_ptr<IRedline>> redlines;
etl::vector<std::unique_ptr<IRedline>, 45> redlines;
redlines.emplace_back(std::unique_ptr<FakeRedline>());

FakeWatchDog dog{std::move(redlines)};
REQUIRE(dog.stepRedlines(data).empty());
}

SECTION("Constructor filters with valid and invalid redlines"){
std::vector<std::unique_ptr<IRedline>> redlines;
etl::vector<std::unique_ptr<IRedline>, 45> redlines;
redlines.emplace_back(std::make_unique<FakeRedline>("bruh", ECSRedLineResponse::WARN));
redlines.emplace_back(std::unique_ptr<FakeRedline>());

Expand All @@ -45,15 +46,15 @@ TEST_CASE("FakeWatchDog updateRedlines tests"){
SensorData data;

SECTION("Update stores list of redlines"){
std::vector<std::unique_ptr<IRedline>> redlines;
etl::vector<std::unique_ptr<IRedline>, 45> redlines;
redlines.emplace_back(std::make_unique<FakeRedline>("bruh", ECSRedLineResponse::WARN));

dog.updateRedlines(std::move(redlines));
REQUIRE(dog.stepRedlines(data).size() == 1);
}

SECTION("Update filters with valid and invalid redlines"){
std::vector<std::unique_ptr<IRedline>> redlines;
etl::vector<std::unique_ptr<IRedline>, 45> redlines;
redlines.emplace_back(std::make_unique<FakeRedline>("bruh", ECSRedLineResponse::WARN));
redlines.emplace_back(std::unique_ptr<FakeRedline>());

Expand All @@ -63,7 +64,7 @@ TEST_CASE("FakeWatchDog updateRedlines tests"){
}

TEST_CASE("FakeWatchDog stepRedlines works"){
std::vector<std::unique_ptr<IRedline>> redlines;
etl::vector<std::unique_ptr<IRedline>, 45> redlines;
redlines.emplace_back(std::make_unique<FakeRedline>("bruh1", ECSRedLineResponse::WARN));
redlines.emplace_back(std::make_unique<FakeRedline>("bruh2", ECSRedLineResponse::ABORT));
redlines.emplace_back(std::make_unique<FakeRedline>("bruh3", ECSRedLineResponse::SAFE));
Expand Down
3 changes: 2 additions & 1 deletion src/comm-boundary/FakeCommBoundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
//

#include "FakeCommBoundary.h"
#include <etl/vector.h>

void FakeCommBoundary::reportState([[maybe_unused]] ECSState &curState) {
this->stateReported = true;
}

void FakeCommBoundary::reportRedlines([[maybe_unused]] std::vector<RedlineResponsePacket> redlineReports) {
void FakeCommBoundary::reportRedlines([[maybe_unused]] etl::vector<RedlineResponsePacket, 45> redlineReports) {
this->redlinesReported = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/comm-boundary/FakeCommBoundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class FakeCommBoundary: public ICommBoundary{
public:
void reportState(ECSState& curState) override;
void reportRedlines(std::vector<RedlineResponsePacket>) override;
void reportRedlines(etl::vector<RedlineResponsePacket, 45>) override;
void reportSensorData(SensorData data, bool isCalibrated) override;
void reportMessage(std::string msg) override;

Expand Down
3 changes: 2 additions & 1 deletion src/comm-boundary/ICommBoundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "utils/SensorData.h"
#include "utils/ECSState.h"
#include "watchdog/redlines/RedlineResponsePacket.h"
#include <etl/vector.h>

/**
* An ICommBoundary is an abstraction for a object for communication to a controller/operator.
Expand All @@ -31,7 +32,7 @@ class ICommBoundary{
* Reports list of redline results back to operator
* @param redlineReports list of redline response data packets
*/
virtual void reportRedlines(std::vector<RedlineResponsePacket> redlineReports) = 0;
virtual void reportRedlines(etl::vector<RedlineResponsePacket, 45> redlineReports) = 0;

/**
* Reports the data back to the operator
Expand Down
3 changes: 2 additions & 1 deletion src/comm-boundary/SocketLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <utility>
#include "IncomingJsonParsers.h"
#include "OutgoingJsonParsers.h"
#include <etl/vector.h>

SocketLogger::SocketLogger(Logger logger_, std::queue<json> temp) :
incomingMessageQueue(std::move(temp)),
Expand Down Expand Up @@ -116,7 +117,7 @@ void SocketLogger::reportState([[maybe_unused]] ECSState &curState) {
// this->outgoingMessageQueue.push(parseECSState(curState).dump(4));
}

void SocketLogger::reportRedlines([[maybe_unused]] std::vector<RedlineResponsePacket> redlineReports) {
void SocketLogger::reportRedlines([[maybe_unused]] etl::vector<RedlineResponsePacket, 45> redlineReports) {
// this->outgoingMessageQueue.push(parseRedlines(redlineReports).dump(4));
}

Expand Down
3 changes: 2 additions & 1 deletion src/comm-boundary/SocketLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "utils/ThreadQueue.h"

#include "logger/Logger.h"
#include <etl/vector.h>

// forward declaration lmao
class IECS;
Expand Down Expand Up @@ -65,7 +66,7 @@ class SocketLogger: public ICommBoundary {
void processOutgoing();

void reportState(ECSState& curState) override;
void reportRedlines(std::vector<RedlineResponsePacket> redlineReports) override;
void reportRedlines(etl::vector<RedlineResponsePacket, 45> redlineReports) override;
void reportSensorData(SensorData data, bool isCalibrated) override;
void reportMessage(std::string msg) override;

Expand Down
22 changes: 11 additions & 11 deletions src/constants/AllConstants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> ONLINE_SAFE_DRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> ONLINE_SAFE_DRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::OPEN),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::OPEN),
Expand All @@ -92,7 +92,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> KERO_FILLRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> KERO_FILLRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::OPEN),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::OPEN),
Expand All @@ -117,7 +117,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> KERO_FILLEDRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> KERO_FILLEDRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::OPEN),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::OPEN),
Expand All @@ -142,7 +142,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> LOX_FILLRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> LOX_FILLRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::OPEN),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::OPEN),
Expand All @@ -167,7 +167,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> LOX_FILLEDRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> LOX_FILLEDRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::OPEN),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::OPEN),
Expand All @@ -192,7 +192,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> ALL_READY_TO_PRESSURIZERedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> ALL_READY_TO_PRESSURIZERedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::CLOSED),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::CLOSED),
Expand All @@ -217,7 +217,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> ALL_PRESSURIZINGRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> ALL_PRESSURIZINGRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::CLOSED),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::CLOSED),
Expand All @@ -242,7 +242,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> ALL_FLOW_closedRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> ALL_FLOW_closedRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::CLOSED),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::CLOSED),
Expand All @@ -267,7 +267,7 @@ namespace {
ECSValveState::OPEN,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> ALL_FLOW_openRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> ALL_FLOW_openRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::CLOSED),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::CLOSED),
Expand All @@ -292,7 +292,7 @@ namespace {
ECSValveState::CLOSED,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> KERO_FLOW_closedRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> KERO_FLOW_closedRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::CLOSED),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::CLOSED),
Expand All @@ -317,7 +317,7 @@ namespace {
ECSValveState::OPEN,
ECSValveState::CLOSED,
ECSValveState::CLOSED);
std::vector<std::unique_ptr<IRedline>> KERO_FLOW_openRedlines = make_vector_unique<IRedline>(
etl::vector<std::unique_ptr<IRedline>, 45> KERO_FLOW_openRedlines = make_vector_unique<IRedline>(
RedlineFactory("loxTankDucer", loxTankDucerSelector, 0, 15),
RedlineFactory("loxVent", loxVentSelector, ECSValveState::CLOSED),
RedlineFactory("kerVent", kerVentSelector, ECSValveState::CLOSED),
Expand Down
7 changes: 4 additions & 3 deletions src/utils/ECSState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ECSState.h"

#include <utility>
#include <etl/vector.h>

void swap(ECSState& left, ECSState& right) noexcept {
using std::swap;
Expand All @@ -16,7 +17,7 @@ void swap(ECSState& left, ECSState& right) noexcept {
}

ECSState::ECSState(std::string name_,
std::vector<std::unique_ptr<IRedline>> redlines_,
etl::vector<std::unique_ptr<IRedline>, 45> redlines_,
CommandData config_,
CommandData failState_):
name(std::move(name_)),
Expand All @@ -42,8 +43,8 @@ std::string ECSState::getName() const {
return this->name;
}

std::vector<std::unique_ptr<IRedline>> ECSState::getRedlines() const {
std::vector<std::unique_ptr<IRedline>> result;
etl::vector<std::unique_ptr<IRedline>, 45> ECSState::getRedlines() const {
etl::vector<std::unique_ptr<IRedline>, 45> result;

for (auto& elem: this->redlines){
result.emplace_back(elem->clone());
Expand Down
8 changes: 4 additions & 4 deletions src/utils/ECSState.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
#define BETTER_ENGINE_CONTROL_SOFTWARE_ISTATE_H

#include <string>
#include <vector>
#include "watchdog/redlines/IRedline.h"
#include "CommandData.h"
#include <etl/vector.h>

/**
* Represents a pre-defined state for the ECS to transition to
*/
class ECSState{
public:

ECSState(std::string name, std::vector<std::unique_ptr<IRedline>> redlines, CommandData config, CommandData failState);
ECSState(std::string name, etl::vector<std::unique_ptr<IRedline>, 45> redlines, CommandData config, CommandData failState);
~ECSState() = default;

ECSState(const ECSState& other);
Expand All @@ -33,7 +33,7 @@ class ECSState{
* Get redlines for this state
* @return redlines
*/
[[nodiscard]] std::vector<std::unique_ptr<IRedline>> getRedlines() const;
[[nodiscard]] etl::vector<std::unique_ptr<IRedline>, 45> getRedlines() const;

/**
* Get CommandData for this state
Expand All @@ -49,7 +49,7 @@ class ECSState{

private:
std::string name;
std::vector<std::unique_ptr<IRedline>> redlines;
etl::vector<std::unique_ptr<IRedline>, 45> redlines;
CommandData config;
CommandData failState;

Expand Down
4 changes: 2 additions & 2 deletions src/utils/ECSUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <cstdint>
#include <chrono>
#include <string>
#include <vector>
#include <memory>
#include <type_traits>
#include <etl/vector.h>

/**
* Method that allows construction of vector of unique_ptrs similar to the standard initializer list
Expand All @@ -19,7 +19,7 @@
* @return vector of type std::unique_ptr<V>
*/
template <class V, class ... Args> auto make_vector_unique(Args ... args) {
std::vector<std::unique_ptr<V>> rv;
etl::vector<std::unique_ptr<V>, 45> rv;
(rv.emplace_back(std::move(args)), ...);
return rv;
}
Expand Down
8 changes: 4 additions & 4 deletions src/watchdog/FakeWatchDog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "FakeWatchDog.h"
#include <utility>

FakeWatchDog::FakeWatchDog(std::vector<std::unique_ptr<IRedline>> conds):
FakeWatchDog::FakeWatchDog(etl::vector<std::unique_ptr<IRedline>, 45> conds):
conditions()
{
for(auto& redline: conds){
Expand All @@ -15,8 +15,8 @@ FakeWatchDog::FakeWatchDog(std::vector<std::unique_ptr<IRedline>> conds):
}
}

std::vector<RedlineResponsePacket> FakeWatchDog::stepRedlines(const SensorData& data){
std::vector<RedlineResponsePacket> result = {};
etl::vector<RedlineResponsePacket, 45> FakeWatchDog::stepRedlines(const SensorData& data){
etl::vector<RedlineResponsePacket, 45> result = {};

for(auto& curTest : this->conditions){
ECSRedLineResponse response = curTest->testCondition(data);
Expand All @@ -27,7 +27,7 @@ std::vector<RedlineResponsePacket> FakeWatchDog::stepRedlines(const SensorData&
return result;
}

void FakeWatchDog::updateRedlines(std::vector<std::unique_ptr<IRedline>> newRedlines) {
void FakeWatchDog::updateRedlines(etl::vector<std::unique_ptr<IRedline>, 45> newRedlines) {
this->conditions.clear();

for(auto& redline: newRedlines){
Expand Down
Loading
Loading