Skip to content
This repository was archived by the owner on May 4, 2024. It is now read-only.

Commit b953d83

Browse files
committed
Fixed json mapping
1 parent f835989 commit b953d83

12 files changed

+143112
-8
lines changed

schemas/MTConnectAssets_2.1.xsd

Lines changed: 15475 additions & 0 deletions
Large diffs are not rendered by default.

schemas/MTConnectAssets_2.1_1.0.xsd

Lines changed: 15454 additions & 0 deletions
Large diffs are not rendered by default.

schemas/MTConnectDevices_2.1.xsd

Lines changed: 9759 additions & 0 deletions
Large diffs are not rendered by default.

schemas/MTConnectDevices_2.1_1.0.xsd

Lines changed: 9752 additions & 0 deletions
Large diffs are not rendered by default.

schemas/MTConnectError_2.1.xsd

Lines changed: 4376 additions & 0 deletions
Large diffs are not rendered by default.

schemas/MTConnectError_2.1_1.0.xsd

Lines changed: 4376 additions & 0 deletions
Large diffs are not rendered by default.

schemas/MTConnectStreams_2.1.xsd

Lines changed: 41939 additions & 0 deletions
Large diffs are not rendered by default.

schemas/MTConnectStreams_2.1_1.0.xsd

Lines changed: 41939 additions & 0 deletions
Large diffs are not rendered by default.

src/pipeline/transform.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ namespace mtconnect {
181181
if (it->get() == old.get())
182182
{
183183
*it = xform;
184-
for (auto nxt = old->m_next.begin(); it != old->m_next.end(); it++)
184+
for (auto nxt = old->m_next.begin(); nxt != old->m_next.end(); nxt++)
185185
{
186186
xform->bind(*nxt);
187187
}
@@ -196,7 +196,7 @@ namespace mtconnect {
196196
if (it->get() == old.get())
197197
{
198198
m_next.erase(it);
199-
for (auto nxt = old->m_next.begin(); it != old->m_next.end(); it++)
199+
for (auto nxt = old->m_next.begin(); nxt != old->m_next.end(); nxt++)
200200
{
201201
bind(*nxt);
202202
}

src/ruby/ruby_entity.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ namespace mtconnect::ruby {
395395
[](mrb_state *mrb, mrb_value self) {
396396
auto entity = MRubySharedPtr<Entity>::unwrap(self);
397397
const char *key;
398-
mrb_get_args(mrb, "s", &key);
398+
399+
mrb_get_args(mrb, "z", &key);
399400

400401
auto props = entity->getProperties();
401402
auto it = props.find(key);
@@ -411,7 +412,7 @@ namespace mtconnect::ruby {
411412
auto entity = MRubySharedPtr<Entity>::unwrap(self);
412413
const char *key;
413414
mrb_value value;
414-
mrb_get_args(mrb, "so", &key, &value);
415+
mrb_get_args(mrb, "zo", &key, &value);
415416

416417
entity->setProperty(key, valueFromRuby(mrb, value));
417418

src/ruby/ruby_type.hpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,22 @@ namespace mtconnect::ruby {
6363
inline Timestamp timestampFromRuby(mrb_state *mrb, mrb_value value)
6464
{
6565
using namespace std::chrono;
66-
67-
auto tm = static_cast<mrb_time *>(DATA_PTR(value));
68-
auto dur = duration_cast<microseconds>(seconds {tm->sec} + microseconds {tm->usec});
69-
return time_point<system_clock> {duration_cast<system_clock::duration>(dur)};
66+
if (mrb_string_p(value))
67+
{
68+
auto text = std::string(mrb_str_to_cstr(mrb, value));
69+
return parseTimestamp(text);
70+
}
71+
auto dp = DATA_TYPE(value);
72+
if (strncmp(dp->struct_name, "Time", 4) == 0)
73+
{
74+
auto tm = static_cast<mrb_time *>(DATA_PTR(value));
75+
auto dur = duration_cast<microseconds>(seconds {tm->sec} + microseconds {tm->usec});
76+
return time_point<system_clock> {duration_cast<system_clock::duration>(dur)};
77+
}
78+
else
79+
{
80+
return Timestamp();
81+
}
7082
}
7183

7284
inline mrb_value toRuby(mrb_state *mrb, const Timestamp &ts)

src/utilities.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ typedef unsigned __int64 uint64_t;
7474
#include <boost/property_tree/ptree.hpp>
7575
#include <boost/regex.hpp>
7676

77+
#include <date/date.h>
78+
#include <chrono>
79+
7780
#include <version.h>
7881

7982
//####### CONSTANTS #######
@@ -576,6 +579,24 @@ namespace mtconnect {
576579

577580
return camel;
578581
}
582+
583+
inline Timestamp parseTimestamp(const std::string &timestamp)
584+
{
585+
using namespace date;
586+
using namespace std::chrono;
587+
using namespace std::chrono_literals;
588+
using namespace date::literals;
589+
590+
Timestamp ts;
591+
std::istringstream in(timestamp);
592+
in >> std::setw(6) >> parse("%FT%T", ts);
593+
if (!in.good())
594+
{
595+
ts = std::chrono::system_clock::now();
596+
}
597+
return ts;
598+
}
599+
579600

580601
#define SCHEMA_VERSION(major, minor) (major * 100 + minor)
581602

0 commit comments

Comments
 (0)