From 10db13964fe414170fe5d0722a7f85e1720a85dd Mon Sep 17 00:00:00 2001 From: Alex Brinkman Date: Fri, 28 Apr 2023 16:14:23 -0700 Subject: [PATCH 1/6] add enum conversions --- src/CMakeLists.txt | 18 +++-- src/config.h.in | 3 +- src/fcgen/templates/commander.cc.cog | 3 +- .../device_config_parsing_libyamlcpp.h.cog | 35 ++++++++++ src/fcgen/templates/device_includes.h.cog | 1 - src/fcgen/templates/enum_conversions.h.cog | 66 +++++++++++++++++++ src/fcgen/templates/signal_handling.cc.cog | 3 +- src/fcgen/templates/types.h.cog | 1 - test/CMakeLists.txt | 3 +- .../CMakeLists.txt | 3 - .../test_ati_fts.cc | 5 +- .../test_ati_fts_yamls/nominal.yaml | 0 .../test_commander.cc | 4 +- .../test_commander_yamls/c1_config.yaml | 0 .../test_commander_yamls/c2_config.yaml | 0 .../test_commander_yamls/c3_config.yaml | 0 .../test_commander_yamls/sig_gen_config.yaml | 0 .../test_conditional.cc | 4 +- .../test_conditional_yamls/c1_config.yaml | 0 .../test_conditional_yamls/c2_config.yaml | 0 .../test_conditional_yamls/c3_config.yaml | 0 test/{test_unit => device_tests}/test_fts.cc | 5 +- .../test_fts_yamls/fts_wide_cal_matrix.yaml | 0 .../test_fts_yamls/nominal.yaml | 0 .../test_function.cc | 4 +- .../test_function_yamls/f1_config.yaml | 0 .../test_function_yamls/f2_config.yaml | 0 .../test_function_yamls/f3_config.yaml | 0 .../test_gold_actuator.cc | 5 +- .../test_gold_actuator_yamls/valid.yaml | 0 .../valid_with_opts.yaml | 0 .../valid_with_power.yaml | 0 .../test_linear_interpolation.cc | 4 +- .../invalid_1.yaml | 0 .../invalid_2.yaml | 0 .../invalid_3.yaml | 0 .../invalid_4.yaml | 0 .../invalid_5.yaml | 0 .../invalid_6.yaml | 0 .../invalid_7.yaml | 0 .../valid_abs.yaml | 0 .../valid_abs_no_error.yaml | 0 .../test_schmitt_trigger.cc | 4 +- .../st1_config.yaml | 0 .../st2_config.yaml | 0 .../st3_config.yaml | 0 .../test_signal_generator.cc | 4 +- .../sg1_config.yaml | 0 .../sg2_config.yaml | 0 .../sg3_config.yaml | 0 .../sg4_config.yaml | 0 .../test_virtual_fts.cc | 5 +- .../test_virtual_fts_yamls/nominal.yaml | 0 .../test_yaml_parser.cc | 5 +- .../yaml_parser_config.yaml | 0 test/unit_tests/CMakeLists.txt | 33 ++++++++++ test/unit_tests/test_enum_conversions.cc | 10 +++ .../test_jsd_device_base.cc | 0 .../test_transform_utils.cc | 0 test/{test_unit => unit_tests}/test_trap.cc | 0 60 files changed, 187 insertions(+), 41 deletions(-) create mode 100644 src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog create mode 100644 src/fcgen/templates/enum_conversions.h.cog rename test/{test_unit => device_tests}/CMakeLists.txt (92%) rename test/{test_unit => device_tests}/test_ati_fts.cc (90%) rename test/{test_unit => device_tests}/test_ati_fts_yamls/nominal.yaml (100%) rename test/{test_unit => device_tests}/test_commander.cc (96%) rename test/{test_unit => device_tests}/test_commander_yamls/c1_config.yaml (100%) rename test/{test_unit => device_tests}/test_commander_yamls/c2_config.yaml (100%) rename test/{test_unit => device_tests}/test_commander_yamls/c3_config.yaml (100%) rename test/{test_unit => device_tests}/test_commander_yamls/sig_gen_config.yaml (100%) rename test/{test_unit => device_tests}/test_conditional.cc (96%) rename test/{test_unit => device_tests}/test_conditional_yamls/c1_config.yaml (100%) rename test/{test_unit => device_tests}/test_conditional_yamls/c2_config.yaml (100%) rename test/{test_unit => device_tests}/test_conditional_yamls/c3_config.yaml (100%) rename test/{test_unit => device_tests}/test_fts.cc (93%) rename test/{test_unit => device_tests}/test_fts_yamls/fts_wide_cal_matrix.yaml (100%) rename test/{test_unit => device_tests}/test_fts_yamls/nominal.yaml (100%) rename test/{test_unit => device_tests}/test_function.cc (96%) rename test/{test_unit => device_tests}/test_function_yamls/f1_config.yaml (100%) rename test/{test_unit => device_tests}/test_function_yamls/f2_config.yaml (100%) rename test/{test_unit => device_tests}/test_function_yamls/f3_config.yaml (100%) rename test/{test_unit => device_tests}/test_gold_actuator.cc (98%) rename test/{test_unit => device_tests}/test_gold_actuator_yamls/valid.yaml (100%) rename test/{test_unit => device_tests}/test_gold_actuator_yamls/valid_with_opts.yaml (100%) rename test/{test_unit => device_tests}/test_gold_actuator_yamls/valid_with_power.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation.cc (97%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/invalid_1.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/invalid_2.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/invalid_3.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/invalid_4.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/invalid_5.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/invalid_6.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/invalid_7.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/valid_abs.yaml (100%) rename test/{test_unit => device_tests}/test_linear_interpolation_yamls/valid_abs_no_error.yaml (100%) rename test/{test_unit => device_tests}/test_schmitt_trigger.cc (96%) rename test/{test_unit => device_tests}/test_schmitt_trigger_yamls/st1_config.yaml (100%) rename test/{test_unit => device_tests}/test_schmitt_trigger_yamls/st2_config.yaml (100%) rename test/{test_unit => device_tests}/test_schmitt_trigger_yamls/st3_config.yaml (100%) rename test/{test_unit => device_tests}/test_signal_generator.cc (95%) rename test/{test_unit => device_tests}/test_signal_generator_yamls/sg1_config.yaml (100%) rename test/{test_unit => device_tests}/test_signal_generator_yamls/sg2_config.yaml (100%) rename test/{test_unit => device_tests}/test_signal_generator_yamls/sg3_config.yaml (100%) rename test/{test_unit => device_tests}/test_signal_generator_yamls/sg4_config.yaml (100%) rename test/{test_unit => device_tests}/test_virtual_fts.cc (88%) rename test/{test_unit => device_tests}/test_virtual_fts_yamls/nominal.yaml (100%) rename test/{test_unit => device_tests}/test_yaml_parser.cc (96%) rename test/{test_unit => device_tests}/test_yaml_parser_yamls/yaml_parser_config.yaml (100%) create mode 100644 test/unit_tests/CMakeLists.txt create mode 100644 test/unit_tests/test_enum_conversions.cc rename test/{test_unit => unit_tests}/test_jsd_device_base.cc (100%) rename test/{test_unit => unit_tests}/test_transform_utils.cc (100%) rename test/{test_unit => unit_tests}/test_trap.cc (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3fa54c9..428cafa 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,14 +29,24 @@ function(run_fcgen fc_input_file fc_output_file) ) endfunction() -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") +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) + +run_fcgen( + enum_conversions.h.cog + ${CMAKE_BINARY_DIR}/include/fastcat/enum_conversions.h) + +run_fcgen( + device_config_parsing_libyamlcpp.h.cog + ${CMAKE_BINARY_DIR}/include/fastcat/device_config_parsing_libyamlcpp.h) add_custom_target(fcgen DEPENDS ${CMAKE_BINARY_DIR}/include/fastcat/types.h ${CMAKE_BINARY_DIR}/include/fastcat/device_includes.h + ${CMAKE_BINARY_DIR}/include/fastcat/enum_conversions.h + ${CMAKE_BINARY_DIR}/include/fastcat/device_config_parsing_libyamlcpp.h ) add_library(fastcat STATIC diff --git a/src/config.h.in b/src/config.h.in index bf48cfa..f216c88 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -2,7 +2,8 @@ #define FASTCAT_CONFIG_H_ #define FASTCAT_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@" -#define FASTCAT_UNIT_TEST_DIR "@CMAKE_CURRENT_SOURCE_DIR@/test/test_unit/" +#define FASTCAT_TEST_DIR "@CMAKE_CURRENT_SOURCE_DIR@/test/" + #define FASTCAT_VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR} #define FASTCAT_VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR} #define FASTCAT_VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH} diff --git a/src/fcgen/templates/commander.cc.cog b/src/fcgen/templates/commander.cc.cog index 7b42a13..52341c1 100644 --- a/src/fcgen/templates/commander.cc.cog +++ b/src/fcgen/templates/commander.cc.cog @@ -11,8 +11,7 @@ enum_data = yaml.load(open(enum_yaml, 'r'), Loader=yaml.Loader) manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) -cog.outl('// using the python cog tool.') -cog.outl('// Please make modifications to fcgen/commander.cc.cog') +cog.outl('// using the python cog tool. Do not modify this file manually.') ]]] [[[end]]] diff --git a/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog b/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog new file mode 100644 index 0000000..75da82f --- /dev/null +++ b/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog @@ -0,0 +1,35 @@ +#ifndef FASTCAT_DEVICE_CONFIG_PARSING_LIBYAMLCPP_HPP_ +#define FASTCAT_DEVICE_CONFIG_PARSING_LIBYAMLCPP_HPP_ + +[[[cog +import yaml +import re + +def snake2camel(str): + return ''.join(x.capitalize() or '_' for x in str.split('_')) + +cmd_data = yaml.load(open(command_yaml, 'r'), Loader=yaml.Loader) +device_data = yaml.load(open(device_yaml, 'r'), Loader=yaml.Loader) +enum_data = yaml.load(open(enum_yaml, 'r'), Loader=yaml.Loader) +manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) + +cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) +cog.outl('// using the python cog tool. Do not modify this file manually.') +]]] +[[[end]]] + +#include "fastcat/enum_conversions.h" + + +[[[cog +for this_enum in enum_data['enumerations']: + cog.outl('enum %s {' % (snake2camel(this_enum['name']))) + for entry in this_enum['entries']: + cog.outl('%s,' % entry['value'].upper()) + cog.outl('BAD_%s' % this_enum['name'].upper()) + cog.outl('};') + +]]] +[[[end]]] + +#endif diff --git a/src/fcgen/templates/device_includes.h.cog b/src/fcgen/templates/device_includes.h.cog index b0ddbbe..bd11192 100644 --- a/src/fcgen/templates/device_includes.h.cog +++ b/src/fcgen/templates/device_includes.h.cog @@ -12,7 +12,6 @@ manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) cog.outl('// using the python cog tool. Do not modify this file manually.') -cog.outl('// Please make modifications to fcgen/fastcat_devices.h.cog') ]]] [[[end]]] diff --git a/src/fcgen/templates/enum_conversions.h.cog b/src/fcgen/templates/enum_conversions.h.cog new file mode 100644 index 0000000..7f3fbe2 --- /dev/null +++ b/src/fcgen/templates/enum_conversions.h.cog @@ -0,0 +1,66 @@ +#ifndef FASTCAT_ENUM_CONVERSIONS_H_ +#define FASTCAT_ENUM_CONVERSIONS_H_ + +[[[cog +import yaml +import re + +def snake2camel(str): + return ''.join(x.capitalize() or '_' for x in str.split('_')) + +cmd_data = yaml.load(open(command_yaml, 'r'), Loader=yaml.Loader) +device_data = yaml.load(open(device_yaml, 'r'), Loader=yaml.Loader) +enum_data = yaml.load(open(enum_yaml, 'r'), Loader=yaml.Loader) +manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) + +cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) +cog.outl('// using the python cog tool. Do not modify this file manually.') +]]] +[[[end]]] + + +#include "fastcat/types.h" +#include "jsd/jsd_print.h" + +namespace fastcat { + +[[[cog +for this_enum in enum_data['enumerations']: + cog.outl('%s %sFromString(const std::string& s){' % ( + snake2camel(this_enum['name']), + snake2camel(this_enum['name']))) + cog.outl('%s e = BAD_%s;' % ( + snake2camel(this_enum['name']), + this_enum['name'].upper() + )) + + first_entry = True + for entry in this_enum['entries']: + if 'string' in entry.keys(): + compare_str = entry['string'] + else: + compare_str = entry['value'] + + if first_entry: + cog.outl('if (s.compare("%s") == 0) {' % (compare_str)) + first_entry = False + else: + cog.outl('} else if (s.compare("%s") == 0) {' % (compare_str)) + + cog.outl('e = %s;' % entry['value']) + + cog.outl('} else {') + cog.outl('ERROR("%s is not valid value for %s", s.c_str());' % ("%s", snake2camel(this_enum['name']))) + + cog.outl('}') + cog.outl('') + cog.outl('return e;') + + cog.outl('};') + cog.outl('') +]]] +[[[end]]] + +}; // namespace fastcat + +#endif diff --git a/src/fcgen/templates/signal_handling.cc.cog b/src/fcgen/templates/signal_handling.cc.cog index e24cb08..5456a00 100644 --- a/src/fcgen/templates/signal_handling.cc.cog +++ b/src/fcgen/templates/signal_handling.cc.cog @@ -11,8 +11,7 @@ enum_data = yaml.load(open(enum_yaml, 'r'), Loader=yaml.Loader) manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) -cog.outl('// using the python cog tool.') -cog.outl('// Please make modifications to fcgen/signal_handling.cc.cog') +cog.outl('// using the python cog tool. Do not modify this file manually.') dtype_native_enum = [ ('bool' , 'DATA_TYPE_BOOL'), diff --git a/src/fcgen/templates/types.h.cog b/src/fcgen/templates/types.h.cog index 3a2ca93..0202119 100644 --- a/src/fcgen/templates/types.h.cog +++ b/src/fcgen/templates/types.h.cog @@ -12,7 +12,6 @@ manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) cog.outl('// using the python cog tool. Do not modify this file manually.') -cog.outl('// Please make modifications to fcgen/types.h.cog') ]]] [[[end]]] diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 41cb7ab..b109089 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,7 +23,8 @@ target_link_libraries(test_cli ${fastcat_test_libs}) find_package(GTest) if(GTEST_FOUND) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test_unit) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/device_tests) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/unit_tests) find_program(VALGRIND_EXECUTABLE NAMES valgrind) if(VALGRIND_EXECUTABLE) diff --git a/test/test_unit/CMakeLists.txt b/test/device_tests/CMakeLists.txt similarity index 92% rename from test/test_unit/CMakeLists.txt rename to test/device_tests/CMakeLists.txt index 5e52e94..35395eb 100644 --- a/test/test_unit/CMakeLists.txt +++ b/test/device_tests/CMakeLists.txt @@ -6,12 +6,9 @@ set(TEST_SOURCES test_commander.cc test_conditional.cc test_function.cc - test_jsd_device_base.cc test_linear_interpolation.cc test_schmitt_trigger.cc test_signal_generator.cc - test_transform_utils.cc - test_trap.cc test_yaml_parser.cc test_fts.cc test_ati_fts.cc diff --git a/test/test_unit/test_ati_fts.cc b/test/device_tests/test_ati_fts.cc similarity index 90% rename from test/test_unit/test_ati_fts.cc rename to test/device_tests/test_ati_fts.cc index 66a7d48..06fdab8 100644 --- a/test/test_unit/test_ati_fts.cc +++ b/test/device_tests/test_ati_fts.cc @@ -17,9 +17,8 @@ class AtiFtsTest : public ::testing::Test { jsd_context_ = jsd_alloc(); - // FASTCAT_UNIT_TEST_DIR contains path to . - base_dir_ = FASTCAT_UNIT_TEST_DIR; - base_dir_ += "test_ati_fts_yamls/"; + base_dir_ = FASTCAT_TEST_DIR; + base_dir_ += "device_tests/test_ati_fts_yamls/"; device_.SetSlaveId(0); device_.SetContext(jsd_context_); diff --git a/test/test_unit/test_ati_fts_yamls/nominal.yaml b/test/device_tests/test_ati_fts_yamls/nominal.yaml similarity index 100% rename from test/test_unit/test_ati_fts_yamls/nominal.yaml rename to test/device_tests/test_ati_fts_yamls/nominal.yaml diff --git a/test/test_unit/test_commander.cc b/test/device_tests/test_commander.cc similarity index 96% rename from test/test_unit/test_commander.cc rename to test/device_tests/test_commander.cc index ccab3d3..550eb71 100644 --- a/test/test_unit/test_commander.cc +++ b/test/device_tests/test_commander.cc @@ -10,8 +10,8 @@ class CommanderTest : public ::testing::Test protected: void SetUp() override { - std::string unit_test_dir(FASTCAT_UNIT_TEST_DIR); - unit_test_dir += "test_commander_yamls/"; + std::string unit_test_dir(FASTCAT_TEST_DIR); + unit_test_dir += "device_tests/test_commander_yamls/"; config_node = YAML::LoadFile(unit_test_dir + "c1_config.yaml"); c2_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "c2_config.yaml")); c3_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "c3_config.yaml")); diff --git a/test/test_unit/test_commander_yamls/c1_config.yaml b/test/device_tests/test_commander_yamls/c1_config.yaml similarity index 100% rename from test/test_unit/test_commander_yamls/c1_config.yaml rename to test/device_tests/test_commander_yamls/c1_config.yaml diff --git a/test/test_unit/test_commander_yamls/c2_config.yaml b/test/device_tests/test_commander_yamls/c2_config.yaml similarity index 100% rename from test/test_unit/test_commander_yamls/c2_config.yaml rename to test/device_tests/test_commander_yamls/c2_config.yaml diff --git a/test/test_unit/test_commander_yamls/c3_config.yaml b/test/device_tests/test_commander_yamls/c3_config.yaml similarity index 100% rename from test/test_unit/test_commander_yamls/c3_config.yaml rename to test/device_tests/test_commander_yamls/c3_config.yaml diff --git a/test/test_unit/test_commander_yamls/sig_gen_config.yaml b/test/device_tests/test_commander_yamls/sig_gen_config.yaml similarity index 100% rename from test/test_unit/test_commander_yamls/sig_gen_config.yaml rename to test/device_tests/test_commander_yamls/sig_gen_config.yaml diff --git a/test/test_unit/test_conditional.cc b/test/device_tests/test_conditional.cc similarity index 96% rename from test/test_unit/test_conditional.cc rename to test/device_tests/test_conditional.cc index e0ce816..b09cb14 100644 --- a/test/test_unit/test_conditional.cc +++ b/test/device_tests/test_conditional.cc @@ -11,8 +11,8 @@ class ConditionalTest : public ::testing::Test protected: void SetUp() override { - std::string unit_test_dir(FASTCAT_UNIT_TEST_DIR); - unit_test_dir += "test_conditional_yamls/"; + std::string unit_test_dir(FASTCAT_TEST_DIR); + unit_test_dir += "device_tests/test_conditional_yamls/"; config_node = YAML::LoadFile(unit_test_dir + "c1_config.yaml"); c2_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "c2_config.yaml")); c3_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "c3_config.yaml")); diff --git a/test/test_unit/test_conditional_yamls/c1_config.yaml b/test/device_tests/test_conditional_yamls/c1_config.yaml similarity index 100% rename from test/test_unit/test_conditional_yamls/c1_config.yaml rename to test/device_tests/test_conditional_yamls/c1_config.yaml diff --git a/test/test_unit/test_conditional_yamls/c2_config.yaml b/test/device_tests/test_conditional_yamls/c2_config.yaml similarity index 100% rename from test/test_unit/test_conditional_yamls/c2_config.yaml rename to test/device_tests/test_conditional_yamls/c2_config.yaml diff --git a/test/test_unit/test_conditional_yamls/c3_config.yaml b/test/device_tests/test_conditional_yamls/c3_config.yaml similarity index 100% rename from test/test_unit/test_conditional_yamls/c3_config.yaml rename to test/device_tests/test_conditional_yamls/c3_config.yaml diff --git a/test/test_unit/test_fts.cc b/test/device_tests/test_fts.cc similarity index 93% rename from test/test_unit/test_fts.cc rename to test/device_tests/test_fts.cc index c11d3b2..d28e0eb 100644 --- a/test/test_unit/test_fts.cc +++ b/test/device_tests/test_fts.cc @@ -12,9 +12,8 @@ class FtsTest : public ::testing::Test protected: void SetUp() override { - // FASTCAT_UNIT_TEST_DIR contains path to . - base_dir_ = FASTCAT_UNIT_TEST_DIR; - base_dir_ += "test_fts_yamls/"; + base_dir_ = FASTCAT_TEST_DIR; + base_dir_ += "device_tests/test_fts_yamls/"; } std::string base_dir_; diff --git a/test/test_unit/test_fts_yamls/fts_wide_cal_matrix.yaml b/test/device_tests/test_fts_yamls/fts_wide_cal_matrix.yaml similarity index 100% rename from test/test_unit/test_fts_yamls/fts_wide_cal_matrix.yaml rename to test/device_tests/test_fts_yamls/fts_wide_cal_matrix.yaml diff --git a/test/test_unit/test_fts_yamls/nominal.yaml b/test/device_tests/test_fts_yamls/nominal.yaml similarity index 100% rename from test/test_unit/test_fts_yamls/nominal.yaml rename to test/device_tests/test_fts_yamls/nominal.yaml diff --git a/test/test_unit/test_function.cc b/test/device_tests/test_function.cc similarity index 96% rename from test/test_unit/test_function.cc rename to test/device_tests/test_function.cc index bd3871b..848467b 100644 --- a/test/test_unit/test_function.cc +++ b/test/device_tests/test_function.cc @@ -11,8 +11,8 @@ class FunctionTest : public ::testing::Test protected: void SetUp() override { - std::string unit_test_dir(FASTCAT_UNIT_TEST_DIR); - unit_test_dir += "test_function_yamls/"; + std::string unit_test_dir(FASTCAT_TEST_DIR); + unit_test_dir += "device_tests/test_function_yamls/"; config_node = YAML::LoadFile(unit_test_dir + "f1_config.yaml"); f2_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "f2_config.yaml")); f3_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "f3_config.yaml")); diff --git a/test/test_unit/test_function_yamls/f1_config.yaml b/test/device_tests/test_function_yamls/f1_config.yaml similarity index 100% rename from test/test_unit/test_function_yamls/f1_config.yaml rename to test/device_tests/test_function_yamls/f1_config.yaml diff --git a/test/test_unit/test_function_yamls/f2_config.yaml b/test/device_tests/test_function_yamls/f2_config.yaml similarity index 100% rename from test/test_unit/test_function_yamls/f2_config.yaml rename to test/device_tests/test_function_yamls/f2_config.yaml diff --git a/test/test_unit/test_function_yamls/f3_config.yaml b/test/device_tests/test_function_yamls/f3_config.yaml similarity index 100% rename from test/test_unit/test_function_yamls/f3_config.yaml rename to test/device_tests/test_function_yamls/f3_config.yaml diff --git a/test/test_unit/test_gold_actuator.cc b/test/device_tests/test_gold_actuator.cc similarity index 98% rename from test/test_unit/test_gold_actuator.cc rename to test/device_tests/test_gold_actuator.cc index c52bdee..5783b76 100644 --- a/test/test_unit/test_gold_actuator.cc +++ b/test/device_tests/test_gold_actuator.cc @@ -41,9 +41,8 @@ class ActuatorTest : public ::testing::Test { jsd_context_ = jsd_alloc(); - // FASTCAT_UNIT_TEST_DIR contains path to . - base_dir_ = FASTCAT_UNIT_TEST_DIR; - base_dir_ += "test_gold_actuator_yamls/"; + base_dir_ = FASTCAT_TEST_DIR; + base_dir_ += "device_tests/test_gold_actuator_yamls/"; device_.SetSlaveId(0); device_.SetContext(jsd_context_); diff --git a/test/test_unit/test_gold_actuator_yamls/valid.yaml b/test/device_tests/test_gold_actuator_yamls/valid.yaml similarity index 100% rename from test/test_unit/test_gold_actuator_yamls/valid.yaml rename to test/device_tests/test_gold_actuator_yamls/valid.yaml diff --git a/test/test_unit/test_gold_actuator_yamls/valid_with_opts.yaml b/test/device_tests/test_gold_actuator_yamls/valid_with_opts.yaml similarity index 100% rename from test/test_unit/test_gold_actuator_yamls/valid_with_opts.yaml rename to test/device_tests/test_gold_actuator_yamls/valid_with_opts.yaml diff --git a/test/test_unit/test_gold_actuator_yamls/valid_with_power.yaml b/test/device_tests/test_gold_actuator_yamls/valid_with_power.yaml similarity index 100% rename from test/test_unit/test_gold_actuator_yamls/valid_with_power.yaml rename to test/device_tests/test_gold_actuator_yamls/valid_with_power.yaml diff --git a/test/test_unit/test_linear_interpolation.cc b/test/device_tests/test_linear_interpolation.cc similarity index 97% rename from test/test_unit/test_linear_interpolation.cc rename to test/device_tests/test_linear_interpolation.cc index a0da04c..49b2369 100644 --- a/test/test_unit/test_linear_interpolation.cc +++ b/test/device_tests/test_linear_interpolation.cc @@ -14,8 +14,8 @@ class LinearInterpolationTest : public ::testing::Test protected: void SetUp() override { - base_dir_ = FASTCAT_UNIT_TEST_DIR; - base_dir_ += "test_linear_interpolation_yamls/"; + base_dir_ = FASTCAT_TEST_DIR; + base_dir_ += "device_tests/test_linear_interpolation_yamls/"; } std::string base_dir_; diff --git a/test/test_unit/test_linear_interpolation_yamls/invalid_1.yaml b/test/device_tests/test_linear_interpolation_yamls/invalid_1.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/invalid_1.yaml rename to test/device_tests/test_linear_interpolation_yamls/invalid_1.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/invalid_2.yaml b/test/device_tests/test_linear_interpolation_yamls/invalid_2.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/invalid_2.yaml rename to test/device_tests/test_linear_interpolation_yamls/invalid_2.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/invalid_3.yaml b/test/device_tests/test_linear_interpolation_yamls/invalid_3.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/invalid_3.yaml rename to test/device_tests/test_linear_interpolation_yamls/invalid_3.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/invalid_4.yaml b/test/device_tests/test_linear_interpolation_yamls/invalid_4.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/invalid_4.yaml rename to test/device_tests/test_linear_interpolation_yamls/invalid_4.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/invalid_5.yaml b/test/device_tests/test_linear_interpolation_yamls/invalid_5.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/invalid_5.yaml rename to test/device_tests/test_linear_interpolation_yamls/invalid_5.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/invalid_6.yaml b/test/device_tests/test_linear_interpolation_yamls/invalid_6.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/invalid_6.yaml rename to test/device_tests/test_linear_interpolation_yamls/invalid_6.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/invalid_7.yaml b/test/device_tests/test_linear_interpolation_yamls/invalid_7.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/invalid_7.yaml rename to test/device_tests/test_linear_interpolation_yamls/invalid_7.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/valid_abs.yaml b/test/device_tests/test_linear_interpolation_yamls/valid_abs.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/valid_abs.yaml rename to test/device_tests/test_linear_interpolation_yamls/valid_abs.yaml diff --git a/test/test_unit/test_linear_interpolation_yamls/valid_abs_no_error.yaml b/test/device_tests/test_linear_interpolation_yamls/valid_abs_no_error.yaml similarity index 100% rename from test/test_unit/test_linear_interpolation_yamls/valid_abs_no_error.yaml rename to test/device_tests/test_linear_interpolation_yamls/valid_abs_no_error.yaml diff --git a/test/test_unit/test_schmitt_trigger.cc b/test/device_tests/test_schmitt_trigger.cc similarity index 96% rename from test/test_unit/test_schmitt_trigger.cc rename to test/device_tests/test_schmitt_trigger.cc index 37d0092..fcc592f 100644 --- a/test/test_unit/test_schmitt_trigger.cc +++ b/test/device_tests/test_schmitt_trigger.cc @@ -11,8 +11,8 @@ class SchmittTriggerTest : public ::testing::Test protected: void SetUp() override { - std::string unit_test_dir(FASTCAT_UNIT_TEST_DIR); - unit_test_dir += "test_schmitt_trigger_yamls/"; + std::string unit_test_dir(FASTCAT_TEST_DIR); + unit_test_dir += "device_tests/test_schmitt_trigger_yamls/"; config_node = YAML::LoadFile(unit_test_dir + "st1_config.yaml"); st2_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "st2_config.yaml")); st3_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "st3_config.yaml")); diff --git a/test/test_unit/test_schmitt_trigger_yamls/st1_config.yaml b/test/device_tests/test_schmitt_trigger_yamls/st1_config.yaml similarity index 100% rename from test/test_unit/test_schmitt_trigger_yamls/st1_config.yaml rename to test/device_tests/test_schmitt_trigger_yamls/st1_config.yaml diff --git a/test/test_unit/test_schmitt_trigger_yamls/st2_config.yaml b/test/device_tests/test_schmitt_trigger_yamls/st2_config.yaml similarity index 100% rename from test/test_unit/test_schmitt_trigger_yamls/st2_config.yaml rename to test/device_tests/test_schmitt_trigger_yamls/st2_config.yaml diff --git a/test/test_unit/test_schmitt_trigger_yamls/st3_config.yaml b/test/device_tests/test_schmitt_trigger_yamls/st3_config.yaml similarity index 100% rename from test/test_unit/test_schmitt_trigger_yamls/st3_config.yaml rename to test/device_tests/test_schmitt_trigger_yamls/st3_config.yaml diff --git a/test/test_unit/test_signal_generator.cc b/test/device_tests/test_signal_generator.cc similarity index 95% rename from test/test_unit/test_signal_generator.cc rename to test/device_tests/test_signal_generator.cc index 2fb12bc..ad480fb 100644 --- a/test/test_unit/test_signal_generator.cc +++ b/test/device_tests/test_signal_generator.cc @@ -10,8 +10,8 @@ class SignalGeneratorTest : public ::testing::Test protected: void SetUp() override { - std::string unit_test_dir(FASTCAT_UNIT_TEST_DIR); - unit_test_dir += "test_signal_generator_yamls/"; + std::string unit_test_dir(FASTCAT_TEST_DIR); + unit_test_dir += "device_tests/test_signal_generator_yamls/"; sin_config_node = YAML::LoadFile(unit_test_dir + "sg1_config.yaml"); saw_config_node = YAML::LoadFile(unit_test_dir + "sg2_config.yaml"); sg3_.ConfigFromYaml(YAML::LoadFile(unit_test_dir + "sg3_config.yaml")); diff --git a/test/test_unit/test_signal_generator_yamls/sg1_config.yaml b/test/device_tests/test_signal_generator_yamls/sg1_config.yaml similarity index 100% rename from test/test_unit/test_signal_generator_yamls/sg1_config.yaml rename to test/device_tests/test_signal_generator_yamls/sg1_config.yaml diff --git a/test/test_unit/test_signal_generator_yamls/sg2_config.yaml b/test/device_tests/test_signal_generator_yamls/sg2_config.yaml similarity index 100% rename from test/test_unit/test_signal_generator_yamls/sg2_config.yaml rename to test/device_tests/test_signal_generator_yamls/sg2_config.yaml diff --git a/test/test_unit/test_signal_generator_yamls/sg3_config.yaml b/test/device_tests/test_signal_generator_yamls/sg3_config.yaml similarity index 100% rename from test/test_unit/test_signal_generator_yamls/sg3_config.yaml rename to test/device_tests/test_signal_generator_yamls/sg3_config.yaml diff --git a/test/test_unit/test_signal_generator_yamls/sg4_config.yaml b/test/device_tests/test_signal_generator_yamls/sg4_config.yaml similarity index 100% rename from test/test_unit/test_signal_generator_yamls/sg4_config.yaml rename to test/device_tests/test_signal_generator_yamls/sg4_config.yaml diff --git a/test/test_unit/test_virtual_fts.cc b/test/device_tests/test_virtual_fts.cc similarity index 88% rename from test/test_unit/test_virtual_fts.cc rename to test/device_tests/test_virtual_fts.cc index 3ce2dbb..d32c7b7 100644 --- a/test/test_unit/test_virtual_fts.cc +++ b/test/device_tests/test_virtual_fts.cc @@ -12,9 +12,8 @@ class VirtualFtsTest : public ::testing::Test protected: void SetUp() override { - // FASTCAT_UNIT_TEST_DIR contains path to . - base_dir_ = FASTCAT_UNIT_TEST_DIR; - base_dir_ += "test_virtual_fts_yamls/"; + base_dir_ = FASTCAT_TEST_DIR; + base_dir_ += "device_tests/test_virtual_fts_yamls/"; } std::string base_dir_; diff --git a/test/test_unit/test_virtual_fts_yamls/nominal.yaml b/test/device_tests/test_virtual_fts_yamls/nominal.yaml similarity index 100% rename from test/test_unit/test_virtual_fts_yamls/nominal.yaml rename to test/device_tests/test_virtual_fts_yamls/nominal.yaml diff --git a/test/test_unit/test_yaml_parser.cc b/test/device_tests/test_yaml_parser.cc similarity index 96% rename from test/test_unit/test_yaml_parser.cc rename to test/device_tests/test_yaml_parser.cc index 871a84e..b03253c 100644 --- a/test/test_unit/test_yaml_parser.cc +++ b/test/device_tests/test_yaml_parser.cc @@ -10,9 +10,10 @@ class YamlParserTest : public ::testing::Test protected: void SetUp() override { - std::string unit_test_dir(FASTCAT_UNIT_TEST_DIR); + std::string unit_test_dir(FASTCAT_TEST_DIR); + unit_test_dir += "device_tests/test_yaml_parser_yamls/"; parsable_node = YAML::LoadFile( - unit_test_dir + "test_yaml_parser_yamls/yaml_parser_config.yaml"); + unit_test_dir + "yaml_parser_config.yaml"); } YAML::Node parsable_node; YAML::Node empty_node; diff --git a/test/test_unit/test_yaml_parser_yamls/yaml_parser_config.yaml b/test/device_tests/test_yaml_parser_yamls/yaml_parser_config.yaml similarity index 100% rename from test/test_unit/test_yaml_parser_yamls/yaml_parser_config.yaml rename to test/device_tests/test_yaml_parser_yamls/yaml_parser_config.yaml diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt new file mode 100644 index 0000000..cefd81b --- /dev/null +++ b/test/unit_tests/CMakeLists.txt @@ -0,0 +1,33 @@ +find_package(Threads REQUIRED) + +set(TEST_SOURCES + test_transform_utils.cc + test_trap.cc + test_enum_conversions.cc + test_jsd_device_base.cc + ) + +foreach(TEST_SOURCE ${TEST_SOURCES}) + get_filename_component(TEST_EXECUTABLE ${TEST_SOURCE} NAME_WE) + message(STATUS ${TEST_EXECUTABLE}) + add_executable( + ${TEST_EXECUTABLE} + ${TEST_SOURCE} + ) + target_link_libraries( + ${TEST_EXECUTABLE} PRIVATE + ${GTEST_BOTH_LIBRARIES} + Threads::Threads + fastcat + ) + target_include_directories( + ${TEST_EXECUTABLE} PUBLIC + ${GTEST_INCLUDE_DIRS} + ) + add_test( + NAME ${TEST_EXECUTABLE} + COMMAND ${TEST_EXECUTABLE} + ) + +endforeach() + diff --git a/test/unit_tests/test_enum_conversions.cc b/test/unit_tests/test_enum_conversions.cc new file mode 100644 index 0000000..a7df42b --- /dev/null +++ b/test/unit_tests/test_enum_conversions.cc @@ -0,0 +1,10 @@ +#include +#include "fastcat/enum_conversions.h" + +TEST(EnumConversions, ConditionalOperatorType){ + + EXPECT_EQ(fastcat::BAD_CONDITIONAL_OPERATOR_TYPE, + fastcat::ConditionalOperatorTypeFromString("unknown")); + EXPECT_EQ(fastcat::LT, fastcat::ConditionalOperatorTypeFromString("<")); + EXPECT_EQ(fastcat::EQ, fastcat::ConditionalOperatorTypeFromString("==")); +} diff --git a/test/test_unit/test_jsd_device_base.cc b/test/unit_tests/test_jsd_device_base.cc similarity index 100% rename from test/test_unit/test_jsd_device_base.cc rename to test/unit_tests/test_jsd_device_base.cc diff --git a/test/test_unit/test_transform_utils.cc b/test/unit_tests/test_transform_utils.cc similarity index 100% rename from test/test_unit/test_transform_utils.cc rename to test/unit_tests/test_transform_utils.cc diff --git a/test/test_unit/test_trap.cc b/test/unit_tests/test_trap.cc similarity index 100% rename from test/test_unit/test_trap.cc rename to test/unit_tests/test_trap.cc From 08b91c66f61880c58e00757f086abd6b0242144e Mon Sep 17 00:00:00 2001 From: Alex Brinkman Date: Mon, 1 May 2023 15:30:59 -0700 Subject: [PATCH 2/6] AC working up to the JSD devices, need to define config input YAMLs for those next --- src/fcgen/templates/bak.txt | 28 +++ .../device_config_parsing_libyamlcpp.h.cog | 167 +++++++++++++++++- src/fcgen/templates/enum_conversions.h.cog | 92 +++++++--- src/fcgen/templates/signal_handling.cc.cog | 2 +- src/fcgen/templates/types.h.cog | 4 +- test/device_tests/test_commander.cc | 2 +- test/unit_tests/CMakeLists.txt | 1 + .../test_device_config_parsing_libyamlcpp.cc | 17 ++ test/unit_tests/test_enum_conversions.cc | 14 +- 9 files changed, 289 insertions(+), 38 deletions(-) create mode 100644 src/fcgen/templates/bak.txt create mode 100644 test/unit_tests/test_device_config_parsing_libyamlcpp.cc diff --git a/src/fcgen/templates/bak.txt b/src/fcgen/templates/bak.txt new file mode 100644 index 0000000..efe5f30 --- /dev/null +++ b/src/fcgen/templates/bak.txt @@ -0,0 +1,28 @@ +/* +[[[cog +for this_enum in enum_data['enumerations']: + + camel = snake2camel(this_enum['name']) + + cog.outl('template<>') + cog.outl('struct convert {' % camel) + cog.outl(' static Node encode(const fastcat::%s& /*cfg*/) {' % camel) + cog.outl(' Node node;') + + # TODO + cog.outl(' node.push_back("BAD_%s"); // TODO' % this_enum['name'].upper()) + + cog.outl(' return node;') + cog.outl(' }') + cog.outl('') + cog.outl(' static bool decode(const Node& node, fastcat::%s& cfg) {' % camel) + + cog.outl(' std::string s = node[0].as();') + cog.outl(' cfg = fastcat::%sFromString(s);' % camel) + + cog.outl(' return cfg != fastcat::BAD_%s;' % this_enum['name'].upper()) + cog.outl(' }') + cog.outl('};') + +]]] +[[[end]]] diff --git a/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog b/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog index 75da82f..6e07890 100644 --- a/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog +++ b/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog @@ -15,21 +15,178 @@ manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) cog.outl('// using the python cog tool. Do not modify this file manually.') + +native_types = ["double", + "bool", + "uint8_t", + "uint16_t", + "uint32_t", + "int8_t", + "int16_t", + "int32_t"] ]]] [[[end]]] + #include "fastcat/enum_conversions.h" +#include + +// Generate YAML template conversions using libyamlcpp extension class +namespace YAML { + +///////////////////////////// +// Enumerations +///////////////////////////// + +template<> +struct convert<::fastcat::DeviceType> { + static Node encode(const ::fastcat::DeviceType& /*cfg*/) { + Node node; + node.push_back("BAD_DEVICE_TYPE"); // TODO + return node; + } + + static bool decode(const Node& node, ::fastcat::DeviceType& cfg) { + const std::string& s = node.Scalar(); + cfg = ::fastcat::DeviceTypeFromString(s); + return cfg != ::fastcat::BAD_DEVICE_TYPE; + } +}; + +template<> +struct convert<::fastcat::DeviceCmdType> { + static Node encode(const ::fastcat::DeviceCmdType& /*cfg*/) { + Node node; + node.push_back("BAD_DEVICE_CMD_TYPE"); // TODO + return node; + } + + static bool decode(const Node& node, ::fastcat::DeviceCmdType& cfg) { + const std::string& s = node.Scalar(); + cfg = ::fastcat::DeviceCmdTypeFromString(s); + return cfg != ::fastcat::BAD_DEVICE_CMD_TYPE; + } +}; [[[cog for this_enum in enum_data['enumerations']: - cog.outl('enum %s {' % (snake2camel(this_enum['name']))) - for entry in this_enum['entries']: - cog.outl('%s,' % entry['value'].upper()) - cog.outl('BAD_%s' % this_enum['name'].upper()) + + camel = snake2camel(this_enum['name']) + + cog.outl('template<>') + cog.outl('struct convert<::fastcat::%s> {' % camel) + cog.outl(' static Node encode(const ::fastcat::%s& /*cfg*/) {' % camel) + cog.outl(' Node node;') + + # TODO + cog.outl(' node.push_back("BAD_%s"); // TODO' % this_enum['name'].upper()) + + cog.outl(' return node;') + cog.outl(' }') + cog.outl('') + cog.outl(' static bool decode(const Node& node, ::fastcat::%s& cfg) {' % camel) + + cog.outl(' const std::string& s = node.Scalar();') + cog.outl(' cfg = ::fastcat::%sFromString(s);' % camel) + + cog.outl(' return cfg != ::fastcat::BAD_%s;' % this_enum['name'].upper()) + cog.outl(' }') cog.outl('};') -]]] +]]] [[[end]]] + +///////////////////////////// +// Device Config +///////////////////////////// + +[[[cog +for device in device_data['devices']: + + if 'config' not in device: + cog.outl('// Config not yet defined for %s' % device['name']) + continue + + camel = snake2camel(device['name']) + + + cog.outl('template<>') + cog.outl('struct convert<::fastcat::%sConfig> {' % camel) + cog.outl(' static Node encode(const ::fastcat::%sConfig& cfg) {' % camel) + cog.outl(' Node node;') + + for field in device['config']: + cog.outl(' node["%s"] = cfg.%s;' % (field['name'], field['name'])) + + cog.outl(' return node;') + cog.outl(' }') + cog.outl('') + cog.outl(' static bool decode(const Node& node, ::fastcat::%sConfig& cfg) {' % camel) + + for field in device['config']: + if field['type'] in native_types or field['type'].startswith('std::'): + ns_type = field['type'] + else: + ns_type = "::fastcat::" + field['type'] + cog.outl(' cfg.%s = node["%s"].as<%s>();' % (field['name'], field['name'], ns_type)) + + cog.outl(' return true;') + cog.outl(' }') + cog.outl('};') + +]]] +[[[end]]] + +///////////////////////////// +// Device Config Variant +///////////////////////////// + +[[[cog +cog.outl('template<>') +cog.outl('struct convert<::fastcat::DeviceConfig> {') +cog.outl(' static Node encode(const ::fastcat::DeviceConfig& /*cfg*/) {') +cog.outl(' Node node;') +#cog.outl(' switch(cfg.type){'); +#for device in device_data['devices']: +# camel = snake2camel(device['name']) +# cog.outl(' ') +# +# cog.outl(' case ::fastcat::%s_DEVICE:' % device['name'].upper()) +# cog.outl(' node = std::get<::fastcat::%sConfig>(cfg.config_variant);' % camel) +# cog.outl(' node["device_class"] = "%s";' % camel) +# cog.outl(' break;') +#cog.outl(' };') +#cog.outl(' node["name"] = cfg.name;') +cog.outl(' return node;') +cog.outl(' }') +cog.outl('') +cog.outl(' static bool decode(const Node& node, ::fastcat::DeviceConfig& cfg) {') + +cog.outl(' cfg.name = node["name"].as();') +cog.outl(' std::string class_str = node["device_class"].as();'); +first_time = True +for device in device_data['devices']: + camel = snake2camel(device['name']) + if first_time: + first_time = False + cog.outl(' if (class_str.compare("%s") == 0) {' % camel) + else: + cog.outl(' } else if (class_str.compare("%s") == 0) {' % camel ) + + cog.outl(' cfg.type = ::fastcat::%s_DEVICE;' % (device['name'].upper())) + cog.outl(' cfg.config_variant = node.as<::fastcat::%sConfig>();' % camel) +cog.outl(' }') + + +cog.outl(' return true;') +cog.outl(' }') +cog.outl('};') +]]] +[[[end]]] + + +} // YAML namespace + #endif diff --git a/src/fcgen/templates/enum_conversions.h.cog b/src/fcgen/templates/enum_conversions.h.cog index 7f3fbe2..4e35a3b 100644 --- a/src/fcgen/templates/enum_conversions.h.cog +++ b/src/fcgen/templates/enum_conversions.h.cog @@ -15,52 +15,86 @@ manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) cog.outl('// using the python cog tool. Do not modify this file manually.') -]]] -[[[end]]] - -#include "fastcat/types.h" -#include "jsd/jsd_print.h" - -namespace fastcat { - -[[[cog -for this_enum in enum_data['enumerations']: +def createEnum(name, values, string_values=[]): cog.outl('%s %sFromString(const std::string& s){' % ( - snake2camel(this_enum['name']), - snake2camel(this_enum['name']))) - cog.outl('%s e = BAD_%s;' % ( - snake2camel(this_enum['name']), - this_enum['name'].upper() + snake2camel(name), + snake2camel(name))) + cog.outl(' %s e = BAD_%s;' % ( + snake2camel(name), + name.upper() )) - + first_entry = True - for entry in this_enum['entries']: - if 'string' in entry.keys(): - compare_str = entry['string'] - else: - compare_str = entry['value'] - + for (value, string_value) in zip(values, string_values): if first_entry: - cog.outl('if (s.compare("%s") == 0) {' % (compare_str)) first_entry = False + cog.outl(' if (s.compare("%s") == 0) {' % string_value) else: - cog.outl('} else if (s.compare("%s") == 0) {' % (compare_str)) + cog.outl(' } else if (s.compare("%s") == 0) {' % string_value) - cog.outl('e = %s;' % entry['value']) + cog.outl(' e = %s;' % value) - cog.outl('} else {') - cog.outl('ERROR("%s is not valid value for %s", s.c_str());' % ("%s", snake2camel(this_enum['name']))) + cog.outl(' } else {') + cog.outl(' ERROR("%s is not valid value for %s", s.c_str());' % ("%s", name)) - cog.outl('}') + cog.outl(' }') cog.outl('') - cog.outl('return e;') + cog.outl(' return e;') cog.outl('};') cog.outl('') ]]] [[[end]]] + +#include "fastcat/types.h" +#include "jsd/jsd_print.h" + +namespace fastcat { + + +////////////////////// +// Device Types +////////////////////// +[[[cog +entries = [] +for devices in device_data['devices']: + entries.append(devices['name'].upper() + "_DEVICE") +createEnum("device_type", entries, entries) +]]] +[[[end]]] + +////////////////////// +// Device Commands +////////////////////// +[[[cog +entries = [] +for cmds in cmd_data['commands']: + entries.append(cmds['name'].upper() + "_CMD") +createEnum("device_cmd_type", entries, entries) +]]] +[[[end]]] + +////////////////////// +// YAML-defined enums +////////////////////// + +[[[cog +for this_enum in enum_data['enumerations']: + entries = [] + string_entries = [] + for entry in this_enum['entries']: + entries.append(entry['value']) + if 'string' in entry.keys(): + string_entries.append(entry['string']) + else: + string_entries.append(entry['value']) + + createEnum(this_enum['name'], entries, string_entries) +]]] +[[[end]]] + }; // namespace fastcat #endif diff --git a/src/fcgen/templates/signal_handling.cc.cog b/src/fcgen/templates/signal_handling.cc.cog index 5456a00..c520d31 100644 --- a/src/fcgen/templates/signal_handling.cc.cog +++ b/src/fcgen/templates/signal_handling.cc.cog @@ -177,5 +177,5 @@ for cmd in cmd_data['commands']: ]]] [[[end]]] - return fastcat::BAD_DEVICE_CMD; + return fastcat::BAD_DEVICE_CMD_TYPE; } diff --git a/src/fcgen/templates/types.h.cog b/src/fcgen/templates/types.h.cog index 0202119..6b32c13 100644 --- a/src/fcgen/templates/types.h.cog +++ b/src/fcgen/templates/types.h.cog @@ -48,6 +48,7 @@ for device in device_data['devices']: cog.outl('%s_DEVICE,' % device['name'].upper()) ]]] [[[end]]] + BAD_DEVICE_TYPE }; @@ -60,7 +61,7 @@ for cmd in cmd_data['commands']: cog.outl('%s_CMD,' %cmd['name'].upper()) ]]] [[[end]]] - BAD_DEVICE_CMD + BAD_DEVICE_CMD_TYPE }; @@ -142,6 +143,7 @@ for device in device_data['devices']: typedef struct{ std::string name; + DeviceType type; DeviceConfigVariant config_variant; } DeviceConfig; diff --git a/test/device_tests/test_commander.cc b/test/device_tests/test_commander.cc index 550eb71..bf51b5a 100644 --- a/test/device_tests/test_commander.cc +++ b/test/device_tests/test_commander.cc @@ -70,7 +70,7 @@ TEST_F(CommanderTest, WriteInvalidCommand) // Write() returns false if the command sent is not valid for Commander // devices fastcat::DeviceCmd cmd; - cmd.type = fastcat::BAD_DEVICE_CMD; + cmd.type = fastcat::BAD_DEVICE_CMD_TYPE; EXPECT_FALSE(c2_.Write(cmd)); } diff --git a/test/unit_tests/CMakeLists.txt b/test/unit_tests/CMakeLists.txt index cefd81b..0a2704f 100644 --- a/test/unit_tests/CMakeLists.txt +++ b/test/unit_tests/CMakeLists.txt @@ -5,6 +5,7 @@ set(TEST_SOURCES test_trap.cc test_enum_conversions.cc test_jsd_device_base.cc + test_device_config_parsing_libyamlcpp.cc ) foreach(TEST_SOURCE ${TEST_SOURCES}) diff --git a/test/unit_tests/test_device_config_parsing_libyamlcpp.cc b/test/unit_tests/test_device_config_parsing_libyamlcpp.cc new file mode 100644 index 0000000..a7efce4 --- /dev/null +++ b/test/unit_tests/test_device_config_parsing_libyamlcpp.cc @@ -0,0 +1,17 @@ +#include +#include "fastcat/device_config_parsing_libyamlcpp.h" +#include "fastcat/config.h" + +TEST(device_config_parsing_libyamlcpp, ConditionalOperatorType){ + + std::string unit_test_dir(FASTCAT_TEST_DIR); + unit_test_dir += "device_tests/test_conditional_yamls/"; + auto config_node = YAML::LoadFile(unit_test_dir + "c1_config.yaml"); + + EXPECT_EQ(config_node["conditional_type"].as(), fastcat::GT); + + auto cfg = config_node.as(); + EXPECT_EQ(cfg.conditional_type, fastcat::GT); + EXPECT_DOUBLE_EQ(cfg.compare_rhs_value, 100.0); + +} diff --git a/test/unit_tests/test_enum_conversions.cc b/test/unit_tests/test_enum_conversions.cc index a7df42b..7bc10ab 100644 --- a/test/unit_tests/test_enum_conversions.cc +++ b/test/unit_tests/test_enum_conversions.cc @@ -2,9 +2,21 @@ #include "fastcat/enum_conversions.h" TEST(EnumConversions, ConditionalOperatorType){ - + MSG("The following error is expected"); EXPECT_EQ(fastcat::BAD_CONDITIONAL_OPERATOR_TYPE, fastcat::ConditionalOperatorTypeFromString("unknown")); EXPECT_EQ(fastcat::LT, fastcat::ConditionalOperatorTypeFromString("<")); EXPECT_EQ(fastcat::EQ, fastcat::ConditionalOperatorTypeFromString("==")); } + +TEST(EnumConversions, FilterType){ + MSG("The following error is expected"); + EXPECT_EQ(fastcat::BAD_FILTER_TYPE, fastcat::FilterTypeFromString("unknown")); + EXPECT_EQ(fastcat::DIGITAL_AB, fastcat::FilterTypeFromString("DIGITAL_AB")); +} + +TEST(EnumConversions, FunctionType){ + MSG("The following error is expected"); + EXPECT_EQ(fastcat::BAD_FUNCTION_TYPE, fastcat::FunctionTypeFromString("unknown")); + EXPECT_EQ(fastcat::SIGMOID, fastcat::FunctionTypeFromString("SIGMOID")); +} From bd811ddbe25424a5060274487aa7ddad2acd6af2 Mon Sep 17 00:00:00 2001 From: Alex Brinkman Date: Wed, 3 May 2023 16:50:32 -0700 Subject: [PATCH 3/6] few more mods for supporting parity enums with JSD --- src/fcgen/fastcat_devices.yaml | 19 +++++++++++++++ src/fcgen/fastcat_enums.yaml | 27 ++++++++++++++++++++++ src/fcgen/templates/enum_conversions.h.cog | 10 +++++--- src/fcgen/templates/types.h.cog | 9 +++++++- 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/src/fcgen/fastcat_devices.yaml b/src/fcgen/fastcat_devices.yaml index dc6ba48..0eed5fd 100644 --- a/src/fcgen/fastcat_devices.yaml +++ b/src/fcgen/fastcat_devices.yaml @@ -612,6 +612,25 @@ devices: type: double - name: adc_value_ch2 type: int32_t + config: + - name: range + type: El3602Range + - name: filter + type: BeckhoffFilter + default: BECKHOFF_FILTER_30000HZ + - name: limit1_enable + type: std::array + default: {false, false} + - name: limit1_voltage + type: std::array + default: {0, 0} + - name: limit2_enable + type: std::array + default: {false, false} + - name: limit2_voltage + type: std::array + default: {0, 0} + - name: el2124 type: jsd_device diff --git a/src/fcgen/fastcat_enums.yaml b/src/fcgen/fastcat_enums.yaml index 142ca2d..0a9320a 100644 --- a/src/fcgen/fastcat_enums.yaml +++ b/src/fcgen/fastcat_enums.yaml @@ -36,3 +36,30 @@ enumerations: - value: SAW_TOOTH - value: GAUSSIAN_RANDOM - value: UNIFORM_RANDOM + + + - name: beckhoff_filter + jsd_enum_alias: true + entries: + - value: BECKHOFF_FILTER_50HZ + - value: BECKHOFF_FILTER_60HZ + - value: BECKHOFF_FILTER_100HZ + - value: BECKHOFF_FILTER_500HZ + - value: BECKHOFF_FILTER_1000HZ + - value: BECKHOFF_FILTER_2000HZ + - value: BECKHOFF_FILTER_3750HZ + - value: BECKHOFF_FILTER_7500HZ + - value: BECKHOFF_FILTER_15000HZ + - value: BECKHOFF_FILTER_30000HZ + - value: BECKHOFF_FILTER_5HZ + - value: BECKHOFF_FILTER_10HZ + + - name: el3602_range + jsd_enum_alias: true + entries: + - value: EL3602_RANGE_10V + - value: EL3602_RANGE_5V + - value: EL3602_RANGE_2_5V + - value: EL3602_RANGE_1_25V + - value: EL3602_RANGE_75MV + - value: EL3602_RANGE_200MV \ No newline at end of file diff --git a/src/fcgen/templates/enum_conversions.h.cog b/src/fcgen/templates/enum_conversions.h.cog index 4e35a3b..cac84f2 100644 --- a/src/fcgen/templates/enum_conversions.h.cog +++ b/src/fcgen/templates/enum_conversions.h.cog @@ -16,7 +16,7 @@ manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) cog.outl('// using the python cog tool. Do not modify this file manually.') -def createEnum(name, values, string_values=[]): +def createEnum(name, values, string_values=[], is_jsd_enum_alias=False): cog.outl('%s %sFromString(const std::string& s){' % ( snake2camel(name), snake2camel(name))) @@ -83,7 +83,11 @@ createEnum("device_cmd_type", entries, entries) [[[cog for this_enum in enum_data['enumerations']: entries = [] - string_entries = [] + string_entries = [] + jsd_enum_alias = False + if 'jsd_enum_alias' in this_enum: + jsd_enum_alias = bool(this_enum['jsd_enum_alias']) + for entry in this_enum['entries']: entries.append(entry['value']) if 'string' in entry.keys(): @@ -91,7 +95,7 @@ for this_enum in enum_data['enumerations']: else: string_entries.append(entry['value']) - createEnum(this_enum['name'], entries, string_entries) + createEnum(this_enum['name'], entries, string_entries, jsd_enum_alias) ]]] [[[end]]] diff --git a/src/fcgen/templates/types.h.cog b/src/fcgen/templates/types.h.cog index 6b32c13..c308ca4 100644 --- a/src/fcgen/templates/types.h.cog +++ b/src/fcgen/templates/types.h.cog @@ -71,9 +71,16 @@ for cmd in cmd_data['commands']: ////////////////////////////////// [[[cog for this_enum in enum_data['enumerations']: + is_jsd_enum_alias = False + if 'jsd_enum_alias' in this_enum: + is_jsd_enum_alias = bool(this_enum['jsd_enum_alias']) + cog.outl('enum %s {' % (snake2camel(this_enum['name']))) for entry in this_enum['entries']: - cog.outl('%s,' % entry['value'].upper()) + if is_jsd_enum_alias: + cog.outl('%s = JSD_%s,' % (entry['value'].upper(), entry['value'].upper())) + else: + cog.outl('%s,' % entry['value'].upper()) cog.outl('BAD_%s' % this_enum['name'].upper()) cog.outl('};') ]]] From 5a59490fae3b9acf003158086ff2192aaabbabe3 Mon Sep 17 00:00:00 2001 From: Alex Brinkman Date: Wed, 10 May 2023 08:33:31 -0700 Subject: [PATCH 4/6] added yaml defs for simple JSD devices, elmos still remain --- src/fcgen/fastcat_devices.yaml | 50 ++++++++++++++ src/fcgen/fastcat_enums.yaml | 121 ++++++++++++++++++++++++++++++++- test/CMakeLists.txt | 9 ++- 3 files changed, 176 insertions(+), 4 deletions(-) diff --git a/src/fcgen/fastcat_devices.yaml b/src/fcgen/fastcat_devices.yaml index 0eed5fd..d1f908b 100644 --- a/src/fcgen/fastcat_devices.yaml +++ b/src/fcgen/fastcat_devices.yaml @@ -654,6 +654,19 @@ devices: - name: el3208 type: jsd_device + config: + - name: element + type: std::array + - name: filter + type: std::array + default: {BECKHOFF_FILTER_30000HZ} + - name: connection + type: std::array + - name: wire_resistance + type: std:array + - name: presentation + type: std:array + default: {EL3208_PRESENTATION_SIGNED} state: - name: output_ch1 type: double @@ -722,6 +735,19 @@ devices: - name: el3202 type: jsd_device + config: + - name: element + type: std::array + - name: filter + type: std::array + default: {BECKHOFF_FILTER_30000HZ} + - name: connection + type: std::array + - name: wire_resistance + type: std:array + - name: presentation + type: std:array + default: {EL3202_PRESENTATION_SIGNED} state: - name: output_eu_ch1 type: double @@ -734,6 +760,15 @@ devices: - name: el3318 type: jsd_device + config: + - name: element + type: std::array + - name: filter + type: std::array + default: {BECKHOFF_FILTER_30000HZ} + - name: presentation + type: std:array + default: {EL3318_PRESENTATION_SIGNED} state: - name: output_eu_ch1 type: double @@ -770,6 +805,21 @@ devices: - name: ild1900 type: jsd_device + config: + - name: measuring_rate + type: double + - name: averaging_number + type: uint32_t + - name: averaging_type + type: Ild1900Averaging + - name: model + type: Ild1900Model + - name: exposure_mode + type: Ild1900ExposureMode + default: ILD1900_EXPOSURE_MODE_STANDARD + - name: peak_selection + type: Ild1900PeakSelection + default: ILD1900_PEAK_SELECTION_HIGHEST state: - name: distance_m type: double diff --git a/src/fcgen/fastcat_enums.yaml b/src/fcgen/fastcat_enums.yaml index 0a9320a..0852c90 100644 --- a/src/fcgen/fastcat_enums.yaml +++ b/src/fcgen/fastcat_enums.yaml @@ -62,4 +62,123 @@ enumerations: - value: EL3602_RANGE_2_5V - value: EL3602_RANGE_1_25V - value: EL3602_RANGE_75MV - - value: EL3602_RANGE_200MV \ No newline at end of file + - value: EL3602_RANGE_200MV + + - name: el3208_element + jsd_enum_alias: true + entries: + - value: EL3208_ELEMENT_PT100 + - value: EL3208_ELEMENT_NI100 + - value: EL3208_ELEMENT_PT1000 + - value: EL3208_ELEMENT_PT500 + - value: EL3208_ELEMENT_PT200 + - value: EL3208_ELEMENT_NI1000 + - value: EL3208_ELEMENT_NI1000_TK1500 + - value: EL3208_ELEMENT_NI120 + - value: EL3208_ELEMENT_OHMS4096 + - value: EL3208_ELEMENT_OHMS1024 + - value: EL3208_ELEMENT_KT100_ET_AL + + - name: el3208_connection + jsd_enum_alias: true + entries: + - value: EL3208_CONNECTION_2WIRE + - value: EL3208_CONNECTION_3WIRE + - value: EL3208_CONNECTION_4WIRE + - value: EL3208_CONNECTION_NOT_CONNECTED + + - name: el3208_presentation + jsd_enum_alias: true + entries: + - value: EL3208_PRESENTATION_SIGNED + - value: EL3208_PRESENTATION_HIGH_RES + + + - name: el3202_element + jsd_enum_alias: true + entries: + - value: EL3202_ELEMENT_PT100 + - value: EL3202_ELEMENT_NI100 + - value: EL3202_ELEMENT_PT1000 + - value: EL3202_ELEMENT_PT500 + - value: EL3202_ELEMENT_PT200 + - value: EL3202_ELEMENT_NI1000 + - value: EL3202_ELEMENT_NI1000_TK1500 + - value: EL3202_ELEMENT_NI120 + - value: EL3202_ELEMENT_OHMS4096 + - value: EL3202_ELEMENT_OHMS1024 + - value: EL3202_ELEMENT_KT100_ET_AL + + - name: el3202_connection + jsd_enum_alias: true + entries: + - value: EL3202_CONNECTION_2WIRE + - value: EL3202_CONNECTION_3WIRE + - value: EL3202_CONNECTION_4WIRE + - value: EL3202_CONNECTION_NOT_CONNECTED + + - name: el3202_presentation + jsd_enum_alias: true + entries: + - value: EL3202_PRESENTATION_SIGNED + - value: EL3202_PRESENTATION_HIGH_RES + + + - name: el3318_element + jsd_enum_alias: true + entries: + - value: EL3318_ELEMENT_TYPE_K + - value: EL3318_ELEMENT_TYPE_J + - value: EL3318_ELEMENT_TYPE_L + - value: EL3318_ELEMENT_TYPE_E + - value: EL3318_ELEMENT_TYPE_T + - value: EL3318_ELEMENT_TYPE_N + - value: EL3318_ELEMENT_TYPE_U + - value: EL3318_ELEMENT_TYPE_B + - value: EL3318_ELEMENT_TYPE_R + - value: EL3318_ELEMENT_TYPE_S + - value: EL3318_ELEMENT_TYPE_C + + - name: el3318_presentation + jsd_enum_alias: true + entries: + - value: EL3318_PRESENTATION_SIGNED + - value: EL3318_PRESENTATION_HIGH_RES + + - name: ild1900_model + jsd_enum_alias: true + entries: + - value: ILD1900_MODEL_2 + - value: ILD1900_MODEL_10 + - value: ILD1900_MODEL_25 + - value: ILD1900_MODEL_50 + - value: ILD1900_MODEL_100 + - value: ILD1900_MODEL_200 + - value: ILD1900_MODEL_500 + - value: ILD1900_MODEL_2LL + - value: ILD1900_MODEL_6LL + - value: ILD1900_MODEL_10LL + - value: ILD1900_MODEL_25LL + - value: ILD1900_MODEL_50LL + + - name: ild1900_exposure + jsd_enum_alias: true + entries: + - value: ILD1900_EXPOSURE_MODE_STANDARD + - value: ILD1900_EXPOSURE_MODE_INTELLIGENT + - value: ILD1900_EXPOSURE_MODE_BACKGROUND + + - name: ild1900_peak_selection + jsd_enum_alias: true + entries: + - value: ILD1900_PEAK_SELECTION_HIGHEST + - value: ILD1900_PEAK_SELECTION_WIDEST + - value: ILD1900_PEAK_SELECTION_LAST + - value: ILD1900_PEAK_SELECTION_FIRST + + - name: ild1900_averaging + jsd_enum_alias: true + entries: + - value: ILD1900_AVERAGING_NONE + - value: ILD1900_AVERAGING_MOVING + - value: ILD1900_AVERAGING_RECURSIVE diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b109089..136b7f3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,14 +12,17 @@ include_directories( set(fastcat_test_libs fastcat m - -lreadline ) add_executable(test_config test_config.cc) target_link_libraries(test_config ${fastcat_test_libs}) -add_executable(test_cli test_cli.cc) -target_link_libraries(test_cli ${fastcat_test_libs}) +if(READLINE_FOUND) + add_executable(test_cli test_cli.cc) + target_link_libraries(test_cli ${fastcat_test_libs}) +else() + message("readline not found, not building test_cli executable") +endif() find_package(GTest) if(GTEST_FOUND) From 9f3116118bb75dc6dc8be7540fc0dc683953fcaa Mon Sep 17 00:00:00 2001 From: Alex Brinkman Date: Wed, 10 May 2023 10:47:24 -0700 Subject: [PATCH 5/6] wip, added config enums and structs for actuator types --- src/fcgen/fastcat_devices.yaml | 186 +++++++++++++++++++++++++++++++++ src/fcgen/fastcat_enums.yaml | 26 +++++ 2 files changed, 212 insertions(+) diff --git a/src/fcgen/fastcat_devices.yaml b/src/fcgen/fastcat_devices.yaml index d1f908b..e607b78 100644 --- a/src/fcgen/fastcat_devices.yaml +++ b/src/fcgen/fastcat_devices.yaml @@ -399,6 +399,74 @@ devices: - name: gold_actuator type: jsd_device + config: + - name: actuator_type + type: ActuatorType + - name: gear_ratio + type: double + - name: counts_per_rev + type: double + - name: max_speed_eu_per_sec + type: double + - name: max_accel_eu_per_sec2 + type: double + - name: over_speed_multiplier + type: double + default: 2.0 + - name: vel_tracking_error_eu_per_sec + type: double + - name: pos_tracking_error_eu + type: double + - name: peak_current_limit_amps + type: double + - name: peak_current_time_sec + type: double + - name: continuous_current_limit_amps + type: double + - name: torque_slope_amps_per_sec + type: double + - name: low_pos_cal_limit_eu + type: double + - name: low_pos_cmd_limit_eu + type: double + - name: high_pos_cal_limit_eu + type: double + - name: high_pos_cmd_limit_eu + type: double + - name: holding_duration_sec + type: double + - name: elmo_brake_engage_msec + type: int32_t + - name: elmo_brake_disengage_msec + type: int32_t + - name: elmo_crc + type: int32_t + - name: elmo_drive_max_current_limit + type: double + - name: smooth_factor + type: int32_t + default: 0 + - name: ctrl_gain_scheduling_mode: + type: ElmoGainSchedulingMode + default: ELMO_GAIN_SCHEDULING_MODE_PRELOADED + - name: absolute_encoder + type: bool + default: false + - name: prof_pos_hold + type: bool + default: false + - name: torque_constant + type: double + default: NAN + - name: winding_resistance + type: double + default: NAN + - name: brake_power + type: double + default: 0 + - name: motor_encoder_gear_ratio + type: double + default: 1 state: - name: actual_position type: double @@ -455,6 +523,65 @@ devices: - name: platinum_actuator type: jsd_device + config: + - name: actuator_type + type: ActuatorType + - name: gear_ratio + type: double + - name: counts_per_rev + type: double + - name: max_speed_eu_per_sec + type: double + - name: max_accel_eu_per_sec2 + type: double + - name: over_speed_multiplier + type: double + default: 2.0 + - name: vel_tracking_error_eu_per_sec + type: double + - name: pos_tracking_error_eu + type: double + - name: peak_current_limit_amps + type: double + - name: peak_current_time_sec + type: double + - name: continuous_current_limit_amps + type: double + - name: torque_slope_amps_per_sec + type: double + - name: low_pos_cal_limit_eu + type: double + - name: low_pos_cmd_limit_eu + type: double + - name: high_pos_cal_limit_eu + type: double + - name: high_pos_cmd_limit_eu + type: double + - name: holding_duration_sec + type: double + - name: elmo_brake_engage_msec + type: int32_t + - name: elmo_brake_disengage_msec + type: int32_t + - name: elmo_crc + type: int32_t + - name: elmo_drive_max_current_limit + type: double + - name: smooth_factor + type: int32_t + default: 0 + - name: torque_constant + type: double + default: NAN + - name: winding_resistance + type: double + default: NAN + - name: brake_power + type: double + default: 0 + - name: motor_encoder_gear_ratio + type: double + default: 1 state: - name: actual_position type: double @@ -522,6 +649,65 @@ devices: - name: egd type: jsd_device + config: + - name: drive_cmd_mode + type: EgdDriveCmdMode + - name: max_motor_speed + type: double + - name: torque_slope + type: double + - name: max_profile_accel + type: uint32_t + - name: max_profile_decel + type: uint32_t + - name: velocity_tracking_error + type: int32_t + - name: position_tracking_error + type: int32_t + - name: peak_current_limit + type: float + - name: peak_current_time + type: float + - name: continuous_current_limit + type: float + - name: motor_stuck_current_level_pct + type: float + default: 0 + comment: The default value of zero disables the motor stuck feature + - name: motor_stuck_velocity_threshold + type: float + default: 0 + - name: motor_stuck_timeout + type: float + default: 3.0 + - name: over_speed_threshold + type: int32_t + default: 0 + comment: The default value of zero disables over speed faults + - name: low_position_limit + type: int32_t + default: 0 + comment: The default value of zero disables the low position limit + - name: high_position_limit + type: int32_t + default: 0 + comment: The default value of zero disables the high position limit + - name: brake_engage_msec + type: int32_t + default: 0 + - name: brake_disengage_msec + type: int32_t + default: 0 + - name: crc + type: int32_t + - name: drive_max_current_limit + type: float + - name: smooth_factor + type: int32_t + default: 0 + - name: ctrl_gain_scheduling_mode + type: ElmoGainSchedulingMode + default: ELMO_GAIN_SCHEDULING_MODE_PRELOADED state: - name: actual_position type: int32_t diff --git a/src/fcgen/fastcat_enums.yaml b/src/fcgen/fastcat_enums.yaml index 0852c90..65ca246 100644 --- a/src/fcgen/fastcat_enums.yaml +++ b/src/fcgen/fastcat_enums.yaml @@ -16,6 +16,13 @@ enumerations: - string: "!=" value: NE + - name: actuator_type + entries: + - string: "revolute" + value: REVOLUTE + - string: "prismatic" + value: PRISMATIC + - name: filter_type entries: - value: DIGITAL_AB @@ -182,3 +189,22 @@ enumerations: - value: ILD1900_AVERAGING_NONE - value: ILD1900_AVERAGING_MOVING - value: ILD1900_AVERAGING_RECURSIVE + + - name: egd_drive_cmd_mode + jsd_enum_alias: true + entries: + - value: EGD_DRIVE_CMD_MODE_PROFILED + - value: EGD_DRIVE_CMD_MODE_CS + + - name: elmo_gain_scheduling_mode + jsd_enum_alias: true + entries: + - value: ELMO_GAIN_SCHEDULING_MODE_PRELOADED + - value: ELMO_GAIN_SCHEDULING_MODE_DISABLED + - value: ELMO_GAIN_SCHEDULING_MODE_SPEED + - value: ELMO_GAIN_SCHEDULING_MODE_POSITION + - value: ELMO_GAIN_SCHEDULING_MODE_SETTLING + - value: ELMO_GAIN_SCHEDULING_MODE_MANUAL_LOW + - value: ELMO_GAIN_SCHEDULING_MODE_MANUAL_HIGH + + From 9a40e6f17fe2ad0767a305c898bf0ec298df2520 Mon Sep 17 00:00:00 2001 From: Alex Brinkman Date: Wed, 10 May 2023 13:40:36 -0700 Subject: [PATCH 6/6] fixed autocoder issues with handling std arrays and vectors --- src/fcgen/fastcat_devices.yaml | 92 +++++++++---------- src/fcgen/fastcat_enums.yaml | 6 +- .../device_config_parsing_libyamlcpp.h.cog | 57 +++++++++--- src/jsd/actuator.h | 5 - 4 files changed, 92 insertions(+), 68 deletions(-) diff --git a/src/fcgen/fastcat_devices.yaml b/src/fcgen/fastcat_devices.yaml index e607b78..4ab5e87 100644 --- a/src/fcgen/fastcat_devices.yaml +++ b/src/fcgen/fastcat_devices.yaml @@ -446,7 +446,7 @@ devices: - name: smooth_factor type: int32_t default: 0 - - name: ctrl_gain_scheduling_mode: + - name: ctrl_gain_scheduling_mode type: ElmoGainSchedulingMode default: ELMO_GAIN_SCHEDULING_MODE_PRELOADED - name: absolute_encoder @@ -849,9 +849,9 @@ devices: - name: connection type: std::array - name: wire_resistance - type: std:array + type: std::array - name: presentation - type: std:array + type: std::array default: {EL3208_PRESENTATION_SIGNED} state: - name: output_ch1 @@ -930,9 +930,9 @@ devices: - name: connection type: std::array - name: wire_resistance - type: std:array + type: std::array - name: presentation - type: std:array + type: std::array default: {EL3202_PRESENTATION_SIGNED} state: - name: output_eu_ch1 @@ -946,48 +946,48 @@ devices: - name: el3318 type: jsd_device - config: - - name: element - type: std::array - - name: filter - type: std::array - default: {BECKHOFF_FILTER_30000HZ} - - name: presentation - type: std:array - default: {EL3318_PRESENTATION_SIGNED} + config: + - name: element + type: std::array + - name: filter + type: std::array + default: {BECKHOFF_FILTER_30000HZ} + - name: presentation + type: std::array + default: {EL3318_PRESENTATION_SIGNED} state: - - name: output_eu_ch1 - type: double - - name: adc_value_ch1 - type: int16_t - - name: output_eu_ch2 - type: double - - name: adc_value_ch2 - type: int16_t - - name: output_eu_ch3 - type: double - - name: adc_value_ch3 - type: int16_t - - name: output_eu_ch4 - type: double - - name: adc_value_ch4 - type: int16_t - - name: output_eu_ch5 - type: double - - name: adc_value_ch5 - type: int16_t - - name: output_eu_ch6 - type: double - - name: adc_value_ch6 - type: int16_t - - name: output_eu_ch7 - type: double - - name: adc_value_ch7 - type: int16_t - - name: output_eu_ch8 - type: double - - name: adc_value_ch8 - type: int16_t + - name: output_eu_ch1 + type: double + - name: adc_value_ch1 + type: int16_t + - name: output_eu_ch2 + type: double + - name: adc_value_ch2 + type: int16_t + - name: output_eu_ch3 + type: double + - name: adc_value_ch3 + type: int16_t + - name: output_eu_ch4 + type: double + - name: adc_value_ch4 + type: int16_t + - name: output_eu_ch5 + type: double + - name: adc_value_ch5 + type: int16_t + - name: output_eu_ch6 + type: double + - name: adc_value_ch6 + type: int16_t + - name: output_eu_ch7 + type: double + - name: adc_value_ch7 + type: int16_t + - name: output_eu_ch8 + type: double + - name: adc_value_ch8 + type: int16_t - name: ild1900 type: jsd_device diff --git a/src/fcgen/fastcat_enums.yaml b/src/fcgen/fastcat_enums.yaml index 65ca246..5f422b6 100644 --- a/src/fcgen/fastcat_enums.yaml +++ b/src/fcgen/fastcat_enums.yaml @@ -19,9 +19,9 @@ enumerations: - name: actuator_type entries: - string: "revolute" - value: REVOLUTE + value: ACTUATOR_TYPE_REVOLUTE - string: "prismatic" - value: PRISMATIC + value: ACTUATOR_TYPE_PRISMATIC - name: filter_type entries: @@ -168,7 +168,7 @@ enumerations: - value: ILD1900_MODEL_25LL - value: ILD1900_MODEL_50LL - - name: ild1900_exposure + - name: ild1900_exposure_mode jsd_enum_alias: true entries: - value: ILD1900_EXPOSURE_MODE_STANDARD diff --git a/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog b/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog index 6e07890..2c80121 100644 --- a/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog +++ b/src/fcgen/templates/device_config_parsing_libyamlcpp.h.cog @@ -4,6 +4,7 @@ [[[cog import yaml import re +import parse def snake2camel(str): return ''.join(x.capitalize() or '_' for x in str.split('_')) @@ -16,7 +17,8 @@ manager_data = yaml.load(open(manager_yaml, 'r'), Loader=yaml.Loader) cog.outl('// This file is autogenerated from: %s' % cog_yaml_file) cog.outl('// using the python cog tool. Do not modify this file manually.') -native_types = ["double", +native_types = ["float", + "double", "bool", "uint8_t", "uint16_t", @@ -105,32 +107,59 @@ for this_enum in enum_data['enumerations']: [[[cog for device in device_data['devices']: - if 'config' not in device: - cog.outl('// Config not yet defined for %s' % device['name']) - continue - camel = snake2camel(device['name']) - cog.outl('template<>') cog.outl('struct convert<::fastcat::%sConfig> {' % camel) cog.outl(' static Node encode(const ::fastcat::%sConfig& cfg) {' % camel) cog.outl(' Node node;') - for field in device['config']: - cog.outl(' node["%s"] = cfg.%s;' % (field['name'], field['name'])) + if 'config' in device: + for field in device['config']: + cog.outl(' node["%s"] = cfg.%s;' % (field['name'], field['name'])) + else: + cog.outl(' // Config not defined for %s' % device['name']) cog.outl(' return node;') cog.outl(' }') cog.outl('') cog.outl(' static bool decode(const Node& node, ::fastcat::%sConfig& cfg) {' % camel) - for field in device['config']: - if field['type'] in native_types or field['type'].startswith('std::'): - ns_type = field['type'] - else: - ns_type = "::fastcat::" + field['type'] - cog.outl(' cfg.%s = node["%s"].as<%s>();' % (field['name'], field['name'], ns_type)) + if 'config' in device: + for field in device['config']: + if field['type'].startswith('std::array'): + + parsed_array = parse.parse('std::array<{type},{length}>', field['type']) + if parsed_array['type'] not in native_types: + qualified_type = "fastcat::" + parsed_array['type'].split(" ")[0] + else: + qualified_type = parsed_array['type'].split(" ")[0] + + cog.outl(' cfg.%s = node["%s"].as>();' % ( + field['name'], + field['name'], + qualified_type, + parsed_array['length'])) + + elif field['type'].startswith('std::vector'): + + parsed_vector = parse.parse('std::vector<{type}>', field['type']) + if parsed_vector['type'] not in native_types: + qualified_type = "fastcat::" + parsed_vector['type'].split(" ")[0] + else: + qualified_type = parsed_vector['type'] + + cog.outl(' cfg.%s = node["%s"].as>();' % ( + field['name'], + field['name'], + qualified_type)) + + elif field['type'] in native_types or field['type'].startswith('std::string'): + ns_type = field['type'] + cog.outl(' cfg.%s = node["%s"].as<%s>();' % (field['name'], field['name'], ns_type)) + else: + ns_type = "::fastcat::" + field['type'] + cog.outl(' cfg.%s = node["%s"].as<%s>();' % (field['name'], field['name'], ns_type)) cog.outl(' return true;') cog.outl(' }') diff --git a/src/jsd/actuator.h b/src/jsd/actuator.h index d4c4cfd..e2a2196 100644 --- a/src/jsd/actuator.h +++ b/src/jsd/actuator.h @@ -28,11 +28,6 @@ typedef enum { ACTUATOR_SMS_CAL_MOVE_TO_SOFTSTOP, } ActuatorStateMachineState; -typedef enum { - ACTUATOR_TYPE_REVOLUTE, - ACTUATOR_TYPE_PRISMATIC, -} ActuatorType; - typedef enum { ACTUATOR_FASTCAT_FAULT_OKAY = 0, // Faults that can occur in handling of new commands