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/SimpleSubscribe.cpp (1 of 24 files). Show all

Unified · Split

Source/Libraries/TimeSeriesPlatformLibrary/Samples/SimpleSubscribe.cpp+66−66
@@ -50,34 +50,34 @@ void DisplayErrorMessage(DataSubscriber* source, const string& message); · 49 unmodified lines
5050 // Measurements are transmitted via the TCP command channel.
5151 int main(int argc, char* argv[])
5252 {
53− string hostname;
54− uint16_t port;
55−
56− // Ensure that the necessary
57− // command line arguments are given.
58− if (argc < 3)
59− {
60− cout << "Usage:" << endl;
61− cout << " SimpleSubscribe HOSTNAME PORT" << endl;
62− return 0;
63− }
64−
65− // Get hostname and port.
66− hostname = argv[1];
67− stringstream(argv[2]) >> port;
68−
69− // Run the subscriber.
70− RunSubscriber(hostname, port);
71−
72− // Wait until the user presses enter before quitting.
73− string line;
74− getline(cin, line);
75−
76− // Disconnect the subscriber to stop background threads.
77− Subscriber.Disconnect();
78− cout << "Disconnected." << endl;
79−
80− return 0;
53+ string hostname;
54+ uint16_t port;
55+
56+ // Ensure that the necessary
57+ // command line arguments are given.
58+ if (argc < 3)
59+ {
60+ cout << "Usage:" << endl;
61+ cout << " SimpleSubscribe HOSTNAME PORT" << endl;
62+ return 0;
63+ }
64+
65+ // Get hostname and port.
66+ hostname = argv[1];
67+ stringstream(argv[2]) >> port;
68+
69+ // Run the subscriber.
70+ RunSubscriber(hostname, port);
71+
72+ // Wait until the user presses enter before quitting.
73+ string line;
74+ getline(cin, line);
75+
76+ // Disconnect the subscriber to stop background threads.
77+ Subscriber.Disconnect();
78+ cout << "Disconnected." << endl;
79+
80+ return 0;
8181 }
8282
8383 // The proper procedure when creating and running a subscriber is:
@@ -87,66 +87,66 @@ int main(int argc, char* argv[]) · 3 unmodified lines
8787 // - Subscribe
8888 void RunSubscriber(string hostname, uint16_t port)
8989 {
90− // SubscriptionInfo is a helper object which allows the user
91− // to set up their subscription and reuse subscription settings.
92− SubscriptionInfo info;
93− 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";
94−
95− // Register callbacks
96− Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage);
97− Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage);
98− Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements);
99−
100− cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl;
101− Subscriber.Connect(hostname, port);
102−
103− cout << "Connected! Subscribing to data..." << endl << endl;
104− Subscriber.Subscribe(info);
90+ // SubscriptionInfo is a helper object which allows the user
91+ // to set up their subscription and reuse subscription settings.
92+ SubscriptionInfo info;
93+ 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";
94+
95+ // Register callbacks
96+ Subscriber.RegisterStatusMessageCallback(&DisplayStatusMessage);
97+ Subscriber.RegisterErrorMessageCallback(&DisplayErrorMessage);
98+ Subscriber.RegisterNewMeasurementsCallback(&ProcessMeasurements);
99+
100+ cout << endl << "Connecting to " << hostname << ":" << port << "..." << endl << endl;
101+ Subscriber.Connect(hostname, port);
102+
103+ cout << "Connected! Subscribing to data..." << endl << endl;
104+ Subscriber.Subscribe(info);
105105 }
106106
107107 // Callback which is called when the subscriber has
108108 // received a new packet of measurements from the publisher.
109109 void ProcessMeasurements(DataSubscriber* source, const vector<MeasurementPtr>& newMeasurements)
110110 {
111− const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
112− const size_t MaxTimestampSize = 80;
111+ const string TimestampFormat = "%Y-%m-%d %H:%M:%S.%f";
112+ const size_t MaxTimestampSize = 80;
113113
114− static int processCount = 0;
115− size_t i;
114+ static int processCount = 0;
115+ size_t i;
116116
117− char timestamp[MaxTimestampSize];
117+ char timestamp[MaxTimestampSize];
118118
119− // Only display messages every five
120− // seconds (assuming 30 calls per second).
121− if (processCount % 150 == 0)
122− {
123− cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
119+ // Only display messages every five
120+ // seconds (assuming 30 calls per second).
121+ if (processCount % 150 == 0)
122+ {
123+ cout << source->GetTotalMeasurementsReceived() << " measurements received so far..." << endl;
124124
125− if (!newMeasurements.empty())
126− {
127− if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp))
128− cout << "Timestamp: " << string(timestamp) << endl;
125+ if (!newMeasurements.empty())
126+ {
127+ if (TicksToString(timestamp, MaxTimestampSize, TimestampFormat, newMeasurements[0]->Timestamp))
128+ cout << "Timestamp: " << string(timestamp) << endl;
129129
130− cout << "Point\tValue" << endl;
130+ cout << "Point\tValue" << endl;
131131
132− for (i = 0; i < newMeasurements.size(); ++i)
133− cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl;
132+ for (i = 0; i < newMeasurements.size(); ++i)
133+ cout << newMeasurements[i]->ID << '\t' << newMeasurements[i]->Value << endl;
134134
135− cout << endl;
136− }
137− }
135+ cout << endl;
136+ }
137+ }
138138
139− ++processCount;
139+ ++processCount;
140140 }
141141
142142 // Callback which is called to display status messages from the subscriber.
143143 void DisplayStatusMessage(DataSubscriber* source, const string& message)
144144 {
145− cout << message << endl << endl;
145+ cout << message << endl << endl;
146146 }
147147
148148 // Callback which is called to display error messages from the connector and subscriber.
149149 void DisplayErrorMessage(DataSubscriber* source, const string& message)
150150 {
151− cerr << message << endl << endl;
151+ cerr << message << endl << endl;
152152 }

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