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 10)
set(AGENT_VERSION_BUILD 11)
set(AGENT_VERSION_RC "")

# This minimum version is to support Visual Studio 2019 and C++ feature checking and FetchContent
Expand Down
4 changes: 2 additions & 2 deletions conan/mruby/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ def package_info(self):

buf = io.StringIO()
self.run("{} --cflags".format(ruby), stdout=buf, shell=True)
self.cpp_info.defines = [d[2:] for d in buf.getvalue().split(' ') if d.startswith('/D') or d.startswith('-D')]

self.conf_info.define('mruby', 'ON')
defines = [d[2:] for d in buf.getvalue().split(' ') if d.startswith('/D') or d.startswith('-D')]
self.cpp_info.defines = defines

self.cpp_info.bindirs = ["bin"]
if self.settings.os == 'Windows':
Expand Down
6 changes: 3 additions & 3 deletions src/mtconnect/entity/data_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace mtconnect::entity {
{
return std::holds_alternative<T2>(v1) && std::get<T2>(v1) == v2;
}

/// @brief One entry in a data set. Has necessary interface to be work with maps.
/// @tparam T The type of the underlying variant data
template <typename T>
Expand Down Expand Up @@ -109,8 +109,8 @@ namespace mtconnect::entity {
/// @param other the other value to compare against `m_value`
/// @returns `true` if the values are the same
///
/// Compares using the `SameValue` free function in the `data_set` namespace. It must be overloaded
/// for any special types required by the variant type T.
/// Compares using the `SameValue` free function in the `data_set` namespace. It must be
/// overloaded for any special types required by the variant type T.
bool sameValue(const Entry &other) const
{
const auto &ov = other.m_value;
Expand Down
5 changes: 4 additions & 1 deletion src/mtconnect/printer/json_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,10 @@ namespace mtconnect::printer {
}
else
{
AutoJsonObject streams(writer, "Streams");
if (m_jsonVersion == 1)
AutoJsonArray streams(writer, "Streams");
else
AutoJsonObject streams(writer, "Streams");
}
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/mtconnect/source/adapter/adapter_pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ namespace mtconnect {
if (IsOptionSet(m_options, configuration::CorrectTimestamps))
next = next->bind(make_shared<CorrectTimestamp>(m_context));

// Validate Values
if (IsOptionSet(m_options, configuration::Validation))
next = next->bind(make_shared<Validator>(m_context));

// Filter dups, by delta, and by period
next = next->bind(make_shared<DuplicateFilter>(m_context));
next = next->bind(make_shared<DeltaFilter>(m_context));
next = next->bind(make_shared<PeriodFilter>(m_context, m_strand));

// Validate Values
if (IsOptionSet(m_options, configuration::Validation))
next = next->bind(make_shared<Validator>(m_context));

// Deliver
std::optional<string> obsMetrics;
obsMetrics = m_identity + "_observation_update_rate";
Expand Down
41 changes: 21 additions & 20 deletions src/mtconnect/utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,25 +685,27 @@ namespace mtconnect {
///
/// @param[in,out] start starting iterator
/// @param[in,out] end ending iterator
inline void capitalize(std::string::iterator start, std::string::iterator end)
inline void capitalize(std::ostringstream &camel, std::string::const_iterator start,
std::string::const_iterator end)
{
using namespace std;

// Exceptions to the rule
const static std::unordered_map<std::string, std::string> exceptions = {
const static std::unordered_map<std::string_view, std::string_view> exceptions = {
{"AC", "AC"}, {"DC", "DC"}, {"PH", "PH"},
{"IP", "IP"}, {"URI", "URI"}, {"MTCONNECT", "MTConnect"}};

const auto &w = exceptions.find(std::string(start, end));
std::string_view s(&*start, distance(start, end));
const auto &w = exceptions.find(s);
ostream_iterator<char> out(camel);
if (w != exceptions.end())
{
copy(w->second.begin(), w->second.end(), start);
copy(w->second.begin(), w->second.end(), out);
}
else
{
*start = ::toupper(*start);
start++;
transform(start, end, start, ::tolower);
camel << static_cast<char>(::toupper(*start));
transform(start + 1, end, out, ::tolower);
}
}

Expand All @@ -721,34 +723,33 @@ namespace mtconnect {
if (type.empty())
return "";

string camel;
ostringstream camel;

auto start = type.begin();
decltype(start) end;

auto colon = type.find(':');

if (colon != string::npos)
{
prefix = type.substr(0ul, colon);
camel = type.substr(colon + 1ul);
start += colon + 1;
}
else
camel = type;

auto start = camel.begin();
decltype(start) end;

bool done;
do
{
end = find(start, camel.end(), '_');
capitalize(start, end);
done = end == camel.end();
end = find(start, type.end(), '_');
if (start != end)
capitalize(camel, start, end);
done = end == type.end();
if (!done)
{
camel.erase(end);
start = end;
start = end + 1;
}
} while (!done);

return camel;
return camel.str();
}

/// @brief parse a string timestamp to a `Timestamp`
Expand Down
5 changes: 5 additions & 0 deletions test_package/data_item_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ TEST_F(DataItemTest, GetCamel)
ASSERT_EQ((string) "CamelCase", pascalize("CAMEL_CASE", prefix));
ASSERT_EQ((string) "ABCc", pascalize("A_B_CC", prefix));

ASSERT_EQ((string) "ThreeHumpCamelCase", pascalize("THREE_HUMP_CAMEL_CASE", prefix));

prefix.reset();
ASSERT_EQ((string) "CamelCase", pascalize("x:CAMEL_CASE", prefix));
ASSERT_EQ((string) "x", *prefix);
prefix.reset();
ASSERT_EQ((string) "MySillyTag", pascalize("y:MY__SILLY_TAG", prefix));
ASSERT_EQ((string) "y", *prefix);
}

TEST_F(DataItemTest, Condition) { ASSERT_EQ(DataItem::CONDITION, m_dataItemC->getCategory()); }
Expand Down
28 changes: 28 additions & 0 deletions test_package/json_printer_stream_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,34 @@ TEST_F(JsonPrinterStreamTest, DeviceStream)
stream.at("/uuid"_json_pointer).get<string>());
}

TEST_F(JsonPrinterStreamTest, should_use_array_for_empty_version_1_stream)
{
Checkpoint checkpoint;
ObservationList list;
checkpoint.getObservations(list);
auto doc = m_printer->printSample(123, 131072, 10254805, 10123733, 10123800, list);

auto jdoc = json::parse(doc);
json stream = jdoc.at("/MTConnectStreams/Streams"_json_pointer);
ASSERT_TRUE(stream.is_array());
ASSERT_EQ(0, stream.size());
}

TEST_F(JsonPrinterStreamTest, should_use_object_for_empty_version_2_stream)
{
m_printer = std::make_unique<printer::JsonPrinter>(2, true);

Checkpoint checkpoint;
ObservationList list;
checkpoint.getObservations(list);
auto doc = m_printer->printSample(123, 131072, 10254805, 10123733, 10123800, list);

auto jdoc = json::parse(doc);
json stream = jdoc.at("/MTConnectStreams/Streams"_json_pointer);
ASSERT_TRUE(stream.is_object());
ASSERT_EQ(0, stream.size());
}

TEST_F(JsonPrinterStreamTest, DeviceStream_version_2_one_device)
{
m_printer = std::make_unique<printer::JsonPrinter>(2, true);
Expand Down