Skip to content

Commit

Permalink
Merge pull request #97 from nasa-jpl/dev-refactor-config-yaml
Browse files Browse the repository at this point in the history
1) Refactor the fastcat_types.yaml
  • Loading branch information
alex-brinkman authored May 10, 2023
2 parents dfba432 + 066d133 commit 0846f74
Show file tree
Hide file tree
Showing 51 changed files with 1,841 additions and 738 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project(fastcat
LANGUAGES C CXX
)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
87 changes: 33 additions & 54 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,75 +1,57 @@
####### Fastcat COG Autocoding #######
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/include/fastcat/types.h
COMMAND
cog -d -D cog_yaml_file=fcgen/fastcat_types.yaml
-o ${CMAKE_BINARY_DIR}/include/fastcat/types.h
${CMAKE_CURRENT_LIST_DIR}/fcgen/types.h.cog
DEPENDS
${CMAKE_CURRENT_LIST_DIR}/fcgen/fastcat_types.yaml
${CMAKE_CURRENT_LIST_DIR}/fcgen/types.h.cog
WORKING_DIRECTORY
${CMAKE_CURRENT_LIST_DIR}
COMMENT
"running fcgen - types"
VERBATIM
)

add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/fastcat/autogen/signal_handling.cc
COMMAND
cog -d -D cog_yaml_file=fcgen/fastcat_types.yaml
-o ${CMAKE_BINARY_DIR}/fastcat/autogen/signal_handling.cc
${CMAKE_CURRENT_LIST_DIR}/fcgen/signal_handling.cc.cog
DEPENDS
${CMAKE_BINARY_DIR}/include/fastcat/types.h
${CMAKE_CURRENT_LIST_DIR}/fcgen/signal_handling.cc.cog
WORKING_DIRECTORY
${CMAKE_CURRENT_LIST_DIR}
COMMENT
"running fcgen - signals"
VERBATIM
)
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/autogen)

add_custom_command(
function(run_fcgen fc_input_file fc_output_file)
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/fastcat/autogen/fastcat_devices/commander.cc
${fc_output_file}
COMMAND
cog -d -D cog_yaml_file=fcgen/fastcat_types.yaml
-o ${CMAKE_BINARY_DIR}/fastcat/autogen/fastcat_devices/commander.cc
${CMAKE_CURRENT_LIST_DIR}/fcgen/commander.cc.cog
cog -d
-D cog_yaml_file=fcgen/templates/${fc_input_file}
-D command_yaml=fcgen/fastcat_commands.yaml
-D device_yaml=fcgen/fastcat_devices.yaml
-D enum_yaml=fcgen/fastcat_enums.yaml
-D manager_yaml=fcgen/fastcat_manager_config.yaml
-o ${fc_output_file}
fcgen/templates/${fc_input_file}
DEPENDS
${CMAKE_BINARY_DIR}/include/fastcat/types.h
${CMAKE_CURRENT_LIST_DIR}/fcgen/commander.cc.cog
fcgen/fastcat_commands.yaml
fcgen/fastcat_devices.yaml
fcgen/fastcat_enums.yaml
fcgen/fastcat_manager_config.yaml
fcgen/templates/${fc_input_file}
WORKING_DIRECTORY
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_LIST_DIR}
COMMENT
"running fcgen - commander"
"fcgen: ${fc_input_file} -> ${fc_output_file}"
VERBATIM
)
endfunction()

