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

Added real32 (Beckhoff float) and real64 (Beckhoff double) #132

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ size_t type2bytes(std::string type)
return 1;
} else if (type == "int16" || type == "uint16") {
return 2;
} else if (type == "int32" || type == "uint32") {
} else if (type == "int32" || type == "uint32" || type == "float" || type == "real32") {
return 4;
} else if (type == "int64" || type == "uint64") {
} else if (type == "int64" || type == "uint64" || type == "double" || type == "real64") {
return 8;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class EcPdoChannelManager
last_value = static_cast<double>(EC_READ_U64(domain_address));
} else if (data_type == "int64") {
last_value = static_cast<double>(EC_READ_S64(domain_address));
} else if (data_type == "real32" || data_type == "float") {
uint32_t raw = EC_READ_U32(domain_address);
float value = *(float *)&raw;
last_value = static_cast<double>(value);
} else if (data_type == "real64" || data_type == "double") {
uint64_t raw = EC_READ_U64(domain_address);
double value = *(double *)&raw;
last_value = static_cast<double>(value);
} else if (data_type == "bool") {
last_value = (EC_READ_U8(domain_address) & data_mask) ? 1 : 0;
} else {
Expand Down Expand Up @@ -92,6 +100,13 @@ class EcPdoChannelManager
EC_WRITE_U64(domain_address, static_cast<uint64_t>(value));
} else if (data_type == "int64") {
EC_WRITE_S64(domain_address, static_cast<int64_t>(value));
} else if (data_type == "real32" || data_type == "float") {
float f = (float)value;
uint32_t raw = *(uint32_t *)&f;
EC_WRITE_U32(domain_address, static_cast<uint32_t>(raw));
} else if (data_type == "real64" || data_type == "double") {
uint32_t raw = *(uint32_t *)&value;
EC_WRITE_U64(domain_address, static_cast<uint64_t>(raw));
} else {
buffer_ = EC_READ_U8(domain_address);
if (popcount(data_mask) == 1) {
Expand Down Expand Up @@ -192,9 +207,9 @@ class EcPdoChannelManager
return 8;
} else if (type == "int16" || type == "uint16") {
return 16;
} else if (type == "int32" || type == "uint32") {
} else if (type == "int32" || type == "uint32" || type == "float" || type == "real32") {
return 32;
} else if (type == "int64" || type == "uint64") {
} else if (type == "int64" || type == "uint64" || type == "double" || type == "real64") {
return 64;
} else if (type.find("bit") != std::string::npos) {
std::string n_bits = type.substr(type.find("bit") + 3);
Expand Down
18 changes: 13 additions & 5 deletions ethercat_interface/include/ethercat_interface/ec_sdo_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class SdoConfigEntry
EC_WRITE_U16(buffer, static_cast<uint16_t>(data));
} else if (data_type == "int16") {
EC_WRITE_S16(buffer, static_cast<int16_t>(data));
} else if (data_type == "uint32") {
} else if (data_type == "uint32" || data_type == "real32" || data_type == "float") {
EC_WRITE_U32(buffer, static_cast<uint32_t>(data));
} else if (data_type == "int32") {
EC_WRITE_S32(buffer, static_cast<int32_t>(data));
} else if (data_type == "uint64") {
} else if (data_type == "uint64" || data_type == "real64" || data_type == "double") {
EC_WRITE_U64(buffer, static_cast<uint64_t>(data));
} else if (data_type == "int64") {
EC_WRITE_S64(buffer, static_cast<int64_t>(data));
Expand Down Expand Up @@ -79,7 +79,15 @@ class SdoConfigEntry
}
// value
if (sdo_config["value"]) {
data = sdo_config["value"].as<int>();
if (data_type == "float" || data_type == "real32") {
float floatvalue = sdo_config["value"].as<float>();
data = *(int *)&floatvalue;
} else if (data_type == "double" || data_type == "real64") {
float doublevalue = sdo_config["value"].as<double>();
data = *(int *)&doublevalue;
} else {
data = sdo_config["value"].as<int>();
}
} else {
std::cerr << "sdo " << index << ": missing sdo value" << std::endl;
return false;
Expand All @@ -105,9 +113,9 @@ class SdoConfigEntry
return 1;
} else if (type == "int16" || type == "uint16") {
return 2;
} else if (type == "int32" || type == "uint32") {
} else if (type == "int32" || type == "uint32" || type == "float" || type == "real32") {
return 4;
} else if (type == "int64" || type == "uint64") {
} else if (type == "int64" || type == "uint64" || type == "double" || type == "real64") {
return 8;
}
}
Expand Down