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

etl Mods #35

Open
wants to merge 3 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
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
3 changes: 2 additions & 1 deletion src/comm-boundary/FakeCommBoundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define BETTER_ENGINE_CONTROL_SOFTWARE_FAKECOMMBOUNDARY_H

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

/**
* Mock impl of ICommBoundary
Expand All @@ -15,7 +16,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
4 changes: 2 additions & 2 deletions src/comm-boundary/ICommBoundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define BETTER_ENGINE_CONTROL_SOFTWARE_ICOMMBOUNDARY_H

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

Expand All @@ -31,7 +31,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/OutgoingJsonParsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "OutgoingJsonParsers.h"
#include "ParsingHelpers.h"
#include "utils/ECSUtils.h"
#include <etl/vector.h>

// anonymous namespace for helper functions
namespace{
Expand Down Expand Up @@ -369,7 +370,7 @@ json parseECSState(ECSState& curState){
return state;
}

json parseRedlines(const std::vector<RedlineResponsePacket>& redlineReports){
json parseRedlines(const etl::vector<RedlineResponsePacket, 45>& redlineReports){
json report;
report["command"] = "REDLINE_REPORT";

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

using json = nlohmann::json;

Expand All @@ -32,7 +33,7 @@ json parseECSState(ECSState &curState);
* @param redlineReports vector of redline results
* @return json formatted according to specification in examples folder
*/
json parseRedlines(const std::vector<RedlineResponsePacket>& redlineReports);
json parseRedlines(const etl::vector<RedlineResponsePacket, 45>& redlineReports);

/**
* Returns JSON object describing a SensorData obtained from the ECS, for
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
4 changes: 2 additions & 2 deletions src/constants/AllCalibrations.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#define BETTER_ENGINE_CONTROL_SOFTWARE_ALLCALIBRATIONS_H

#include "phys-boundary/calibrators/SensorDataCalibrator.h"
#include <vector>
#include <etl/vector.h>

extern std::vector<SensorDataCalibrator> calibratorList;
extern etl::vector<SensorDataCalibrator, 30> calibratorList;


#endif //BETTER_ENGINE_CONTROL_SOFTWARE_ALLCALIBRATIONS_H
3 changes: 2 additions & 1 deletion src/phys-boundary/TeensyBoundary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

namespace{
/*
Expand Down Expand Up @@ -60,7 +61,7 @@ TeensyBoundary::TeensyBoundary(std::unique_ptr<IECSValve> loxPressurant_, std::u
std::unique_ptr<IECSValve> kerOrifice_,
std::unique_ptr<IECSValve> loxDrip_, std::unique_ptr<IECSValve> kerDrip_,
std::unique_ptr<IPacketSource<PropBoardSensorData>> pSource,
std::vector<SensorDataCalibrator> cList):
etl::vector<SensorDataCalibrator, 30> cList):
loxPressurant(std::move(loxPressurant_)),
kerPressurant(std::move(kerPressurant_)),
loxPurge(std::move(loxPurge_)),
Expand Down
5 changes: 3 additions & 2 deletions src/phys-boundary/TeensyBoundary.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "calibrators/SensorDataCalibrator.h"

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

/**
Expand All @@ -40,7 +41,7 @@ class TeensyBoundary: public IPhysicalBoundary{
std::unique_ptr<IECSValve> kerDrip,

std::unique_ptr<IPacketSource<PropBoardSensorData>> packetSource,
std::vector<SensorDataCalibrator> calibratorList = {});
etl::vector<SensorDataCalibrator, 30> calibratorList = {});


TeensyBoundary(const TeensyBoundary& other) = delete;
Expand Down Expand Up @@ -83,6 +84,6 @@ class TeensyBoundary: public IPhysicalBoundary{

std::unique_ptr<IPacketSource<PropBoardSensorData>> packetSource;

std::vector<SensorDataCalibrator> calibratorList;
etl::vector<SensorDataCalibrator, 30> calibratorList;
};
#endif //BETTER_ENGINE_CONTROL_SOFTWARE_TEENSYBOUNDARY_H
9 changes: 5 additions & 4 deletions src/utils/ECSState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
#include "ECSState.h"

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

void swap(ECSState& left, ECSState& right) noexcept {
using std::swap;

swap(left.name, right.name);
swap(left.redlines, right.redlines);
etl::swap(left.redlines, right.redlines);
swap(left.config, right.config);
swap(left.failState, right.failState);
}

ECSState::ECSState(std::string name_,
std::vector<std::unique_ptr<IRedline>> redlines_,
etl::vector<std::unique_ptr<IRedline>, 45> redlines_, //21 redlines, 9 states, 15 extra for margin
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,7 +6,7 @@
#define BETTER_ENGINE_CONTROL_SOFTWARE_ISTATE_H

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

Expand All @@ -16,7 +16,7 @@
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
6 changes: 3 additions & 3 deletions src/utils/ECSUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cstdint>
#include <chrono>
#include <string>
#include <vector>
#include <etl/vector.h>
#include <memory>
#include <type_traits>

Expand All @@ -18,8 +18,8 @@
* @param args elements of the vector
* @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;
template <class V, size_t size, class ... Args> auto make_vector_unique(Args ... args) {
etl::vector<std::unique_ptr<V>, size> 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
10 changes: 6 additions & 4 deletions src/watchdog/FakeWatchDog.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define BETTER_ENGINE_CONTROL_SOFTWARE_FAKEWATCHDOG_H

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

/**
* An implementation of WatchDog without any filtering
Expand All @@ -17,19 +18,20 @@ class FakeWatchDog: public IWatchDog{
* Stores list of initial redlines
*
* Filters out null pointers from list
* 30 REDLINES, 15 EXTRA FOR WARNINGS AND ABORTS
* @param conds list to store
*/
explicit FakeWatchDog(std::vector<std::unique_ptr<IRedline>> conds = {});
explicit FakeWatchDog(etl::vector<std::unique_ptr<IRedline>, 45> conds = {});

void updateRedlines(std::vector<std::unique_ptr<IRedline>> newRedlines) override;
void updateRedlines(etl::vector<std::unique_ptr<IRedline>, 45> newRedlines) override;

std::vector<RedlineResponsePacket> stepRedlines(const SensorData& data) override;
etl::vector<RedlineResponsePacket, 45> stepRedlines(const SensorData& data) override;

private:
/*
* INVARIANT: this vector does not contain null pointers
*/
std::vector<std::unique_ptr<IRedline>> conditions;
etl::vector<std::unique_ptr<IRedline>, 45> conditions;
};

#endif //BETTER_ENGINE_CONTROL_SOFTWARE_FAKEWATCHDOG_H
4 changes: 2 additions & 2 deletions src/watchdog/IWatchDog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class IWatchDog{
/**
* Updates stored current redlines list
*/
virtual void updateRedlines(std::vector<std::unique_ptr<IRedline>> newRedlines) = 0;
virtual void updateRedlines(etl::vector<std::unique_ptr<IRedline>, 45> newRedlines) = 0;

/**
* Runs passed sensor data through redlines list
* @param data sensor data to check
* @return list of tuples, each tuple being the failed redline's response, and the failed redline itself
*/
virtual std::vector<RedlineResponsePacket> stepRedlines(const SensorData& data) = 0;
virtual etl::vector<RedlineResponsePacket, 45> stepRedlines(const SensorData& data) = 0;
};
#endif //BETTER_ENGINE_CONTROL_SOFTWARE_IWATCHDOG_H
Loading