Skip to content
Merged
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set(AGENT_VERSION_MAJOR 2)
set(AGENT_VERSION_MINOR 5)
set(AGENT_VERSION_PATCH 0)
set(AGENT_VERSION_BUILD 2)
set(AGENT_VERSION_BUILD 3)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
32 changes: 23 additions & 9 deletions src/mtconnect/device_model/data_item/unit_conversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,31 @@ namespace mtconnect::device_model::data_item {

factor = sscale / tscale;

key = source;
key = key.append("-").append(target);
vector<string> sunits;
boost::split(sunits, source, boost::is_any_of("_"));

const auto &conversion = m_conversions.find(string(key));
// Check for no support units and not power or factor scaling.
if (conversion == m_conversions.end() && factor == 1.0)
return nullptr;
else if (conversion != m_conversions.end())
vector<string> tunits;
boost::split(tunits, target, boost::is_any_of("_"));

if (sunits.size() == tunits.size())
{
factor *= conversion->second.factor();
offset = conversion->second.offset();
for (auto si = sunits.begin(), ti = tunits.begin();
si != sunits.end() && ti != tunits.end(); si++, ti++)
{
key = *si;
key = key.append("-").append(*ti);

const auto &conversion = m_conversions.find(string(key));

// Check for no support units and not power or factor scaling.
if (conversion == m_conversions.end() && factor == 1.0)
return nullptr;
else if (conversion != m_conversions.end())
{
factor *= conversion->second.factor();
offset = conversion->second.offset();
}
}
}

if (tpower != 1.0)
Expand Down
1 change: 0 additions & 1 deletion src/mtconnect/entity/xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ namespace mtconnect::entity {
}
}

/// TODO: Add support for tables
DataSetValue value;
auto valueNode = child->children;
if (valueNode)
Expand Down
4 changes: 4 additions & 0 deletions test_package/unit_conversion_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,8 @@ TEST(UnitConversionTest, check_conversion_from_kw_h_to_watt_second)
auto conv = UnitConversion::make("KILOWATT/HOUR", "WATT/SECOND");
EXPECT_NEAR(0.16666, conv->convert(0.6), 0.001);
EXPECT_NEAR(0.25556, conv->convert(0.92), 0.001);

conv = UnitConversion::make("KILOWATT_HOUR", "WATT_SECOND");
EXPECT_NEAR(2160000.0, conv->convert(0.6), 0.001);
EXPECT_NEAR(3312000.0, conv->convert(0.92), 0.001);
}