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 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  void setDelimiter(const std::string &delimiter) {m_delimiter = delimiter;};
55  void setFormats(const std::string& doubleFormat, const std::string& integerFormat)
56  {
57  m_doubleFormat = doubleFormat;
58  m_integerFormat = integerFormat;
59  };
60  private:
61  std::string getBaseType(Datapoint *dp, const std::string& format);
62  void sendContainer(std::string& link, Datapoint *dp, OMFHints * hints, const std::string& baseType);
63  bool isTypeSupported(DatapointValue& dataPoint)
64  {
65  switch (dataPoint.getType())
66  {
67  case DatapointValue::DatapointTag::T_FLOAT:
68  case DatapointValue::DatapointTag::T_INTEGER:
69  case DatapointValue::DatapointTag::T_STRING:
70  return true;
71  default:
72  return false;
73  }
74  };
75 
76  private:
77  bool m_sendFullStructure;
78  std::string m_delimiter;
79 
86  std::unordered_map<std::string, LALookup> *m_linkedAssetState;
87 
91  OMF_ENDPOINT m_endpoint;
92 
93 
97  std::string m_containers;
98  std::set<std::string> m_containerNames;
99  std::string m_doubleFormat;
100  std::string m_integerFormat;
101 
102 };
103 #endif
An encapsulation of an error return from an OMF call.
Definition: omferror.h:21
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:279
The OMFLinkedData class.
Definition: omflinkeddata.h:38
Name and value pair used to represent a data value within an asset reading.
Definition: datapoint.h:310
dataTagType getType() const
Return the Tag type.
Definition: datapoint.h:226
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:72
A set of hints for a reading.
Definition: OMFHint.h:151
An asset reading represented as a class.
Definition: reading.h:33
Class to hold an actual reading value.
Definition: datapoint.h:30
Definition: http_sender.h:20
Buffer class designed to hold OMF payloads that can grow as required but have minimal copy semantics...
Definition: omfbuffer.h:24
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:501