History

TimeSeriesPlatformLibrary: (1) Fixed issue with SignalReference parser, (2) converted tabs to spaces, (3) tested 64-bit compilation

J. Ritchie Carroll committed 8 years ago

Commit 3dfa6731 parent dab518924 files · +3167 −3043Browse files

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

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/AdvancedSubscribe.cpp+139−139
@@ -59,34 +59,34 @@ void RunSubscriber(string hostname, uint16_t port); · 58 unmodified lines
5959 // Measurements are transmitted via a separate UDP data channel.
6060 int main(int argc, char* argv[])
6161 {
62− string hostname;
63− uint16_t port;
64−
65− // Ensure that the necessary
66− // command line arguments are given.
67− if (argc < 3)
68− {
69− cout << "Usage:" << endl;
70− cout << " AdvancedSubscribe HOSTNAME PORT" << endl;
71− return 0;
72− }
73−
74− // Get hostname and port.
75− hostname = argv[1];
76− stringstream(argv[2]) >> port;
77−
78− // Run the subscriber.
79− RunSubscriber(hostname, port);
80−
81− // Wait until the user presses enter before quitting.
82− string line;
83− getline(cin, line);
84−
85− // Disconnect the subscriber to stop background threads.
86− Subscriber.Disconnect();
87− cout << "Disconnected." << endl;
88−
89− return 0;
62+ string hostname;
63+ uint16_t port;
64+
65+ // Ensure that the necessary
66+ // command line arguments are given.
67+ if (argc < 3)
68+ {
69+ cout << "Usage:" << endl;
70+ cout << " AdvancedSubscribe HOSTNAME PORT" << endl;
71+ return 0;
72+ }
73+
74+ // Get hostname and port.
75+ hostname = argv[1];
76+ stringstream(argv[2]) >> port;
77+
78+ // Run the subscriber.
79+ RunSubscriber(hostname, port);
80+
81+ // Wait until the user presses enter before quitting.
82+ string line;
83+ getline(cin, line);
84+
85+ // Disconnect the subscriber to stop background threads.
86+ Subscriber.Disconnect();
87+ cout << "Disconnected." << endl;
88+
89+ return 0;
9090 }
9191
9292 // The proper procedure when creating and running a subscriber is:
@@ -96,155 +96,155 @@ int main(int argc, char* argv[]) · 3 unmodified lines
9696 // - Subscribe
9797 void RunSubscriber(string hostname, uint16_t port)
9898 {
99− // The connector is declared here because it
100− // is only needed for the initial connection
101− SubscriberConnector connector;
102−
103− // Set up helper objects
104− connector = CreateSubscriberConnector(hostname, port);
105− Info = CreateSubscriptionInfo();
106−
107− // Register callbacks
108− Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage);
109− Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage);
110−
111− cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl;
112−
113− // Connect and subscribe to publisher
114− if (connector.Connect(Subscriber))
115− {
116− cout << "Connected! Subscribing to data..." << endl << endl;
117− Subscriber.Subscribe(Info);
118− }
119− else
120− {
121− cout << "Connection attempts exceeded. Press enter to exit." << endl;
122− }
99+ // The connector is declared here because it
100+ // is only needed for the initial connection
101+ SubscriberConnector connector;
102+
103+ // Set up helper objects
104+ connector = CreateSubscriberConnector(hostname, port);
105+ Info = CreateSubscriptionInfo();
106+
107+ // Register callbacks
108+ Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage);
109+ Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage);
110+
111+ cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl;
112+
113+ // Connect and subscribe to publisher
114+ if (connector.Connect(Subscriber))
115+ {
116+ cout << "Connected! Subscribing to data..." << endl << endl;
117+ Subscriber.Subscribe(Info);
118+ }
119+ else
120+ {
121+ cout << "Connection attempts exceeded. Press enter to exit." << endl;
122+ }
123123 }
124124
125125 SubscriptionInfo CreateSubscriptionInfo()
126126 {
127− // SubscriptionInfo is a helper object which allows the user
128− // to set up their subscription and reuse subscription settings.
129− SubscriptionInfo info;
130−
131− // The following filter expression formats are also available:
132− //
133− // - Signal ID list -
134− //info.FilterExpression = "7aaf0a8f-3a4f-4c43-ab43-ed9d1e64a255;"
135− // "93673c68-d59d-4926-b7e9-e7678f9f66b4;"
136− // "65ac9cf6-ae33-4ece-91b6-bb79343855d5;"
137− // "3647f729-d0ed-4f79-85ad-dae2149cd432;"
138− // "069c5e29-f78a-46f6-9dff-c92cb4f69371;"
139− // "25355a7b-2a9d-4ef2-99ba-4dd791461379";
140− //
141− // - Filter pattern -
142− //info.FilterExpression = "FILTER ActiveMeasurements WHERE ID LIKE 'PPA:*'";
143− //info.FilterExpression = "FILTER ActiveMeasurements WHERE Device = 'SHELBY' AND SignalType = 'FREQ'";
144−
145− 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";
146− info.NewMeasurementsCallback = &ProcessMeasurements;
147−
148− // To set up a remotely synchronized subscription, set this flag
149− // to true and add the framesPerSecond parameter to the
150− // ExtraConnectionStringParameters. Additionally, the following
151− // example demonstrates the use of some other useful parameters
152− // when setting up remotely synchronized subscriptions.
153− //
154− //info.RemotelySynchronized = true;
155− //info.ExtraConnectionStringParameters = "framesPerSecond=30;timeResolution=10000;downsamplingMethod=Closest";
156−
157− info.RemotelySynchronized = false;
158− info.Throttled = false;
159−
160− info.UdpDataChannel = true;
161− info.DataChannelLocalPort = 9600;
162−
163− info.IncludeTime = true;
164− info.LagTime = 3.0;
165− info.LeadTime = 1.0;
166− info.UseLocalClockAsRealTime = false;
167− info.UseMillisecondResolution = true;
168−
169− return info;
127+ // SubscriptionInfo is a helper object which allows the user
128+ // to set up their subscription and reuse subscription settings.
129+ SubscriptionInfo info;
130+
131+ // The following filter expression formats are also available:
132+ //
133+ // - Signal ID list -
134+ //info.FilterExpression = "7aaf0a8f-3a4f-4c43-ab43-ed9d1e64a255;"
135+ // "93673c68-d59d-4926-b7e9-e7678f9f66b4;"
136+ // "65ac9cf6-ae33-4ece-91b6-bb79343855d5;"
137+ // "3647f729-d0ed-4f79-85ad-dae2149cd432;"
138+ // "069c5e29-f78a-46f6-9dff-c92cb4f69371;"
139+ // "25355a7b-2a9d-4ef2-99ba-4dd791461379";
140+ //
141+ // - Filter pattern -
142+ //info.FilterExpression = "FILTER ActiveMeasurements WHERE ID LIKE 'PPA:*'";
143+ //info.FilterExpression = "FILTER ActiveMeasurements WHERE Device = 'SHELBY' AND SignalType = 'FREQ'";
144+
145+ 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";
146+ info.NewMeasurementsCallback = &ProcessMeasurements;
147+
148+ // To set up a remotely synchronized subscription, set this flag
149+ // to true and add the framesPerSecond parameter to the
150+ // ExtraConnectionStringParameters. Additionally, the following
151+ // example demonstrates the use of some other useful parameters
152+ // when setting up remotely synchronized subscriptions.
153+ //
154+ //info.RemotelySynchronized = true;
155+ //info.ExtraConnectionStringParameters = "framesPerSecond=30;timeResolution=10000;downsamplingMethod=Closest";
156+
157+ info.RemotelySynchronized = false;
158+ info.Throttled = false;
159+
160+ info.UdpDataChannel = true;
161+ info.DataChannelLocalPort = 9600;
162+
163+ info.IncludeTime = true;
164+ info.LagTime = 3.0;
165+ info.LeadTime = 1.0;
166+ info.UseLocalClockAsRealTime = false;
167+ info.UseMillisecondResolution = true;
168+
169+ return info;
170170 }
171171
172172 SubscriberConnector CreateSubscriberConnector(string hostname, uint16_t port)
173173 {
174− // SubscriberConnector is another helper object which allows the
175− // user to modify settings for auto-reconnects and retry cycles.
176− SubscriberConnector connector;
174+ // SubscriberConnector is another helper object which allows the
175+ // user to modify settings for auto-reconnects and retry cycles.
176+ SubscriberConnector connector;
177177
178− connector.RegisterErrorMessageCallback(&DisplayErrorMessage);
179− connector.RegisterReconnectCallback(&Resubscribe);
178+ connector.RegisterErrorMessageCallback(&DisplayErrorMessage);
179+ connector.RegisterReconnectCallback(&Resubscribe);
180180
181− connector.SetHostname(hostname);
182− connector.SetPort(port);
183− connector.SetMaxRetries(5);
184− connector.SetRetryInterval(1500);
185− connector.SetAutoReconnect(true);
181+ connector.SetHostname(hostname);
182+ connector.SetPort(port);
183+ connector.SetMaxRetries(5);
184+ connector.SetRetryInterval(1500);
185+ connector.SetAutoReconnect(true);
186186
187− return connector;
187+ return connector;
188188 }
189189
190190 // Callback which is called when the subscriber has
191191 // received a new packet of measurements from the publisher.
192192 void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements)
193193 {
194− const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
195− const size_t MaxTimestampSize = 80;
194+ const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
195+ const size_t MaxTimestampSize = 80;
196196
197− static int processCount = 0;
198− size_t i;
197+ static int processCount = 0;
198+ size_t i;
199199
200− char timestamp[MaxTimestampSize];
200+ char timestamp[MaxTimestampSize];
201201
202− // Only display messages every five
203− // seconds (assuming 30 calls per second).
204− if (processCount % 150 == 0)
205− {
206− cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
202+ // Only display messages every five
203+ // seconds (assuming 30 calls per second).
204+ if (processCount % 150 == 0)
205+ {
206+ cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
207207
208− if (!newMeasurements.empty())
209− {
210− if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp))
211− cout << "Timestamp: " << string(timestamp) << endl;
208+ if (!newMeasurements.empty())
209+ {
210+ if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp))
211+ cout << "Timestamp: " << string(timestamp) << endl;
212212
213− cout << "Point\tValue" << endl;
213+ cout << "Point\tValue" << endl;
214214
215− for (i = 0; i < newMeasurements.size(); ++i)
216− cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl;
215+ for (i = 0; i < newMeasurements.size(); ++i)
216+ cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl;
217217
218− cout << endl;
219− }
220− }
218+ cout << endl;
219+ }
220+ }
221221
222− ++processCount;
222+ ++processCount;
223223 }
224224
225225 // Callback that is called when the subscriber auto-reconnects.
226226 void Resubscribe(DataSubscriber* source)
227227 {
228− if (source->IsConnected())
229− {
230− cout << "Reconnected! Subscribing to data..." << endl << endl;
231− source->Subscribe(Info);
232− }
233− else
234− {
235− source->Disconnect();
236− cout << "Connection retry attempts exceeded. Press enter to exit." << endl;
237− }
228+ if (source->IsConnected())
229+ {
230+ cout << "Reconnected! Subscribing to data..." << endl << endl;
231+ source->Subscribe(Info);
232+ }
233+ else
234+ {
235+ source->Disconnect();
236+ cout << "Connection retry attempts exceeded. Press enter to exit." << endl;
237+ }
238238 }
239239
240240 // Callback which is called to display status messages from the subscriber.
241241 void DisplayStatusMessage(DataSubscriber* source, const string& message)
242242 {
243− cout << message << endl << endl;
243+ cout << message << endl << endl;
244244 }
245245
246246 // Callback which is called to display error messages from the connector and subscriber.
247247 void DisplayErrorMessage(DataSubscriber* source, const string& message)
248248 {
249− cerr << message << endl << endl;
249+ cerr << message << endl << endl;
250250 }

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