Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/AverageFrequencyCalculator.cpp (1 of 24 files). Show all
Unified · Split
| @@ -41,7 +41,7 @@ SubscriptionInfo CreateSubscriptionInfo(); · 40 unmodified lines | |||
| 41 | 41 | ||
| 42 | // Handlers for subscriber callbacks. | 42 | // Handlers for subscriber callbacks. |
| 43 | void Resubscribe(DataSubscriber* source); | 43 | void Resubscribe(DataSubscriber* source); |
| 44 | void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements); | 44 | void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements); |
| 45 | void DisplayStatusMessage(DataSubscriber* source, const string& message); | 45 | void DisplayStatusMessage(DataSubscriber* source, const string& message); |
| 46 | void DisplayErrorMessage(DataSubscriber* source, const string& message); | 46 | void DisplayErrorMessage(DataSubscriber* source, const string& message); |
| 47 | 47 | ||
| @@ -152,14 +152,14 @@ void SetupSubscriberConnector(SubscriberConnector& connector, string hostname, u · 104 unmodified lines | |||
| 152 | 152 | ||
| 153 | // Callback which is called when the subscriber has | 153 | // Callback which is called when the subscriber has |
| 154 | // received a new packet of measurements from the publisher. | 154 | // received a new packet of measurements from the publisher. |
| 155 | void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements) | 155 | void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& measurements) |
| 156 | { | 156 | { |
| 157 | const double LoFrequency = 57.0; | 157 | const float64_t LoFrequency = 57.0F; |
| 158 | const double HiFrequency = 62.0; | 158 | const float64_t HiFrequency = 62.0F; |
| 159 | const double HzResolution = 1000.0; // three decimal places | 159 | const float64_t HzResolution = 1000.0; // three decimal places |
| 160 | 160 | ||
| 161 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; | 161 | const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f"; |
| 162 | const size_t MaxTimestampSize = 80; | 162 | const uint32_t MaxTimestampSize = 80; |
| 163 | 163 | ||
| 164 | static map<Guid, int> m_lastValues; | 164 | static map<Guid, int> m_lastValues; |
| 165 | 165 | ||
| @@ -167,40 +167,39 @@ void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& n · 1 unmodified line | |||
| 167 | MeasurementPtr currentMeasurement; | 167 | MeasurementPtr currentMeasurement; |
| 168 | Guid signalID; | 168 | Guid signalID; |
| 169 | 169 | ||
| 170 | double frequency; | 170 | float64_t frequency; |
| 171 | double frequencyTotal; | 171 | float64_t frequencyTotal; |
| 172 | double maximumFrequency = LoFrequency; | 172 | float64_t maximumFrequency = LoFrequency; |
| 173 | double minimumFrequency = HiFrequency; | 173 | float64_t minimumFrequency = HiFrequency; |
| 174 | int adjustedFrequency; | 174 | int32_t adjustedFrequency; |
| 175 | int lastValue; | 175 | int32_t lastValue; |
| 176 | int total; | 176 | int32_t total; |
| 177 | 177 | ||
| 178 | char timestamp[MaxTimestampSize]; | 178 | char timestamp[MaxTimestampSize]; |
| 179 | size_t i; | ||
| 180 | 179 | ||
| 181 | frequencyTotal = 0.0; | 180 | frequencyTotal = 0.0; |
| 182 | total = 0; | 181 | total = 0; |
| 183 | 182 | ||
| 184 | cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; | 183 | cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl; |
| 185 | 184 | ||
| 186 | if (!newMeasurements.empty()) | 185 | if (!measurements.empty()) |
| 187 | { | 186 | { |
| 188 | if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp)) | 187 | if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp)) |
| 189 | cout << "Timestamp: " << string(timestamp) << endl; | 188 | cout << "Timestamp: " << string(timestamp) << endl; |
| 190 | 189 | ||
| 191 | cout << "Point\tValue" << endl; | 190 | cout << "Point\tValue" << endl; |
| 192 | 191 | ||
| 193 | for (i = 0; i < newMeasurements.size(); ++i) | 192 | for (uint32_t i = 0; i < measurements.size(); ++i) |
| 194 | cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl; | 193 | cout << measurements[i]->ID << '\t' << measurements[i]->Value << endl; |
| 195 | 194 | ||
| 196 | cout << endl; | 195 | cout << endl; |
| 197 | 196 | ||
| 198 | for (i = 0; i < newMeasurements.size(); ++i) | 197 | for (uint32_t i = 0; i < measurements.size(); ++i) |
| 199 | { | 198 | { |
| 200 | currentMeasurement = newMeasurements[i]; | 199 | currentMeasurement = measurements[i]; |
| 201 | frequency = currentMeasurement->Value; | 200 | frequency = currentMeasurement->Value; |
| 202 | signalID = currentMeasurement->SignalID; | 201 | signalID = currentMeasurement->SignalID; |
| 203 | adjustedFrequency = static_cast<int>(frequency * HzResolution); | 202 | adjustedFrequency = static_cast<int32_t>(frequency * HzResolution); |
| 204 | 203 | ||
| 205 | // Do some simple flat line avoidance... | 204 | // Do some simple flat line avoidance... |
| 206 | lastValueIter = m_lastValues.find(signalID); | 205 | lastValueIter = m_lastValues.find(signalID); |