@@ -185,7 +185,7 @@ namespace mtconnect {
185
185
}
186
186
}
187
187
188
- auto seq = m_sinkContract-> getCircularBuffer (). getSequence ( );
188
+ auto seq = publishCurrent (boost:: system ::error_code {} );
189
189
for (auto &dev : m_sinkContract->getDevices ())
190
190
{
191
191
FilterSet filterSet = filterForDevice (dev);
@@ -197,10 +197,8 @@ namespace mtconnect {
197
197
sampler->observe (seq, [this ](const std::string &id) {
198
198
return m_sinkContract->getDataItemById (id).get ();
199
199
});
200
- sampler-> handlerCompleted ( );
200
+ publishSample (sampler );
201
201
}
202
-
203
- publishCurrent (boost::system ::error_code {});
204
202
}
205
203
206
204
// / @brief publish sample when observations arrive.
@@ -244,18 +242,20 @@ namespace mtconnect {
244
242
return end;
245
243
}
246
244
247
- void Mqtt2Service::publishCurrent (boost::system::error_code ec)
245
+ SequenceNumber_t Mqtt2Service::publishCurrent (boost::system::error_code ec)
248
246
{
247
+ SequenceNumber_t firstSeq, seq = 0 ;
248
+
249
249
if (ec)
250
250
{
251
251
LOG (warning) << " Mqtt2Service::publishCurrent: " << ec.message ();
252
- return ;
252
+ return 0 ;
253
253
}
254
254
255
255
if (!m_client->isRunning () || !m_client->isConnected ())
256
256
{
257
257
LOG (warning) << " Mqtt2Service::publishCurrent: client stopped" ;
258
- return ;
258
+ return 0 ;
259
259
}
260
260
261
261
for (auto &device : m_sinkContract->getDevices ())
@@ -264,7 +264,6 @@ namespace mtconnect {
264
264
LOG (debug) << " Publishing current for: " << topic;
265
265
266
266
ObservationList observations;
267
- SequenceNumber_t firstSeq, seq;
268
267
auto filterSet = filterForDevice (device);
269
268
270
269
{
@@ -288,6 +287,8 @@ namespace mtconnect {
288
287
m_currentTimer.expires_after (m_currentInterval);
289
288
m_currentTimer.async_wait (boost::asio::bind_executor (
290
289
m_strand, boost::bind (&Mqtt2Service::publishCurrent, this , _1)));
290
+
291
+ return seq;
291
292
}
292
293
293
294
bool Mqtt2Service::publish (observation::ObservationPtr &observation)
@@ -325,8 +326,9 @@ namespace mtconnect {
325
326
326
327
LOG (debug) << " Publishing Asset to topic: " << topic;
327
328
328
- auto doc = m_jsonPrinter->print (asset);
329
-
329
+ asset::AssetList list {asset};
330
+ auto doc = m_printer->printAssets (
331
+ m_instanceId, uint32_t (m_sinkContract->getAssetStorage ()->getMaxAssets ()), 1 , list);
330
332
stringstream buffer;
331
333
buffer << doc;
332
334
0 commit comments