Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimpleSubscribe.cpp (1 of 24 files). Show all
Unified · Split
| @@ -35,7 +35,7 @@ using namespace GSF::TimeSeries::Transport; · 34 unmodified lines | ||
| 35 | 35 | DataSubscriber Subscriber; |
| 36 | 36 | |
| 37 | 37 | bool RunSubscriber(string hostname, uint16_t port); |
| 38 | −void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements); | |
| 38 | +void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements); | |
| 39 | 39 | void DisplayStatusMessage(DataSubscriber* source, const string& message); |
| 40 | 40 | void DisplayErrorMessage(DataSubscriber* source, const string& message); |
| 41 | 41 | |
| @@ -136,37 +136,38 @@ bool RunSubscriber(string hostname, uint16_t port) · 94 unmodified lines | ||
| 136 | 136 | |
| 137 | 137 | // Callback which is called when the subscriber has |
| 138 | 138 | // received a new packet of measurements from the publisher. |
| 139 | −void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements) | |
| 139 | +void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements) | |
| 140 | 140 | { |
| 141 | 141 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; |
| 142 | − const size_t MaxTimestampSize = 80; | |
| 142 | + const uint32_t MaxTimestampSize = 80; | |
| 143 | 143 | |
| 144 | − static int processCount = 0; | |
| 145 | − size_t i; | |
| 144 | + static long processCount = 0; | |
| 145 | + static char timestamp[MaxTimestampSize]; | |
| 146 | + static const long interval = 5 * 60; | |
| 147 | + const long measurementCount = measurements.size(); | |
| 148 | + const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval); | |
| 146 | 149 | |
| 147 | − char timestamp[MaxTimestampSize]; | |
| 150 | + processCount += measurementCount; | |
| 148 | 151 | |
| 149 | − // Only display messages every five | |
| 150 | − // seconds (assuming 30 calls per second). | |
| 151 | − if (processCount % 150 == 0) | |
| 152 | + // Only display messages every few seconds | |
| 153 | + if (showMessage) | |
| 152 | 154 | { |
| 153 | − cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | |
| 155 | + stringstream message; | |
| 154 | 156 | |
| 155 | − if (!newMeasurements.empty()) | |
| 156 | − { | |
| 157 | − if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp)) | |
| 158 | − cout << "Timestamp: " << string(timestamp) << endl; | |
| 157 | + message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | |
| 159 | 158 | |
| 160 | − cout << "Point\tValue" << endl; | |
| 159 | + if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) | |
| 160 | + message << "Timestamp: " << string(timestamp) << endl; | |
| 161 | 161 | |
| 162 | − for (i = 0; i < newMeasurements.size(); ++i) | |
| 163 | − cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl; | |
| 162 | + message << "Point\tValue" << endl; | |
| 164 | 163 | |
| 165 | − cout << endl; | |
| 166 | − } | |
| 167 | − } | |
| 164 | + for (const auto& measurement : measurements) | |
| 165 | + message << measurement->ID << '\t' << measurement->Value << endl; | |
| 166 | + | |
| 167 | + message << endl; | |
| 168 | 168 | |
| 169 | − ++processCount; | |
| 169 | + cout << message.str(); | |
| 170 | + } | |
| 170 | 171 | } |
| 171 | 172 | |
| 172 | 173 | // Callback which is called to display status messages from the subscriber. |