aron_conversions.cpp
Go to the documentation of this file.
1 #include "aron_conversions.h"
2 
4 
5 
6 namespace armarx::armem
7 {
8  constexpr const char* DATA_WRAPPER_TIME_STORED_FIELD = "__WRITER_METADATA__TIME_STORED";
9  constexpr const char* DATA_WRAPPER_TIME_REFERENCED_FIELD = "__ENTITY_METADATA__TIME_REFERENCED";
10  constexpr const char* DATA_WRAPPER_TIME_SENT_FIELD = "__ENTITY_METADATA__TIME_SENT";
11  constexpr const char* DATA_WRAPPER_TIME_ARRIVED_FIELD = "__ENTITY_METADATA__TIME_ARRIVED";
12  constexpr const char* DATA_WRAPPER_CONFIDENCE_FIELD = "__ENTITY_METADATA__CONFIDENCE";
13 }
14 
15 
17 {
18  ARMARX_CHECK_NOT_NULL(metadata);
19  // Todo: What if data is null?
20 
22 
23  e.data() = data;
24 
25  auto referencedTime = aron::data::Long::DynamicCastAndCheck(metadata->getElement(DATA_WRAPPER_TIME_REFERENCED_FIELD));
26  m.referencedTime = Time(Duration::MicroSeconds(referencedTime->toAronLongDTO()->value));
27 
28  auto timeSent = aron::data::Long::DynamicCastAndCheck(metadata->getElement(DATA_WRAPPER_TIME_SENT_FIELD));
29  m.sentTime = Time(Duration::MicroSeconds(timeSent->toAronLongDTO()->value));
30 
31  auto timeArrived = aron::data::Long::DynamicCastAndCheck(metadata->getElement(DATA_WRAPPER_TIME_ARRIVED_FIELD));
32  m.arrivedTime = Time(Duration::MicroSeconds(timeArrived->toAronLongDTO()->value));
33 
34  auto confidence = aron::data::Double::DynamicCastAndCheck(metadata->getElement(DATA_WRAPPER_CONFIDENCE_FIELD));
35  m.confidence = static_cast<float>(confidence->toAronDoubleDTO()->value);
36 }
37 
38 
40 {
41  data = e.data();
42  metadata = std::make_shared<aron::data::Dict>();
43 
44  auto timeWrapped = std::make_shared<aron::data::Long>(armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_TIME_STORED_FIELD}));
45  timeWrapped->setValue(Time::Now().toMicroSecondsSinceEpoch());
46  metadata->addElement(DATA_WRAPPER_TIME_STORED_FIELD, timeWrapped);
47 
48  const wm::EntityInstanceMetadata& m = e.metadata();
49  auto referencedTime = std::make_shared<aron::data::Long>(armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_TIME_REFERENCED_FIELD}));
50  referencedTime->setValue(m.referencedTime.toMicroSecondsSinceEpoch());
51  metadata->addElement(DATA_WRAPPER_TIME_REFERENCED_FIELD, referencedTime);
52 
53  auto timeSent = std::make_shared<aron::data::Long>(armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_TIME_SENT_FIELD}));
54  timeSent->setValue(m.sentTime.toMicroSecondsSinceEpoch());
55  metadata->addElement(DATA_WRAPPER_TIME_SENT_FIELD, timeSent);
56 
57  auto timeArrived = std::make_shared<aron::data::Long>(armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_TIME_ARRIVED_FIELD}));
58  timeArrived->setValue(m.arrivedTime.toMicroSecondsSinceEpoch());
59  metadata->addElement(DATA_WRAPPER_TIME_ARRIVED_FIELD, timeArrived);
60 
61  auto confidence = std::make_shared<aron::data::Double>(armarx::aron::Path(std::vector<std::string>{DATA_WRAPPER_CONFIDENCE_FIELD}));
62  confidence->setValue(static_cast<double>(m.confidence));
63  metadata->addElement(DATA_WRAPPER_CONFIDENCE_FIELD, confidence);
64 }
armarx::armem::DATA_WRAPPER_TIME_REFERENCED_FIELD
constexpr const char * DATA_WRAPPER_TIME_REFERENCED_FIELD
Definition: aron_conversions.cpp:9
armarx::armem::wm::EntityInstance
Client-side working entity instance.
Definition: memory_definitions.h:32
armarx::armem::DATA_WRAPPER_TIME_ARRIVED_FIELD
constexpr const char * DATA_WRAPPER_TIME_ARRIVED_FIELD
Definition: aron_conversions.cpp:11
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::armem::DATA_WRAPPER_TIME_STORED_FIELD
constexpr const char * DATA_WRAPPER_TIME_STORED_FIELD
Definition: aron_conversions.cpp:8
armarx::armem
Definition: LegacyRobotStateMemoryAdapter.cpp:31
armarx::armem::DATA_WRAPPER_TIME_SENT_FIELD
constexpr const char * DATA_WRAPPER_TIME_SENT_FIELD
Definition: aron_conversions.cpp:10
aron_conversions.h
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::armem::base::EntityInstanceMetadata::sentTime
Time sentTime
Time when this value was sent to the memory.
Definition: EntityInstanceBase.h:49
armarx::armem::to_aron
void to_aron(aron::data::DictPtr &metadata, aron::data::DictPtr &data, const wm::EntityInstance &)
convert to metadata and aron instance
Definition: aron_conversions.cpp:39
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
All.h
armarx::core::time::DateTime::toMicroSecondsSinceEpoch
std::int64_t toMicroSecondsSinceEpoch() const
Definition: DateTime.cpp:95
armarx::armem::base::EntityInstanceMetadata::arrivedTime
Time arrivedTime
Time when this value has arrived at the memory.
Definition: EntityInstanceBase.h:51
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::armem::DATA_WRAPPER_CONFIDENCE_FIELD
constexpr const char * DATA_WRAPPER_CONFIDENCE_FIELD
Definition: aron_conversions.cpp:12
armarx::armem::base::EntityInstanceMetadata::referencedTime
Time referencedTime
Time this instance refers to.
Definition: EntityInstanceBase.h:46
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::armem::from_aron
void from_aron(const aron::data::DictPtr &metadata, const aron::data::DictPtr &data, wm::EntityInstance &)
convert from metadata and data aron instance
Definition: aron_conversions.cpp:16
armarx::armem::base::EntityInstanceMetadata
Metadata of an entity instance.
Definition: EntityInstanceBase.h:34
armarx::armem::base::EntityInstanceMetadata::confidence
float confidence
An optional confidence, may be used for things like decay.
Definition: EntityInstanceBase.h:54
armarx::armem::base::EntityInstanceBase::metadata
MetadataT & metadata()
Definition: EntityInstanceBase.h:117
armarx::armem::base::EntityInstanceBase::data
const DataT & data() const
Definition: EntityInstanceBase.h:129