Fledge
An open source edge computing platform for industrial users
omflinkeddata.h
1 #ifndef OMFLINKEDDATA_H
2 #define OMFLINKEDDATA_H
3 /*
4  * Fledge OSIsoft OMF interface to PI Server.
5  *
6  * Copyright (c) 2022-2025 Dianomic Systems
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch
11  */
12 
13 #include <map>
14 #include <set>
15 #include <reading.h>
16 #include <OMFHint.h>
17 #include <omfbuffer.h>
18 #include <linkedlookup.h>
19 #include <omferror.h>
20 
39 {
40  public:
41  OMFLinkedData( std::unordered_map<std::string, LALookup> *linkedAssetState,
42  const OMF_ENDPOINT PIServerEndpoint = ENDPOINT_CR) :
43  m_linkedAssetState(linkedAssetState),
44  m_endpoint(PIServerEndpoint),
45  m_doubleFormat("float64"),
46  m_integerFormat("int64")
47  {};
48  bool processReading(OMFBuffer& payload, bool needDelim, const Reading& reading,
49  const std::string& DefaultAFLocation = std::string(),
50  OMFHints *hints = NULL);
51  void buildLookup(const std::vector<Reading *>& reading);
52  void setSendFullStructure(const bool sendFullStructure) {m_sendFullStructure = sendFullStructure;};
53  bool flushContainers(HttpSender& sender, const std::string& path, std::vector<std::pair<std::string, std::string> >& header, OMFError& error, bool *isConnected);
54  std::size_t clearLALookup(const std::vector<Reading *>& reading, std::size_t startIndex, std::size_t numReadings, std::string &delimiter);
55  void setDelimiter(const std::string &delimiter) {m_delimiter = delimiter;};
56  void setFormats(const std::string& doubleFormat, const std::string& integerFormat)
57  {
58  m_doubleFormat = doubleFormat;
59  m_integerFormat = integerFormat;
60  };
61  void setStaticData(std::vector<std::pair<std::string, std::string>> *staticData)
62  {
63  m_staticData = staticData;
64  };
65 
66  private:
67  std::string getBaseType(Datapoint *dp, const std::string& format);
68  void sendContainer(std::string& link, Datapoint *dp, OMFHints * hints, const std::string& baseType);
69  bool isTypeSupported(DatapointValue& dataPoint)
70  {
71  switch (dataPoint.getType())
72  {
73  case DatapointValue::DatapointTag::T_FLOAT:
74  case DatapointValue::DatapointTag::T_INTEGER:
75  case DatapointValue::DatapointTag::T_STRING:
76  return true;
77  default:
78  return false;
79  }
80  };
81 
82  private:
83  bool m_sendFullStructure;
84  std::string m_delimiter;
85 
92  std::unordered_map<std::string, LALookup> *m_linkedAssetState;
93 
97  OMF_ENDPOINT m_endpoint;
98 
102  std::vector<std::pair<std::string, std::string>> *m_staticData;
103 
104 
108  std::string m_containers;
109  std::set<std::string> m_containerNames;
110  std::string m_doubleFormat;
111  std::string m_integerFormat;
112 
113 };
114 #endif
OMFLinkedData::buildLookup
void buildLookup(const std::vector< Reading * > &reading)
If the entries are needed in the lookup table for this block of readings then create them.
Definition: linkdata.cpp:377
OMFLinkedData::flushContainers
bool flushContainers(HttpSender &sender, const std::string &path, std::vector< std::pair< std::string, std::string > > &header, OMFError &error, bool *isConnected)
Flush the container definitions that have been built up.
Definition: linkdata.cpp:615
Reading
An asset reading represented as a class.
Definition: reading.h:33
OMFLinkedData
The OMFLinkedData class.
Definition: omflinkeddata.h:38
OMFLinkedData::processReading
bool processReading(OMFBuffer &payload, bool needDelim, const Reading &reading, const std::string &DefaultAFLocation=std::string(), OMFHints *hints=NULL)
OMFLinkedData constructor, generates the OMF message containing the data.
Definition: linkdata.cpp:134
DatapointValue::getType
dataTagType getType() const
Return the Tag type.
Definition: datapoint.h:226
Datapoint
Name and value pair used to represent a data value within an asset reading.
Definition: datapoint.h:310
OMFBuffer
Buffer class designed to hold OMF payloads that can grow as required but have minimal copy semantics.
Definition: omfbuffer.h:24
HttpSender
Definition: http_sender.h:20
OMFError
An encapsulation of an error return from an OMF call.
Definition: omferror.h:21
DatapointValue
Class to hold an actual reading value.
Definition: datapoint.h:30
OMFLinkedData::clearLALookup
std::size_t clearLALookup(const std::vector< Reading * > &reading, std::size_t startIndex, std::size_t numReadings, std::string &delimiter)
Clear selected Reading and Datapoint information from the linked asset state map.
Definition: linkdata.cpp:736
OMFHints
A set of hints for a reading.
Definition: OMFHint.h:160