-
Notifications
You must be signed in to change notification settings - Fork 11
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
davidinkyu-kim
wants to merge
8
commits into
master
Choose a base branch
from
davkim-add-el6001
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9b48f8c
Added el6001 device skeleton
davidinkyu-kim 8ad125d
Added write for el6001, and offline codes
davidinkyu-kim 416a85a
Added baud rate config loading
davidinkyu-kim cb3ebf8
Added offline, device process
davidinkyu-kim 610ec78
Merge branch 'master' into davkim-add-el6001
davidinkyu-kim 440dc51
Merged recent master to be up-to-date
davidinkyu-kim ff69b5e
Populating more data in Read
davidinkyu-kim 10b0d03
Merge branch 'master' into davkim-add-el6001
davidinkyu-kim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.