Fledge
An open source edge computing platform for industrial users
OMF Class Reference

The OMF class. More...

#include <omf.h>

Public Member Functions

 OMF (const std::string &name, HttpSender &sender, const std::string &path, const long typeId, const std::string &producerToken)
 Constructor: pass server URL path, OMF_type_id and producerToken.
 
 OMF (const std::string &name, HttpSender &sender, const std::string &path, std::map< std::string, OMFDataTypes > &types, const std::string &producerToken)
 
void setOMFVersion (std::string &omfversion)
 
void setSender (HttpSender &sender)
 
uint32_t sendToServer (const std::vector< Reading > &readings, bool skipSentDataTypes=true)
 Send data to PI Server passing a vector of readings. More...
 
uint32_t sendToServer (const std::vector< Reading *> &readings, bool compression, bool skipSentDataTypes=true)
 Send all the readings to the PI Server. More...
 
uint32_t sendToServer (const Reading &reading, bool skipSentDataTypes=true)
 Send a single reading to the PI Server. More...
 
uint32_t sendToServer (const Reading *reading, bool skipSentDataTypes=true)
 Send a single reading pointer to the PI Server. More...
 
void setFormatType (const std::string &key, std::string &value)
 Add the key (OMF type + OMF format) into a map. More...
 
void setPIServerEndpoint (const OMF_ENDPOINT PIServerEndpoint)
 Set which PIServer component should be used for the communication.
 
void setNamingScheme (const NAMINGSCHEME_ENDPOINT namingScheme)
 
std::string generateMeasurementId (const string &assetName)
 Generate the container id for the given asset. More...
 
std::string generateSuffixType (string &assetName, long typeId)
 Generate a suffix for the given asset in relation to the selected naming schema and the value of the type id. More...
 
long getNamingScheme (const string &assetName)
 Retrieve the naming scheme for the given asset in relation to the end point selected the default naming scheme selected and the naming scheme of the asset itself. More...
 
string getHashStored (const string &assetName)
 Retrieve the hash for the given asset in relation to the end point selected. More...
 
string getPathStored (const string &assetName)
 Retrieve the current AF hierarchy for the given asset. More...
 
string getPathOrigStored (const string &assetName)
 Retrieve the AF hierarchy in which given asset was created. More...
 
bool setPathStored (const string &assetName, string &afHierarchy)
 Stores the current AF hierarchy for the given asset. More...
 
bool deleteAssetAFH (const string &assetName, string &path)
 AFHierarchy - delete the link between 2 elements in the AF hierarchy. More...
 
bool createAssetAFH (const string &assetName, string &path)
 AFHierarchy - create the link between 2 elements in the AF hierarchy. More...
 
void setDefaultAFLocation (const std::string &DefaultAFLocation)
 Set the first level of hierarchy in Asset Framework in which the assets will be created, PI Web API only.
 
bool setAFMap (const std::string &AFMap)
 Set the Names and Metadata rules to address where assets should be placed in the AF hierarchy.
 
void setSendFullStructure (const bool sendFullStructure)
 
void setPrefixAFAsset (const std::string &prefixAFAsset)
 Set the first level of hierarchy in Asset Framework in which the assets will be created, PI Web API only.
 
void setDelimiter (const std::string &delimiter)
 
void setDataActionCode (const std::string &actionCode)
 
std::string getFormatType (const std::string &key) const
 Get from m_formatTypes map the key (OMF type + OMF format) More...
 
void setNotBlockingErrors (std::vector< std::string > &)
 Set the list of errors considered not blocking in the communication with the PI Server.
 
std::string compress_string (const std::string &str, int compressionlevel=Z_DEFAULT_COMPRESSION)
 Compress a string. More...
 
const long getTypeId () const
 
bool isDataTypeError (const char *message)
 Check for invalid/redefinition data type error. More...
 
bool isPIstable ()
 
bool isPIconnected ()
 
void setPIconnected (bool connectionStatus)
 
void setMapObjectTypes (const std::vector< Reading *> &data, std::map< std::string, Reading *> &dataSuperSet)
 Create a superset data map for each reading and found datapoints. More...
 
void unsetMapObjectTypes (std::map< std::string, Reading *> &dataSuperSet) const
 Cleanup the mapped object types for input data. More...
 
void setStaticData (std::vector< std::pair< std::string, std::string >> *staticData)
 
void generateAFHierarchyPrefixLevel (string &path, string &prefix, string &AFHierarchyLevel)
 Calculate the prefix to be used for AF objects and the last level of the hierarchies from a given AF path. More...
 
map< std::string, std::string > getNamesRules () const
 
map< std::string, std::string > getMetadataRulesExist () const
 
bool getAFMapEmptyNames () const
 
bool getAFMapEmptyMetadata () const
 
void setLegacyMode (bool legacy)
 

Static Public Member Functions

static std::string ApplyPIServerNamingRulesObj (const std::string &objName, bool *changed)
 Check a PI Server object name and returns the proper name to use following the naming rules: More...
 
