11#if !defined(_OBSERVATIONS_H_)
12#define _OBSERVATIONS_H_
36int64
ExtractIntFromMessage(
const char* name, DataMessage* msg, std::map<std::string, std::string>& mappings,
bool &ok);
38float64
ExtractFloatFromMessage(
const char* name, DataMessage* msg, std::map<std::string, std::string>& mappings,
bool &ok);
40uint64
ExtractTimeFromMessage(
const char* name, DataMessage* msg, std::map<std::string, std::string>& mappings,
bool &ok);
42std::string
ExtractStringFromMessage(
const char* name, DataMessage* msg, std::map<std::string, std::string>& mappings,
bool &ok);
68 void init() { memset(
this, 0,
sizeof(*
this)); }
81 std::string
toJSON() {
return utils::StringFormat(
" \"x\": %.3f, \"y\": %.3f, \"z\": %.3f, \"pitch\": %.3f, \"roll\": %.3f, \"yaw\": %.3f, \"size\": %.2f",
x,
y,
z,
pitch,
roll,
yaw,
size); }
84 x = msg->
getFloat(
"FromX", ok);
if (!ok)
return false;
96 if ((
x < a.
x) || (
x > b.
x))
99 if ((
y < a.
y) || (
y > b.
y))
103 if ((
y < b.
y) || (
y > a.
y))
108 if ((
x < b.
x) || (
x > a.
x))
111 if ((
y < a.
y) || (
y > b.
y))
115 if ((
y < b.
y) || (
y > a.
y))
124 if (!ok)
return false;
126 if (!ok)
return false;
144 void init() { memset(
this, 0,
sizeof(*
this)); }
149 w = msg->
getFloat(
"FromW", ok);
if (!ok)
return false;
150 h = msg->
getFloat(
"FromH", ok);
if (!ok)
return false;
156 w = msg->
getFloat(
"ToW", ok);
if (!ok)
return false;
157 h = msg->
getFloat(
"ToH", ok);
if (!ok)
return false;
162 float64 vol, volA, volB;
166 volA = a.
w * a.
h * a.
d;
167 volB = b.
w * b.
h * b.
d;
176 if ((vol < volA) || (vol > volB))
180 if ((vol < volB) || (vol > volA))
188 if (!ok)
return false;
190 if (!ok)
return false;
203 void init() { memset(
this, 0,
sizeof(*
this)); }
235 void init() { memset(
this, 0,
sizeof(*
this)); }
267 void init() { memset(
this, 0,
sizeof(*
this)); }
293#define OBSID_STRING 6
299 void init() { memset(
this, 0,
sizeof(*
this)); }
304 const char* str = msg->
getString(
"FromVal", ok);
305 if (!ok)
return false;
311 const char* str = msg->
getString(
"ToVal", ok);
312 if (!ok)
return false;
332 if (!ok)
return false;
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
Template implementations for GenericObservation<T> (declared in Observations.h).
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool getInt(const char *key, int64 &value)
getInt(const char* key, int64& value)
uint64 getTime(const char *key)
getTime(const char* key)
bool getFloat(const char *key, float64 &value)
getFloat(const char* key, float64& value)
const char * getString(const char *key)
getString(const char* key)
std::string toJSON()
JSON object rendering.
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
Populate the payload from a message using logical→actual field mappings.
static bool WriteAllToMessage(DataMessage *msg, std::list< GenericObservation< T > * > &list)
Serialize all observations in list into msg.
ObsHeader header
Identity/provenance/confidence header.
bool readFromMessage(DataMessage *msg, uint64 id=0)
Read the observation with id id (0 = first) from msg.
std::string print()
One-line human-readable rendering (header + payload).
static std::list< GenericObservation< T > * > ReadAllFromMessage(DataMessage *msg)
Deserialize every observation of type T carried by msg.
bool writeToMessage(DataMessage *msg, uint64 id)
Append this observation to msg under entry id id.
bool readFromData(const char *data, uint32 size, uint64 id=0)
Parse from a raw blob.
GenericObservation()
Empty observation (zeroed header and payload).
bool isBetween(GenericObservation< T > *a, GenericObservation< T > *b)
Range test delegated to the payload's isBetween(); see per-type notes on semantics.
std::string PrintTimeString(uint64 t, bool local=true, bool us=true, bool ms=true)
char * PrintTime(uint64 t, bool local=true, bool us=true, bool ms=true)
Full date + time-of-day.
std::string StringFormat(const char *format,...)
printf into a std::string.
uint32 strcpyavail(char *dst, const char *src, uint32 maxlen, bool copyAvailable)
Bounded strcpy that always NUL-terminates.
std::string ExtractStringFromMessage(const char *name, DataMessage *msg, std::map< std::string, std::string > &mappings, bool &ok)
String variant of ExtractIntFromMessage(); same mapping semantics.
uint64 ExtractTimeFromMessage(const char *name, DataMessage *msg, std::map< std::string, std::string > &mappings, bool &ok)
Timestamp variant of ExtractIntFromMessage(); same mapping semantics.
float64 ExtractFloatFromMessage(const char *name, DataMessage *msg, std::map< std::string, std::string > &mappings, bool &ok)
Float variant of ExtractIntFromMessage(); same mapping semantics.
bool Observations_UnitTest()
Unit test for the Observations module.
uint32 GetObsTypeFromRawData(const char *data, uint32 size)
Inspect a raw observation blob and return its OBSID_* type tag from the embedded ObsHeader.
int64 ExtractIntFromMessage(const char *name, DataMessage *msg, std::map< std::string, std::string > &mappings, bool &ok)
Read an integer field from a message, translating name through mappings first.
void Register_Observations_Tests()
Register the Observations tests with the unit test framework.
Extent observation (w,h,d).
bool extractRangeTo(DataMessage *msg)
bool extractRangeFrom(DataMessage *msg)
static std::string getTypeName()
bool isBetween(ObsDimension &a, ObsDimension &b)
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
Declarative description of one observation source: name, observation type, trigger expression and fie...
std::map< std::string, std::string > mappings
Scalar float observation.
bool extractRangeTo(DataMessage *msg)
bool isBetween(ObsFloat &a, ObsFloat &b)
bool extractRangeFrom(DataMessage *msg)
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
static std::string getTypeName()
Scalar integer observation.
bool extractRangeFrom(DataMessage *msg)
bool extractRangeTo(DataMessage *msg)
bool isBetween(ObsInteger &a, ObsInteger &b)
static std::string getTypeName()
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
6-DOF pose observation: position (x,y,z), orientation (pitch,roll,yaw), size and owning map id.
bool isBetween(ObsLocation &a, ObsLocation &b)
static std::string getTypeName()
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
bool extractRangeFrom(DataMessage *msg)
bool extractRangeTo(DataMessage *msg)
Fixed-buffer (1023 chars + NUL) string observation; comparisons are case-insensitive lexicographic.
static std::string getTypeName()
bool extractRangeFrom(DataMessage *msg)
bool extractRangeTo(DataMessage *msg)
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
bool isBetween(ObsString &a, ObsString &b)
Timestamp observation (ms epoch).
static std::string getTypeName()
bool extractRangeTo(DataMessage *msg)
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
bool extractRangeFrom(DataMessage *msg)
bool isBetween(ObsTime &a, ObsTime &b)
Comparator matching ObsEntry records by name only (used for de-duplication in containers).
bool operator()(const ObsEntry &a, const ObsEntry &b) const