add_custom_target(fcgen
DEPENDS
run_fcgen("types.h.cog" "${CMAKE_BINARY_DIR}/include/fastcat/types.h")
run_fcgen("device_includes.h.cog" "${CMAKE_BINARY_DIR}/include/fastcat/device_includes.h")
run_fcgen("signal_handling.cc.cog" "${CMAKE_BINARY_DIR}/autogen/signal_handling.cc")
run_fcgen("commander.cc.cog" "${CMAKE_BINARY_DIR}/autogen/commander.cc")

add_custom_target(fcgen DEPENDS
${CMAKE_BINARY_DIR}/include/fastcat/types.h
${CMAKE_BINARY_DIR}/fastcat/autogen/signal_handling.cc
${CMAKE_BINARY_DIR}/fastcat/autogen/fastcat_devices/commander.cc
${CMAKE_BINARY_DIR}/include/fastcat/device_includes.h
)

# Build a library regardless of BUILD_TESTS flag
add_library(fastcat STATIC
${CMAKE_BINARY_DIR}/autogen/signal_handling.cc
${CMAKE_BINARY_DIR}/autogen/commander.cc
trap.c
device_base.cc
manager.cc
yaml_parser.cc
${CMAKE_BINARY_DIR}/fastcat/autogen/signal_handling.cc
transform_utils.cc

jsd/jsd_device_base.cc

# JSD Devices
jsd/actuator.cc
jsd/actuator_fsm_helpers.cc

jsd/ati_fts.cc
jsd/egd.cc
jsd/el3208.cc
Expand All @@ -82,10 +64,9 @@ add_library(fastcat STATIC
jsd/el3318.cc
jsd/gold_actuator.cc
jsd/ild1900.cc
jsd/jed0101.cc
jsd/jed0200.cc
jsd/platinum_actuator.cc

# Offline Devices
jsd/ati_fts_offline.cc
jsd/egd_offline.cc
jsd/el2124_offline.cc
Expand All @@ -98,11 +79,9 @@ add_library(fastcat STATIC
jsd/el3318_offline.cc
jsd/ild1900_offline.cc
jsd/gold_actuator_offline.cc
jsd/jed0101_offline.cc
jsd/jed0200_offline.cc
jsd/platinum_actuator_offline.cc

${CMAKE_BINARY_DIR}/fastcat/autogen/fastcat_devices/commander.cc
# Fastcat Devices
fastcat_devices/signal_generator.cc
fastcat_devices/function.cc
fastcat_devices/conditional.cc
Expand Down
10 changes: 5 additions & 5 deletions src/fastcat_devices/conditional.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#include "fastcat/yaml_parser.h"
#include "jsd/jsd_print.h"

fastcat::ConditionalType fastcat::ConditionalTypeFromString(
fastcat::ConditionalOperatorType fastcat::ConditionalTypeFromString(
std::string cond_type)
{
ConditionalType type;
ConditionalOperatorType type;

if (cond_type.compare("<") == 0) {
type = LT;
Expand All @@ -28,7 +28,7 @@ fastcat::ConditionalType fastcat::ConditionalTypeFromString(
type = NE;

} else {
type = BAD_CONDITIONAL_TYPE;
type = BAD_CONDITIONAL_OPERATOR_TYPE;
ERROR("%s is not a known ConditionalType", cond_type.c_str());
}

Expand All @@ -38,7 +38,7 @@ fastcat::ConditionalType fastcat::ConditionalTypeFromString(
fastcat::Conditional::Conditional()
{
state_ = std::make_shared<DeviceState>();
state_->type = CONDITIONAL_STATE;
state_->type = CONDITIONAL_DEVICE;
}

bool fastcat::Conditional::ConfigFromYaml(YAML::Node node)
Expand All @@ -53,7 +53,7 @@ bool fastcat::Conditional::ConfigFromYaml(YAML::Node node)
}

conditional_type_ = ConditionalTypeFromString(conditional_type_string_);
if (conditional_type_ == BAD_CONDITIONAL_TYPE) {
if (conditional_type_ == BAD_CONDITIONAL_OPERATOR_TYPE) {
return false;
}

Expand Down
17 changes: 4 additions & 13 deletions src/fastcat_devices/conditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,8 @@

namespace fastcat
{
enum ConditionalType {
LT, // <
LE, // <=
GT, // >
GE, // >=
EQ, // ==, limited use for double types
NE, // !=, limited use for double types
BAD_CONDITIONAL_TYPE
};

ConditionalType ConditionalTypeFromString(std::string cond_type);
ConditionalOperatorType ConditionalTypeFromString(std::string cond_type);

class Conditional : public DeviceBase
{
Expand All @@ -30,9 +21,9 @@ class Conditional : public DeviceBase
bool Read() override;

protected:
std::string conditional_type_string_;
enum ConditionalType conditional_type_;
double compare_rhs_value_{0};
std::string conditional_type_string_;
ConditionalOperatorType conditional_type_;
double compare_rhs_value_{0};
};

} // namespace fastcat
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/faulter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fastcat::Faulter::Faulter()
{
state_ = std::make_shared<DeviceState>();
state_->type = FAULTER_STATE;
state_->type = FAULTER_DEVICE;
}

bool fastcat::Faulter::ConfigFromYaml(YAML::Node node)
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fastcat::FilterType fastcat::FilterTypeFromString(std::string str)
fastcat::Filter::Filter()
{
state_ = std::make_shared<DeviceState>();
state_->type = FILTER_STATE;
state_->type = FILTER_DEVICE;
}

bool fastcat::Filter::ConfigFromYaml(YAML::Node node)
Expand Down
2 changes: 0 additions & 2 deletions src/fastcat_devices/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class DigitalABFilter
std::vector<double> B_;
};

enum FilterType { MOVING_AVERAGE, DIGITAL_AB, BAD_FILTER_TYPE };

FilterType FilterTypeFromString(std::string str);

class Filter : public DeviceBase
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/fts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fastcat::Fts::Fts()
{
state_ = std::make_shared<DeviceState>();
state_->type = FTS_STATE;
state_->type = FTS_DEVICE;
}

bool fastcat::Fts::ConfigFromYaml(YAML::Node node)
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fastcat::Function::Function()
{
state_ = std::make_shared<DeviceState>();
state_->type = FUNCTION_STATE;
state_->type = FUNCTION_DEVICE;
}

fastcat::FunctionType fastcat::FunctionTypeFromString(
Expand Down
9 changes: 0 additions & 9 deletions src/fastcat_devices/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@

namespace fastcat
{
enum FunctionType {
POLYNOMIAL,
SUMMATION,
MULTIPLICATION,
POWER,
EXPONENTIAL,
SIGMOID,
BAD_FUNCTION_TYPE
};
FunctionType FunctionTypeFromString(const std::string&);

typedef struct {
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/linear_interpolation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
fastcat::LinearInterpolation::LinearInterpolation()
{
state_ = std::make_shared<DeviceState>();
state_->type = LINEAR_INTERPOLATION_STATE;
state_->type = LINEAR_INTERPOLATION_DEVICE;
}

bool fastcat::LinearInterpolation::ConfigFromYaml(YAML::Node node)
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/pid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fastcat::Pid::Pid()
{
state_ = std::make_shared<DeviceState>();
state_->type = PID_STATE;
state_->type = PID_DEVICE;
}

bool fastcat::Pid::ConfigFromYaml(YAML::Node node)
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/saturation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fastcat::Saturation::Saturation()
{
state_ = std::make_shared<DeviceState>();
state_->type = SATURATION_STATE;
state_->type = SATURATION_DEVICE;
}

bool fastcat::Saturation::ConfigFromYaml(YAML::Node node)
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/schmitt_trigger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fastcat::SchmittTrigger::SchmittTrigger()
{
state_ = std::make_shared<DeviceState>();
state_->type = SCHMITT_TRIGGER_STATE;
state_->type = SCHMITT_TRIGGER_DEVICE;
}

bool fastcat::SchmittTrigger::ConfigFromYaml(YAML::Node node)
Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/signal_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fastcat::SignalGenerator::SignalGenerator()
MSG_DEBUG("Constructed SignalGenerator");

state_ = std::make_shared<DeviceState>();
state_->type = SIGNAL_GENERATOR_STATE;
state_->type = SIGNAL_GENERATOR_DEVICE;
}

bool fastcat::SignalGenerator::ConfigFromYaml(YAML::Node node)
Expand Down
10 changes: 1 addition & 9 deletions src/fastcat_devices/signal_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@

namespace fastcat
{
enum SignalGeneratorType {
SINE_WAVE,
SAW_TOOTH,
GAUSSIAN_RANDOM,
UNIFORM_RANDOM,
BAD_SIGNAL_GENERATOR_TYPE
};

SignalGeneratorType SignalGeneratorTypeFromString(const std::string&);

typedef struct {
Expand Down Expand Up @@ -60,7 +52,7 @@ class SignalGenerator : public DeviceBase

protected:
std::string signal_generator_type_string_;
enum SignalGeneratorType signal_generator_type_;
SignalGeneratorType signal_generator_type_;
double start_time_ = 0;
std::default_random_engine generator_;

Expand Down
2 changes: 1 addition & 1 deletion src/fastcat_devices/virtual_fts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
fastcat::VirtualFts::VirtualFts()
{
state_ = std::make_shared<DeviceState>();
state_->type = FTS_STATE;
state_->type = FTS_DEVICE;
}

bool fastcat::VirtualFts::ConfigFromYaml(YAML::Node node)
Expand Down
23 changes: 0 additions & 23 deletions src/fcgen/README.md

This file was deleted.

Loading

0 comments on commit 0846f74

Please sign in to comment.