Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/SubscriberHandler.cpp (1 of 18 files). Show all
Unified · Split
| @@ -27,6 +27,7 @@ · 26 unmodified lines | |||
| 27 | #include "../Common/Convert.h" | 27 | #include "../Common/Convert.h" |
| 28 | #include <boost/lexical_cast.hpp> | 28 | #include <boost/lexical_cast.hpp> |
| 29 | #include <boost/uuid/uuid_io.hpp> | 29 | #include <boost/uuid/uuid_io.hpp> |
| 30 | #include <iostream> | ||
| 30 | 31 | ||
| 31 | using namespace std; | 32 | using namespace std; |
| 32 | using namespace GSF::TimeSeries; | 33 | using namespace GSF::TimeSeries; |
| @@ -107,77 +108,77 @@ void SubscriberHandler::ParsedMetadata() · 74 unmodified lines | |||
| 107 | void SubscriberHandler::ReceivedNewMeasurements(const vector<MeasurementPtr>& measurements) | 108 | void SubscriberHandler::ReceivedNewMeasurements(const vector<MeasurementPtr>& measurements) |
| 108 | { | 109 | { |
| 109 | // Start processing measurements | 110 | // Start processing measurements |
| 110 | for (auto &measurement : measurements) | 111 | //for (auto &measurement : measurements) |
| 111 | { | 112 | //{ |
| 112 | time_t soc; | 113 | // time_t soc; |
| 113 | uint16_t milliseconds; | 114 | // uint16_t milliseconds; |
| 114 | 115 | ||
| 115 | // Get adjusted value | 116 | // // Get adjusted value |
| 116 | const float64_t value = measurement->AdjustedValue(); | 117 | // const float64_t value = measurement->AdjustedValue(); |
| 117 | 118 | ||
| 118 | // Get time converted to UNIX second of century plus milliseconds | 119 | // // Get time converted to UNIX second of century plus milliseconds |
| 119 | measurement->GetUnixTime(soc, milliseconds); | 120 | // measurement->GetUnixTime(soc, milliseconds); |
| 120 | 121 | ||
| 121 | // Handle per measurement quality flags | 122 | // // Handle per measurement quality flags |
| 122 | int32_t qualityFlags = measurement->Flags; | 123 | // int32_t qualityFlags = measurement->Flags; |
| 123 | 124 | ||
| 124 | ConfigurationFramePtr configurationFrame; | 125 | // ConfigurationFramePtr configurationFrame; |
| 125 | MeasurementMetadataPtr measurementMetadata; | 126 | // MeasurementMetadataPtr measurementMetadata; |
| 126 | 127 | ||
| 127 | // Find associated configuration for measurement | 128 | // // Find associated configuration for measurement |
| 128 | if (TryFindTargetConfigurationFrame(measurement->SignalID, configurationFrame)) | 129 | // if (TryFindTargetConfigurationFrame(measurement->SignalID, configurationFrame)) |
| 129 | { | 130 | // { |
| 130 | // Lookup measurement metadata - it's faster to find metadata from within configuration frame | 131 | // // Lookup measurement metadata - it's faster to find metadata from within configuration frame |
| 131 | if (TryGetMeasurementMetdataFromConfigurationFrame(measurement->SignalID, configurationFrame, measurementMetadata)) | 132 | // if (TryGetMeasurementMetdataFromConfigurationFrame(measurement->SignalID, configurationFrame, measurementMetadata)) |
| 132 | { | 133 | // { |
| 133 | const SignalReference& reference = measurementMetadata->Reference; | 134 | // const SignalReference& reference = measurementMetadata->Reference; |
| 134 | 135 | ||
| 135 | // reference.Acronym << target device acronym | 136 | // // reference.Acronym << target device acronym |
| 136 | // reference.Kind << kind of signal (see SignalKind in "Types.h"), like Frequency, Angle, etc | 137 | // // reference.Kind << kind of signal (see SignalKind in "Types.h"), like Frequency, Angle, etc |
| 137 | // reference.Index << for Phasors, Analogs and Digitals - this is the ordered "index" | 138 | // // reference.Index << for Phasors, Analogs and Digitals - this is the ordered "index" |
| 138 | 139 | ||
| 139 | // TODO: Handle measurement processing here... | 140 | // // TODO: Handle measurement processing here... |
| 140 | } | 141 | // } |
| 141 | } | 142 | // } |
| 142 | else if (TryGetMeasurementMetdata(measurement->SignalID, measurementMetadata)) | 143 | // else if (TryGetMeasurementMetdata(measurement->SignalID, measurementMetadata)) |
| 143 | { | 144 | // { |
| 144 | // Received measurement is not part of a defined configuration frame, e.g., a statistic | 145 | // // Received measurement is not part of a defined configuration frame, e.g., a statistic |
| 145 | const SignalReference& reference = measurementMetadata->Reference; | 146 | // const SignalReference& reference = measurementMetadata->Reference; |
| 146 | } | 147 | // } |
| 147 | } | 148 | //} |
| 148 | 149 | ||
| 149 | // TODO: *** Temporary Testing Code Below *** -- REMOVE BEFORE USE | 150 | // TODO: *** Temporary Testing Code Below *** -- REMOVE BEFORE USE |
| 150 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; | 151 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; |
| 151 | const uint32_t MaxTimestampSize = 80; | 152 | const uint32_t MaxTimestampSize = 80; |
| 152 | 153 | ||
| 153 | static long processCount = 0; | 154 | //static long processCount = 0; |
| 154 | static char timestamp[MaxTimestampSize]; | 155 | static char timestamp[MaxTimestampSize]; |
| 155 | static const long interval = 5 * 60; | 156 | //static const long interval = 5 * 60; |
| 156 | const long measurementCount = measurements.size(); | 157 | //const long measurementCount = measurements.size(); |
| 157 | const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval); | 158 | const bool showMessage = true; // (processCount + measurementCount >= (processCount / interval + 1) * interval); |
| 158 | 159 | ||
| 159 | processCount += measurementCount; | 160 | //processCount += measurementCount; |
| 160 | 161 | ||
| 161 | // Only display messages every few seconds | 162 | // Only display messages every few seconds |
| 162 | if (showMessage) | 163 | if (showMessage) |
| 163 | { | 164 | { |
| 164 | stringstream message; | 165 | stringstream message; |
| 165 | 166 | ||
| 166 | message << GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | 167 | //message << GetTotalMeasurementsReceived() << " measurements received so far..." << endl; |
| 167 | 168 | ||
| 168 | if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) | 169 | if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) |
| 169 | message << "Timestamp: " << string(timestamp) << endl; | 170 | message << string(timestamp); |
| 170 | 171 | ||
| 171 | message << "Signal ID: " << boost::lexical_cast<string>(measurements[0]->SignalID) << endl; | 172 | //message << "Signal ID: " << boost::lexical_cast<string>(measurements[0]->SignalID) << endl; |
| 172 | 173 | ||
| 173 | message << "Point\tValue" << endl; | 174 | //message << "Point\tValue" << endl; |
| 174 | 175 | ||
| 175 | for (const auto& measurement : measurements) | 176 | for (const auto& measurement : measurements) |
| 176 | message << measurement->ID << '\t' << measurement->Value << endl; | 177 | message << '\t' << measurement->ID << '\t' << measurement->Value; |
| 177 | 178 | ||
| 178 | message << endl; | 179 | message << '\t' << GetTotalMeasurementsReceived() << endl; |
| 179 | 180 | ||
| 180 | StatusMessage(message.str()); | 181 | cout << message.str(); |
| 181 | } | 182 | } |
| 182 | } | 183 | } |
| 183 | 184 | ||
| @@ -194,6 +195,7 @@ void SubscriberHandler::HistoricalReadComplete() · 10 unmodified lines | |||
| 194 | void SubscriberHandler::ConnectionEstablished() | 195 | void SubscriberHandler::ConnectionEstablished() |
| 195 | { | 196 | { |
| 196 | StatusMessage("Connection established."); | 197 | StatusMessage("Connection established."); |
| 198 | |||
| 197 | } | 199 | } |
| 198 | 200 | ||
| 199 | void SubscriberHandler::ConnectionTerminated() | 201 | void SubscriberHandler::ConnectionTerminated() |