From 9b48f8c15f4a71f2e6e66d0e5dfc2778db19a2bb Mon Sep 17 00:00:00 2001 From: David Kim Date: Mon, 20 Mar 2023 11:48:35 -0700 Subject: [PATCH 1/5] Added el6001 device skeleton --- CMakeLists.txt | 3 +- src/CMakeLists.txt | 1 + src/fcgen/fastcat_types.yaml | 7 +++++ src/jsd/el6001.cc | 53 ++++++++++++++++++++++++++++++++++++ src/jsd/el6001.h | 34 +++++++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 src/jsd/el6001.cc create mode 100644 src/jsd/el6001.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0770088..5b584de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,8 @@ find_package(YamlCpp REQUIRED 0.6.3) include(FetchContent) FetchContent_Declare(jsd GIT_REPOSITORY https://github.com/nasa-jpl/jsd.git - GIT_TAG v2.1.2 + #GIT_TAG v2.1.2 + GIT_TAG davkim-add-el6001 ) FetchContent_MakeAvailable(jsd) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32e91db..fe032ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,6 +78,7 @@ add_library(fastcat STATIC jsd/el3104.cc jsd/el3202.cc jsd/el3318.cc + jsd/el6001.cc jsd/ild1900.cc jsd/jed0101.cc jsd/jed0200.cc diff --git a/src/fcgen/fastcat_types.yaml b/src/fcgen/fastcat_types.yaml index 2f2d34a..ef5fa6a 100644 --- a/src/fcgen/fastcat_types.yaml +++ b/src/fcgen/fastcat_types.yaml @@ -368,6 +368,13 @@ states: - name: adc_value_ch8 type: int16_t + - name: el6001 + fields: + - name: statusword + type: uint16_t + - name: controlword + type: uint16_t + - name: ild1900 fields: - name: distance_m diff --git a/src/jsd/el6001.cc b/src/jsd/el6001.cc new file mode 100644 index 0000000..a375d64 --- /dev/null +++ b/src/jsd/el6001.cc @@ -0,0 +1,53 @@ +// Include related header (for cc files) +#include "fastcat/jsd/el6001.h" + +// Include c then c++ libraries +#include + +#include +#include + +// Include external then project includes +#include "fastcat/yaml_parser.h" + +fastcat::El6001::El6001() +{ + MSG_DEBUG("Constructed El6001"); + + state_ = std::make_shared(); + state_->type = EL6001_STATE; +} + +bool fastcat::El6001::ConfigFromYaml(YAML::Node node) +{ + bool retval = ConfigFromYamlCommon(node); + jsd_set_slave_config((jsd_t*)context_, slave_id_, jsd_slave_config_); + return retval; +} + +bool fastcat::El6001::ConfigFromYamlCommon(YAML::Node node) +{ + if (!ParseVal(node, "name", name_)) { + return false; + } + state_->name = name_; + + jsd_slave_config_.configuration_active = true; + jsd_slave_config_.product_code = JSD_EL6001_PRODUCT_CODE; + snprintf(jsd_slave_config_.name, JSD_NAME_LEN, "%s", name_.c_str()); + + return true; +} + +bool fastcat::El6001::Read() +{ + jsd_el6001_read((jsd_t*)context_, slave_id_); + + const jsd_el6001_state_t* jsd_state = + jsd_el6001_get_state((jsd_t*)context_, slave_id_); + + state_->el6001_state.statusword = jsd_state->statusword; + state_->el6001_state.controlword = jsd_state->controlword_user; + + return true; +} diff --git a/src/jsd/el6001.h b/src/jsd/el6001.h new file mode 100644 index 0000000..c63c658 --- /dev/null +++ b/src/jsd/el6001.h @@ -0,0 +1,34 @@ +#ifndef FASTCAT_EL6001_H_ +#define FASTCAT_EL6001_H_ + +// Include related header (for cc files) + +// Include c then c++ libraries + +// Include external then project includes +#include "fastcat/jsd/jsd_device_base.h" +#include "jsd/jsd_el6001_pub.h" + +namespace fastcat +{ +class El6001 : public JsdDeviceBase +{ + public: + El6001(); + bool ConfigFromYaml(YAML::Node node) override; + bool Read() override; + bool Write(DeviceCmd& cmd) override; + // FaultType Process() override; + // void Fault() override; + // void Reset() override; + + protected: + bool ConfigFromYamlCommon(YAML::Node node); + + private: + jsd_slave_config_t jsd_slave_config_{0}; +}; + +} // namespace fastcat + +#endif From 8ad125d619e31fc1d5368e1446d16d870c8c84c3 Mon Sep 17 00:00:00 2001 From: David Kim Date: Mon, 20 Mar 2023 14:01:37 -0700 Subject: [PATCH 2/5] Added write for el6001, and offline codes --- .gitignore | 1 + src/fcgen/fastcat_types.yaml | 11 +++++++++ src/jsd/el6001.cc | 32 ++++++++++++++++++++++++++ src/jsd/el6001_offline.cc | 44 ++++++++++++++++++++++++++++++++++++ src/jsd/el6001_offline.h | 24 ++++++++++++++++++++ 5 files changed, 112 insertions(+) create mode 100644 src/jsd/el6001_offline.cc create mode 100644 src/jsd/el6001_offline.h diff --git a/.gitignore b/.gitignore index 308fbe2..2ca3025 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ build externals bin .vscode +log # doxygen /doxygen_html diff --git a/src/fcgen/fastcat_types.yaml b/src/fcgen/fastcat_types.yaml index ef5fa6a..fd7effb 100644 --- a/src/fcgen/fastcat_types.yaml +++ b/src/fcgen/fastcat_types.yaml @@ -374,6 +374,10 @@ states: type: uint16_t - name: controlword type: uint16_t + - name: data_in_bytes[22] + type: uint8_t + - name: data_out_bytes[22] + type: uint8_t - name: ild1900 fields: @@ -595,6 +599,13 @@ commands: - name: voltage_output type: double + - name: el6001_write_data + fields: + - name: data_size + type: uint8_t + - name: data_out_bytes[22] + type: uint8_t + - name: el4102_write_all_channels fields: - name: voltage_output_ch1 diff --git a/src/jsd/el6001.cc b/src/jsd/el6001.cc index a375d64..f1d5ff9 100644 --- a/src/jsd/el6001.cc +++ b/src/jsd/el6001.cc @@ -32,6 +32,8 @@ bool fastcat::El6001::ConfigFromYamlCommon(YAML::Node node) } state_->name = name_; + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_115200; + jsd_slave_config_.configuration_active = true; jsd_slave_config_.product_code = JSD_EL6001_PRODUCT_CODE; snprintf(jsd_slave_config_.name, JSD_NAME_LEN, "%s", name_.c_str()); @@ -51,3 +53,33 @@ bool fastcat::El6001::Read() return true; } + +bool fastcat::El6001::Write(DeviceCmd& cmd) +{ + + // If device supports async SDO requests + AsyncSdoRetVal sdoResult = WriteAsyncSdoRequest(cmd); + if(sdoResult != SDO_RET_VAL_NOT_APPLICABLE){ + return (sdoResult == SDO_RET_VAL_SUCCESS); + } + + if (cmd.type == EL6001_WRITE_DATA_CMD) { + uint8_t data_size = cmd.el6001_write_data_cmd.data_size; + if (data_size > JSD_EL6001_NUM_DATA_BYTES) { + ERROR("Data size must be in range (0,%u)", JSD_EL6001_NUM_DATA_BYTES); + return false; + } + + for(int i =0; i < data_size; i++){ + jsd_el6001_set_transmit_data_8bits(context_, slave_id_, i, cmd.el6001_write_data_cmd.data_out_bytes[i]); + } + + jsd_el6001_request_transmit_data(context_, slave_id_, data_size); + } + else { + ERROR("Bad EL6001 command"); + return false; + } + + return true; +} \ No newline at end of file diff --git a/src/jsd/el6001_offline.cc b/src/jsd/el6001_offline.cc new file mode 100644 index 0000000..d323d4a --- /dev/null +++ b/src/jsd/el6001_offline.cc @@ -0,0 +1,44 @@ +// Include related header (for cc files) +#include "fastcat/jsd/el6001_offline.h" + +// Include c then c++ libraries + +// Include external then project includes + +bool fastcat::El6001Offline::ConfigFromYaml(YAML::Node node) +{ + return ConfigFromYamlCommon(node); +} + +bool fastcat::El6001Offline::Read() { return true; } + +fastcat::FaultType fastcat::El6001Offline::Process() +{ + return DeviceBase::Process(); +} + +bool fastcat::El4102Offline::Write(DeviceCmd& cmd) +{ + // If device supports async SDO requests + AsyncSdoRetVal sdoResult = WriteAsyncSdoRequest(cmd); + if(sdoResult != SDO_RET_VAL_NOT_APPLICABLE){ + return (sdoResult == SDO_RET_VAL_SUCCESS); + } + + if (cmd.type == EL6001_WRITE_DATA_CMD) { + uint8_t data_size = cmd.el6001_write_data_cmd.data_size; + if (data_size > JSD_EL6001_NUM_DATA_BYTES) { + ERROR("Data size must be in range (0,%u)", JSD_EL6001_NUM_DATA_BYTES); + return false; + } + + for(int i = 0; i < data_size; i++){ + state_->el6001_state.data_out_bytes[i] = cmd.el6001_write_data_cmd.data_out_bytes[i]; + } + + } else { + ERROR("Bad EL6001 Command"); + return false; + } + return true; +} diff --git a/src/jsd/el6001_offline.h b/src/jsd/el6001_offline.h new file mode 100644 index 0000000..b63a18d --- /dev/null +++ b/src/jsd/el6001_offline.h @@ -0,0 +1,24 @@ +#ifndef FASTCAT_EL4102_OFFLINE_H_ +#define FASTCAT_EL4102_OFFLINE_H_ + +// Include related header (for cc files) + +// Include c then c++ libraries + +// Include external then project includes +#include "fastcat/jsd/el4102.h" + +namespace fastcat +{ +class El4102Offline : public El4102 +{ + public: + bool ConfigFromYaml(YAML::Node node) override; + bool Read() override; + FaultType Process() override; + bool Write(DeviceCmd& cmd) override; +}; + +} // namespace fastcat + +#endif \ No newline at end of file From 416a85a5c4f5fea9dda7d3ad8df43b11082e72d9 Mon Sep 17 00:00:00 2001 From: David Kim Date: Mon, 20 Mar 2023 14:40:02 -0700 Subject: [PATCH 3/5] Added baud rate config loading --- src/jsd/el6001.cc | 41 +++++++++++++++++++++++++++++++++++++++-- src/jsd/el6001.h | 2 ++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/jsd/el6001.cc b/src/jsd/el6001.cc index f1d5ff9..b60bfa7 100644 --- a/src/jsd/el6001.cc +++ b/src/jsd/el6001.cc @@ -30,13 +30,50 @@ bool fastcat::El6001::ConfigFromYamlCommon(YAML::Node node) if (!ParseVal(node, "name", name_)) { return false; } + + if (!ParseVal(node, "baud_rate", baud_rate_)) { + return false; + } + state_->name = name_; - jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_115200; + switch(baud_rate_){ + case 2400: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_2400; + break; + case 4800: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_4800; + break; + case 9600: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_9600; + break; + case 19200: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_19200; + break; + case 38400: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_38400; + break; + case 57600: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_57600; + break; + case 115200: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_115200; + break; + case 12000: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_12000; + break; + case 14400: + jsd_slave_config_.el6001.baud_rate = JSD_EL6001_BAUD_RATE_14400; + break; + default: + ERROR("No matching baud rate for EL6001 device"); + return false; + break; + } jsd_slave_config_.configuration_active = true; jsd_slave_config_.product_code = JSD_EL6001_PRODUCT_CODE; - snprintf(jsd_slave_config_.name, JSD_NAME_LEN, "%s", name_.c_str()); + snprintf(jsd_slave_config_.name, JSD_NAME_LEN, "%s", name_.c_str()); return true; } diff --git a/src/jsd/el6001.h b/src/jsd/el6001.h index c63c658..8b4e780 100644 --- a/src/jsd/el6001.h +++ b/src/jsd/el6001.h @@ -25,6 +25,8 @@ class El6001 : public JsdDeviceBase protected: bool ConfigFromYamlCommon(YAML::Node node); + int baud_rate_; + private: jsd_slave_config_t jsd_slave_config_{0}; }; From cb3ebf83245365eb0e09bc0b460b829d1f4c96dd Mon Sep 17 00:00:00 2001 From: David Kim Date: Wed, 22 Mar 2023 13:25:24 -0700 Subject: [PATCH 4/5] Added offline, device process --- src/jsd/el6001.cc | 9 +++++++++ src/jsd/el6001.h | 2 +- src/jsd/el6001_offline.h | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/jsd/el6001.cc b/src/jsd/el6001.cc index b60bfa7..7d768be 100644 --- a/src/jsd/el6001.cc +++ b/src/jsd/el6001.cc @@ -119,4 +119,13 @@ bool fastcat::El6001::Write(DeviceCmd& cmd) } return true; +} + +fastcat::FaultType fastcat::El6001::Process() +{ + fastcat::FaultType retval = NO_FAULT; + + jsd_el6001_process(context_, slave_id); + + return retval; } \ No newline at end of file diff --git a/src/jsd/el6001.h b/src/jsd/el6001.h index 8b4e780..63c9f7f 100644 --- a/src/jsd/el6001.h +++ b/src/jsd/el6001.h @@ -18,7 +18,7 @@ class El6001 : public JsdDeviceBase bool ConfigFromYaml(YAML::Node node) override; bool Read() override; bool Write(DeviceCmd& cmd) override; - // FaultType Process() override; + FaultType Process() override; // void Fault() override; // void Reset() override; diff --git a/src/jsd/el6001_offline.h b/src/jsd/el6001_offline.h index b63a18d..439d8d2 100644 --- a/src/jsd/el6001_offline.h +++ b/src/jsd/el6001_offline.h @@ -1,16 +1,16 @@ -#ifndef FASTCAT_EL4102_OFFLINE_H_ -#define FASTCAT_EL4102_OFFLINE_H_ +#ifndef FASTCAT_EL6001_OFFLINE_H_ +#define FASTCAT_EL6001_OFFLINE_H_ // Include related header (for cc files) // Include c then c++ libraries // Include external then project includes -#include "fastcat/jsd/el4102.h" +#include "fastcat/jsd/el6001.h" namespace fastcat { -class El4102Offline : public El4102 +class El6001Offline : public El6001 { public: bool ConfigFromYaml(YAML::Node node) override; From ff69b5e6938c84767b6f68b723cbcb582b7eb8b1 Mon Sep 17 00:00:00 2001 From: David Kim Date: Wed, 29 Mar 2023 14:45:59 -0700 Subject: [PATCH 5/5] Populating more data in Read --- src/jsd/el6001.cc | 18 +++++++++++++++++- src/jsd/el6001.h | 2 ++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/jsd/el6001.cc b/src/jsd/el6001.cc index c011973..84bb1e2 100644 --- a/src/jsd/el6001.cc +++ b/src/jsd/el6001.cc @@ -35,6 +35,14 @@ bool fastcat::El6001::ConfigFromYamlCommon(YAML::Node node) return false; } + if (!ParseVal(node, "use_first_byte_as_packet_length", use_first_byte_as_packet_length_)) { + return false; + } + + if (!ParseVal(node, "use_last_byte_as_checksum", use_last_byte_as_checksum_)) { + return false; + } + state_->name = name_; switch(baud_rate_){ @@ -71,6 +79,9 @@ bool fastcat::El6001::ConfigFromYamlCommon(YAML::Node node) break; } + jsd_slave_config_.el6001.use_first_byte_as_packet_length = use_first_byte_as_packet_length_; + jsd_slave_config_.el6001.use_last_byte_as_checksum = use_last_byte_as_checksum_; + jsd_slave_config_.configuration_active = true; jsd_slave_config_.product_code = JSD_EL6001_PRODUCT_CODE; snprintf(jsd_slave_config_.name, JSD_NAME_LEN, "%s", name_.c_str()); @@ -86,7 +97,12 @@ bool fastcat::El6001::Read() jsd_el6001_get_state((jsd_t*)context_, slave_id_); state_->el6001_state.statusword = jsd_state->statusword; - state_->el6001_state.controlword = jsd_state->controlword_user; + state_->el6001_state.controlword = jsd_state->controlword_user; + + for(int i=0; i < JSD_EL6001_NUM_DATA_BYTES; i++){ + state_->el6001_state.data_in_bytes[i] = jsd_state->received_bytes[i]; + state_->el6001_state.data_out_bytes[i] = jsd_state->transmit_bytes[i]; + } return true; } diff --git a/src/jsd/el6001.h b/src/jsd/el6001.h index 63c9f7f..d6cb18a 100644 --- a/src/jsd/el6001.h +++ b/src/jsd/el6001.h @@ -26,6 +26,8 @@ class El6001 : public JsdDeviceBase bool ConfigFromYamlCommon(YAML::Node node); int baud_rate_; + bool use_first_byte_as_packet_length_; + bool use_last_byte_as_checksum_; private: jsd_slave_config_t jsd_slave_config_{0};