static std::string ApplyPIServerNamingRulesPath (const std::string &objName, bool *changed)
 Check a PI Server path name and returns the proper name to use following the naming rules: More...
 
static std::string ApplyPIServerNamingRulesInvalidChars (const std::string &objName, bool *changed)
 Check a PI Server name and returns the proper name to use following the naming rules. More...
 
static std::string variableValueHandle (const Reading &reading, std::string &AFHierarchy)
 Evaluate the AF hierarchy provided and expand the variables in the form ${room:unknown}. More...
 
static bool extractVariable (string &strToHandle, string &variable, string &value, string &defaultValue)
 Extracts a variable and its elements from a string, the variable will have the shape ${room:unknown}. More...
 
static void reportAsset (const string &asset, const string &level, const string &msg)
 Report an error related to an asset if the asset has not already been reported. More...
 

Detailed Description

The OMF class.

Implements the OMF protocol

Member Function Documentation

◆ ApplyPIServerNamingRulesInvalidChars()

std::string OMF::ApplyPIServerNamingRulesInvalidChars ( const std::string &  objName,
bool *  changed 
)
static

Check a PI Server name and returns the proper name to use following the naming rules.

Invalid chars: Control characters plus: * ? ; { } [ ] | \ ` ' "

Parameters
objNameThe object name to verify
changedif not null, it is set to true if a change occurred
Returns
Object name following the PI Server naming rules

◆ ApplyPIServerNamingRulesObj()

std::string OMF::ApplyPIServerNamingRulesObj ( const std::string &  objName,
bool *  changed 
)
static

Check a PI Server object name and returns the proper name to use following the naming rules:

  • Blank names are not permitted, substituted with '_'
  • Trailing spaces are removed
  • Maximum name length is 200 characters.
  • Valid chars
  • Names cannot begin with '__', These are reserved for system use, substituted with single '_'

Note: Names on PI-Server side are not case sensitive

Parameters
objNameThe object name to verify
changedif not null, it is set to true if a change occur
Returns
Object name following the PI Server naming rules

Names cannot begin with '__'. These are reserved for system use.

◆ ApplyPIServerNamingRulesPath()

std::string OMF::ApplyPIServerNamingRulesPath ( const std::string &  objName,
bool *  changed 
)
static

Check a PI Server path name and returns the proper name to use following the naming rules:

  • Blank names are not permitted, substituted with '_'
  • Trailing spaces are removed
  • Maximum name length is 200 characters.
  • Valid chars
  • Names cannot begin with '__', These are reserved for system use, substituted with single '_'

Names on PI-Server side are not case sensitive

Parameters
objNameThe object name to verify
changedif not null, it is set to true if a change occurred
Returns
Object name following the PI Server naming rules

Names cannot begin with '__'. These are reserved for system use.

◆ compress_string()

std::string OMF::compress_string ( const std::string &  str,
int  compressionlevel = Z_DEFAULT_COMPRESSION 
)

Compress a string.

Parameters
strInput STL string that is to be compressed
compressionlevelzlib/gzip Compression level
Returns
str gzip compressed binary data

◆ createAssetAFH()

bool OMF::createAssetAFH ( const string &  assetName,
string &  path 
)

AFHierarchy - create the link between 2 elements in the AF hierarchy.

◆ deleteAssetAFH()

bool OMF::deleteAssetAFH ( const string &  assetName,
string &  path 
)

AFHierarchy - delete the link between 2 elements in the AF hierarchy.

◆ extractVariable()

bool OMF::extractVariable ( string &  strToHandle,
string &  variable,
string &  value,
string &  defaultValue 
)
static

Extracts a variable and its elements from a string, the variable will have the shape ${room:unknown}.

Parameters
strToHandleSource string from which the variable should be extracted
variableVariable found in the form ${room:unknown}
valueValue of the variable, left part , room in this case ${room:unknown}
defaultValueDefault value of the variable, right part , unknown in this case ${room:unknown}
Returns
True a variable is found in the source string

◆ generateAFHierarchyPrefixLevel()

void OMF::generateAFHierarchyPrefixLevel ( string &  path,
string &  prefix,
string &  AFHierarchyLevel 
)

Calculate the prefix to be used for AF objects and the last level of the hierarchies from a given AF path.

Parameters
pathPath to evaluate
out/prefixCalculated prefix
out/AFHierarchyLevellast level of the hierarchies evaluated form the path

◆ generateMeasurementId()

std::string OMF::generateMeasurementId ( const string &  assetName)

Generate the container id for the given asset.

Parameters
assetNameAsset for which the container id should be generated
Returns
Container id for the requested asset

◆ generateSuffixType()

std::string OMF::generateSuffixType ( string &  assetName,
long  typeId 
)

Generate a suffix for the given asset in relation to the selected naming schema and the value of the type id.

Parameters
assetNameAsset for which the suffix should be generated
typeIdType id of the asset
Returns
Suffix to be used for the given asset

◆ getFormatType()

std::string OMF::getFormatType ( const std::string &  key) const

Get from m_formatTypes map the key (OMF type + OMF format)

Parameters
keyThe OMF type for which the format is requested
Returns
The defined OMF format for the requested type

◆ getHashStored()

string OMF::getHashStored ( const string &  assetName)

Retrieve the hash for the given asset in relation to the end point selected.

Parameters
assetNameAsset for which the hash should be retrieved
Returns
Hash of the given asset

◆ getNamingScheme()

long OMF::getNamingScheme ( const string &  assetName)

Retrieve the naming scheme for the given asset in relation to the end point selected the default naming scheme selected and the naming scheme of the asset itself.

Parameters
assetNameAsset for which the naming schema should be retrieved
Returns
Naming schema of the given asset

◆ getPathOrigStored()

string OMF::getPathOrigStored ( const string &  assetName)

Retrieve the AF hierarchy in which given asset was created.

Parameters
assetNameAsset for which the path should be retrieved
Returns
Path of the given asset

◆ getPathStored()

string OMF::getPathStored ( const string &  assetName)

Retrieve the current AF hierarchy for the given asset.

Parameters
assetNameAsset for which the path should be retrieved
Returns
Path of the given asset

◆ isDataTypeError()

bool OMF::isDataTypeError ( const char *  message)

Check for invalid/redefinition data type error.

Parameters
messageServer reply message for data type creation
Returns
True for data type error, false otherwise

◆ reportAsset()

void OMF::reportAsset ( const string &  asset,
const string &  level,
const string &  msg 
)
static

Report an error related to an asset if the asset has not already been reported.

Parameters
assetThe asset name
levelThe level to log the message at
msgThe message to log

◆ sendToServer() [1/4]

uint32_t OMF::sendToServer ( const std::vector< Reading > &  readings,
bool  skipSentDataTypes = true 
)

Send data to PI Server passing a vector of readings.

Send all the readings to the PI Server.

Data sending is composed by a few phases handled by private methods.

Note: DataTypes are sent only once by using an in memory key map, being the key = assetName + typeId. Passing false to skipSentDataTypes changes the logic.

Returns the number of processed readings.

Note: this overload is never called.

Parameters
readingsA vector of readings data
skipSendDataTypesSend datatypes only once (default is true)
Returns
Number of readings sent on success, 0 otherwise

◆ sendToServer() [2/4]

uint32_t OMF::sendToServer ( const std::vector< Reading *> &  readings,
bool  compression,
bool  skipSentDataTypes = true 
)

Send all the readings to the PI Server.

Parameters
readingsA vector of readings data pointers
skipSendDataTypesSend datatypes only once (default is true)
compressionIf true, compress JSON payload before sending to PI
Returns
Number of readings sent on success, 0 otherwise

Types messages sent, now transform each reading to OMF format.

After formatting the new vector of data can be sent with one message only

◆ sendToServer() [3/4]

uint32_t OMF::sendToServer ( const Reading reading,
bool  skipSentDataTypes = true 
)

Send a single reading to the PI Server.

Note: this overload is never called.

Parameters
readingA reading to send
Returns
1 = on success, 0 otherwise

◆ sendToServer() [4/4]

uint32_t OMF::sendToServer ( const Reading reading,
bool  skipSentDataTypes = true 
)

Send a single reading pointer to the PI Server.

Note: this overload is never called.

Parameters
readingA reading pointer to send
Returns
1 = on success, 0 otherwise

◆ setFormatType()

void OMF::setFormatType ( const std::string &  key,
std::string &  value 
)

Add the key (OMF type + OMF format) into a map.

Parameters
keyThe OMF type, key of the map
valueThe OMF format to set for the specific OMF type

◆ setMapObjectTypes()

void OMF::setMapObjectTypes ( const std::vector< Reading *> &  data,
std::map< std::string, Reading *> &  dataSuperSet 
)

Create a superset data map for each reading and found datapoints.

The output map is filled with a Reading object containing all the datapoints found for each asset in the input reading set. The datapoints have a fake value based on the datapoint type

Parameters
readingsCurrent input readings data
dataSuperSetMap to store all datapoints for an assetname

◆ setPathStored()

bool OMF::setPathStored ( const string &  assetName,
string &  afHierarchy 
)

Stores the current AF hierarchy for the given asset.

Parameters
assetNameAsset for which the path should be retrieved
afHierarchyCurrent AF hierarchy of the asset
Returns
True if the operation has success

◆ unsetMapObjectTypes()

void OMF::unsetMapObjectTypes ( std::map< std::string, Reading *> &  dataSuperSet) const

Cleanup the mapped object types for input data.

Parameters
dataSuperSetThe mapped object to cleanup

◆ variableValueHandle()

std::string OMF::variableValueHandle ( const Reading reading,
std::string &  AFHierarchy 
)
static

Evaluate the AF hierarchy provided and expand the variables in the form ${room:unknown}.

Parameters
readingAsset reading that should be considered from which to extract the metadata values
AFHierarchyAF hierarchy containing the variable to be expanded
Returns
True if variables were found and expanded

The documentation for this class was generated from the following files: