Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding EL6001 fastcat device library #90

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.0
#GIT_TAG v2.1.2
GIT_TAG davkim-add-el6001
Comment on lines +57 to +58
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be addressed before we can conclude this merge.

)
FetchContent_MakeAvailable(jsd)

Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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
Expand Down
18 changes: 18 additions & 0 deletions src/fcgen/fastcat_types.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,17 @@ states:
- name: adc_value_ch8
type: int16_t

- name: el6001
fields:
- name: statusword
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:
- name: distance_m
Expand Down Expand Up @@ -652,6 +663,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
Expand Down
147 changes: 147 additions & 0 deletions src/jsd/el6001.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// Include related header (for cc files)
#include "fastcat/jsd/el6001.h"

// Include c then c++ libraries
#include <string.h>

#include <cmath>
#include <iostream>

// Include external then project includes
#include "fastcat/yaml_parser.h"

fastcat::El6001::El6001()
{
MSG_DEBUG("Constructed El6001");

state_ = std::make_shared<DeviceState>();
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;
}

if (!ParseVal(node, "baud_rate", baud_rate_)) {
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_){
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_.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());

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;

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;
}

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;
}

fastcat::FaultType fastcat::El6001::Process()
{
fastcat::FaultType retval = NO_FAULT;

jsd_el6001_process(context_, slave_id_);

return retval;
}
38 changes: 38 additions & 0 deletions src/jsd/el6001.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#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);

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};
};

} // namespace fastcat

#endif
44 changes: 44 additions & 0 deletions src/jsd/el6001_offline.cc
Original file line number Diff line number Diff line change
@@ -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;
}
24 changes: 24 additions & 0 deletions src/jsd/el6001_offline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#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/el6001.h"

namespace fastcat
{
class El6001Offline : public El6001
{
public:
bool ConfigFromYaml(YAML::Node node) override;
bool Read() override;
FaultType Process() override;
bool Write(DeviceCmd& cmd) override;
};

} // namespace fastcat

#endif