68 case Type::octet_string:
69 return "octet_string";
71 return "unknown type";
76 #define ENUM_CASE(name) case DataType::name: return #name;
86 ENUM_CASE(VISIBLE_STRING)
87 ENUM_CASE(OCTET_STRING)
88 ENUM_CASE(UNICODE_STRING)
89 ENUM_CASE(TIME_OF_DAY)
90 ENUM_CASE(TIME_DIFFERENCE)
100 ENUM_CASE(UNSIGNED56)
101 ENUM_CASE(UNSIGNED64)
102 ENUM_CASE(PDO_COMMUNICATION_PARAMETER)
103 ENUM_CASE(PDO_MAPPING)
104 ENUM_CASE(SDO_PARAMETER)
107 return "[Utils::data_type_to_string] Unknown type with id "+std::to_string(static_cast<uint16_t>(type));
130 case Type::octet_string:
132 ERROR(
"[Utils::get_type_size] Unknown type or type with variable size.");
139 case (uint16_t) DataType::BOOLEAN:
return Type::boolean;
140 case (uint16_t) DataType::INTEGER8:
return Type::int8;
141 case (uint16_t) DataType::INTEGER16:
return Type::int16;
142 case (uint16_t) DataType::INTEGER32:
return Type::int32;
143 case (uint16_t) DataType::UNSIGNED8:
return Type::uint8;
144 case (uint16_t) DataType::UNSIGNED16:
return Type::uint16;
145 case (uint16_t) DataType::UNSIGNED32:
return Type::uint32;
146 case (uint16_t) DataType::REAL32:
return Type::real32;
147 case (uint16_t) DataType::VISIBLE_STRING:
return Type::string;
148 case (uint16_t) DataType::OCTET_STRING:
return Type::octet_string;
154 case (uint16_t) DataType::REAL64:
return Type::real64;
157 case (uint16_t) DataType::INTEGER64:
return Type::int64;
158 case (uint16_t) DataType::UNSIGNED64:
return Type::uint64;
161 ERROR(
"[Utils::type_code_to_type] Data type "<<
data_type_to_string(static_cast<DataType>(code))<<
" not yet supported.");
162 return Type::invalid;
167 std::string out = str;
168 std::transform(out.begin(), out.end(), out.begin(), ::tolower);
169 std::replace(out.begin(), out.end(),
' ',
'_');
170 std::replace(out.begin(), out.end(),
'-',
'_');
176 return std::stoull(str,
nullptr, 16);
177 }
catch (
const std::invalid_argument& e ) {
178 ERROR(
"[Utils::hexstr_to_uint] Invalid argument: \""<<str<<
"\" ("<<e.what()<<
")");
180 }
catch (
const std::out_of_range& e ) {
181 ERROR(
"[Utils::hexstr_to_uint] Out of range: \""<<str<<
"\" ("<<e.what()<<
")");
188 return std::stoull(str,
nullptr, 10);
189 }
catch (
const std::invalid_argument& e ) {
190 ERROR(
"[Utils::decstr_to_uint] Invalid argument: \""<<str<<
"\" ("<<e.what()<<
")");
192 }
catch (
const std::out_of_range& e ) {
193 ERROR(
"[Utils::decstr_to_uint] Out of range: \""<<str<<
"\" ("<<e.what()<<
")");
200 return AccessType::read_only;
201 }
else if (str ==
"wo") {
202 return AccessType::write_only;
203 }
else if (str ==
"const") {
204 return AccessType::constant;
205 }
else if (str ==
"rw" || str ==
"rwr" || str ==
"rww") {
206 return AccessType::read_write;
208 ERROR(
"[Utils::str_to_access_type] Invalid access type string \""<<str<<
"\". Returning AccessType::read_write.")
209 return AccessType::read_write;
215 case AccessType::read_only:
return "ro";
216 case AccessType::write_only:
return "wo";
217 case AccessType::constant:
return "const";
218 case AccessType::read_write:
return "rw";
220 ERROR(
"[Utils::access_type_to_string] Unknown access type!");
221 return "unknown access type";
static std::string access_type_to_string(AccessType type)
Converts access types to a string.
static unsigned long long hexstr_to_uint(std::string str)
Converts a string containing a hexadecimal numer to unsigned.
static Type type_code_to_type(uint16_t code)
Maps type codes from an EDS file to a data type.
static std::string data_type_to_string(DataType type)
Converts CanOpen data types to a string.
static std::string escape(const std::string &str)
Converts entry names to lower case and replaces all spaces and '-' by underscores.
static AccessType string_to_access_type(std::string str)
Converts a string representation of AccessType from an EDS file to AccessType.
static std::string type_to_string(Type type)
Converts data types to a string.
static unsigned long long decstr_to_uint(std::string str)
Converts a string containing a decimal numer to unsigned.
static uint8_t get_type_size(Type type)
Returns the size of a data type in bytes.