History

TimeSeriesPlatformLibrary: Updated SimplePublish sample to properly run.

J. Ritchie Carroll committed 7 years ago

Commit 4d190cd1 parent 285fcea7 files · +108 −99Browse files

Showing the changes to Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimplePublish.cpp (1 of 7 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimplePublish.cpp+45−56
@@ -23,9 +23,7 @@ · 22 unmodified lines
23 23
24#include <iostream>24#include <iostream>
25#include <string>25#include <string>
26#include <vector>
27 26
28#include "../Common/Convert.h"
29#include "../Transport/DataPublisher.h"27#include "../Transport/DataPublisher.h"
30 28
31using namespace std;29using namespace std;
@@ -33,7 +31,7 @@ using namespace GSF; · 1 unmodified line
33using namespace GSF::TimeSeries;31using namespace GSF::TimeSeries;
34using namespace GSF::TimeSeries::Transport;32using namespace GSF::TimeSeries::Transport;
35 33
36DataPublisher Subscriber;34DataPublisherPtr Publisher;
37 35
38bool RunPublisher(uint16_t port);36bool RunPublisher(uint16_t port);
39//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements);37//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements);
@@ -86,27 +84,15 @@ int main(int argc, char* argv[]) · 46 unmodified lines
86// - Publish84// - Publish
87bool RunPublisher(uint16_t port)85bool RunPublisher(uint16_t port)
88{86{
89 // SubscriptionInfo is a helper object which allows the user
90 // to set up their subscription and reuse subscription settings.
91 //SubscriptionInfo info;
92 //info.FilterExpression = "PPA:1;PPA:2;PPA:3;PPA:4;PPA:5;PPA:6;PPA:7;PPA:8;PPA:9;PPA:10;PPA:11;PPA:12;PPA:13;PPA:14";
93
94 // Register callbacks
95 Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage);
96 Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage);
97 //Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements);
98
99 cout << endl << "Listening on port: " << port << "..." << endl << endl;
100
101 string errorMessage;87 string errorMessage;
102 bool connected = false;88 bool connected = false;
103 89
104 try90 try
105 {91 {
106 //Subscriber.Connect(hostname, port);92 Publisher = NewSharedPtr<DataPublisher>(port);
107 connected = true;93 connected = true;
108 }94 }
109 catch (SubscriberException& ex)95 catch (PublisherException& ex)
110 {96 {
111 errorMessage = ex.what();97 errorMessage = ex.what();
112 }98 }
@@ -116,57 +102,60 @@ bool RunPublisher(uint16_t port) · 3 unmodified lines
116 }102 }
117 catch (...)103 catch (...)
118 {104 {
119 errorMessage = current_exception_diagnostic_information(true);105 errorMessage = boost::current_exception_diagnostic_information(true);
120 }106 }
121 107
122 if (connected)108 if (connected)
123 {109 {
124 cout << "Connected! Subscribing to data..." << endl << endl;110 cout << endl << "Listening on port: " << port << "..." << endl << endl;
125 Subscriber.Subscribe(info);111
112 // Register callbacks
113 Publisher->RegisterStatusMessageCallback(&DisplayStatusMessage);
114 Publisher->RegisterErrorMessageCallback(&DisplayErrorMessage);
126 }115 }
127 else116 else
128 {117 {
129 cerr << "Failed to connect to \"" << hostname << ":" << port << "\": " << errorMessage;118 cerr << "Failed to listen on port: " << port << ": " << errorMessage;
130 }119 }
131 120
132 return connected;121 return connected;
133}122}
134 123
135// Callback which is called when the subscriber has124//// Callback which is called when the subscriber has
136// received a new packet of measurements from the publisher.125//// received a new packet of measurements from the publisher.
137void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements)126//void ProcessMeasurements(DataPublisher* source, const vector<MeasurementPtr>& measurements)
138{127//{
139 const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";128// const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
140 const uint32_t MaxTimestampSize = 80;129// const uint32_t MaxTimestampSize = 80;
141 130//
142 static long processCount = 0;131// static long processCount = 0;
143 static char timestamp[MaxTimestampSize];132// static char timestamp[MaxTimestampSize];
144 static const long interval = 5 * 60;133// static const long interval = 5 * 60;
145 const long measurementCount = measurements.size();134// const long measurementCount = measurements.size();
146 const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval);135// const bool showMessage = (processCount + measurementCount >= (processCount / interval + 1) * interval);
147 136//
148 processCount += measurementCount;137// processCount += measurementCount;
149 138//
150 // Only display messages every few seconds139// // Only display messages every few seconds
151 if (showMessage)140// if (showMessage)
152 {141// {
153 stringstream message;142// stringstream message;
154 143//
155 message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;144// message << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
156 145//
157 if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp))146// if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, measurements[0]->Timestamp))
158 message << "Timestamp: " << string(timestamp) << endl;147// message << "Timestamp: " << string(timestamp) << endl;
159 148//
160 message << "Point\tValue" << endl;149// message << "Point\tValue" << endl;
161 150//
162 for (const auto& measurement : measurements)151// for (const auto& measurement : measurements)
163 message << measurement->ID << '\t' << measurement->Value << endl;152// message << measurement->ID << '\t' << measurement->Value << endl;
164 153//
165 message << endl;154// message << endl;
166 155//
167 cout << message.str();156// cout << message.str();
168 }157// }
169}158//}
170 159
171// Callback which is called to display status messages from the subscriber.160// Callback which is called to display status messages from the subscriber.
172void DisplayStatusMessage(DataPublisher* source, const string& message)161void DisplayStatusMessage(DataPublisher* source, const string& message)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t