@@ -113,16 +113,12 @@ DoublePointValue Server::convertIntToDPValue(int value)
113
113
{
114
114
case 0 :
115
115
return IEC60870_DOUBLE_POINT_INTERMEDIATE;
116
- break ;
117
116
case 1 :
118
117
return IEC60870_DOUBLE_POINT_OFF;
119
- break ;
120
118
case 2 :
121
119
return IEC60870_DOUBLE_POINT_ON;
122
- break ;
123
120
case 3 :
124
121
return IEC60870_DOUBLE_POINT_INDETERMINATE;
125
- break ;
126
122
default :
127
123
return IEC60870_DOUBLE_POINT_INTERMEDIATE;
128
124
}
@@ -162,29 +158,20 @@ void Server::reversePollSinglePoint()
162
158
for (const auto &kv : gServer ->mBinaryPoints )
163
159
{
164
160
const std::string tag = kv.second .first ;
165
- if (CS101_ASDU_getPayloadSize (newAsdu) < MAX_ASDU_PAYLOAD_SIZE)
166
- {
167
- if (gServer ->mDataManager ->hasTag (tag))
168
- {
169
- auto status = gServer ->mDataManager ->getDataByTag <bool >(tag);
170
- InformationObject io = (InformationObject)SinglePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
171
- CS101_ASDU_addInformationObject (newAsdu, io);
172
- InformationObject_destroy (io);
173
- }
174
- }
175
- else
161
+ if (CS101_ASDU_getPayloadSize (newAsdu) >= MAX_ASDU_PAYLOAD_SIZE)
176
162
{
177
163
// Send current ASDU and create a new one for the remaining values
178
164
IMasterConnection_sendASDU (mConnection , newAsdu);
179
165
CS101_ASDU_destroy (newAsdu);
180
166
newAsdu = CS101_ASDU_create (alParams, false , CS101_COT_PERIODIC, 0 , 1 , false , false );
181
- if (gServer ->mDataManager ->hasTag (tag))
182
- {
183
- auto status = gServer ->mDataManager ->getDataByTag <bool >(tag);
184
- InformationObject io = (InformationObject)SinglePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
185
- CS101_ASDU_addInformationObject (newAsdu, io);
186
- InformationObject_destroy (io);
187
- }
167
+ }
168
+
169
+ if (gServer ->mDataManager ->hasTag (tag))
170
+ {
171
+ auto status = gServer ->mDataManager ->getDataByTag <bool >(tag);
172
+ InformationObject io = (InformationObject)SinglePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
173
+ CS101_ASDU_addInformationObject (newAsdu, io);
174
+ InformationObject_destroy (io);
188
175
}
189
176
}
190
177
IMasterConnection_sendASDU (mConnection , newAsdu);
@@ -196,29 +183,20 @@ void Server::reversePollSinglePoint()
196
183
for (const auto &kv : gServer ->mAnalogPoints )
197
184
{
198
185
const std::string tag = kv.second .first ;
199
- if (CS101_ASDU_getPayloadSize (newAsdu) < MAX_ASDU_PAYLOAD_SIZE)
200
- {
201
- if (gServer ->mDataManager ->hasTag (tag))
202
- {
203
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
204
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
205
- CS101_ASDU_addInformationObject (newAsdu, io);
206
- InformationObject_destroy (io);
207
- }
208
- }
209
- else
186
+ if (CS101_ASDU_getPayloadSize (newAsdu) >= MAX_ASDU_PAYLOAD_SIZE)
210
187
{
211
188
// Send current ASDU and create a new one for the remaining values
212
189
IMasterConnection_sendASDU (mConnection , newAsdu);
213
190
CS101_ASDU_destroy (newAsdu);
214
191
newAsdu = CS101_ASDU_create (alParams, false , CS101_COT_PERIODIC, 0 , 1 , false , false );
215
- if (gServer ->mDataManager ->hasTag (tag))
216
- {
217
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
218
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
219
- CS101_ASDU_addInformationObject (newAsdu, io);
220
- InformationObject_destroy (io);
221
- }
192
+ }
193
+
194
+ if (gServer ->mDataManager ->hasTag (tag))
195
+ {
196
+ auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
197
+ InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
198
+ CS101_ASDU_addInformationObject (newAsdu, io);
199
+ InformationObject_destroy (io);
222
200
}
223
201
}
224
202
IMasterConnection_sendASDU (mConnection , newAsdu);
@@ -259,29 +237,20 @@ void Server::reversePollDoublePoint()
259
237
for (const auto &kv : gServer ->mAnalogPoints )
260
238
{
261
239
const std::string tag = kv.second .first ;
262
- if (CS101_ASDU_getPayloadSize (newAsdu) < MAX_ASDU_PAYLOAD_SIZE)
263
- {
264
- if (gServer ->mDataManager ->hasTag (tag))
265
- {
266
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
267
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
268
- CS101_ASDU_addInformationObject (newAsdu, io);
269
- InformationObject_destroy (io);
270
- }
271
- }
272
- else
240
+ if (CS101_ASDU_getPayloadSize (newAsdu) >= MAX_ASDU_PAYLOAD_SIZE)
273
241
{
274
242
// Send current ASDU and create a new one for the remaining values
275
243
IMasterConnection_sendASDU (mConnection , newAsdu);
276
244
CS101_ASDU_destroy (newAsdu);
277
245
newAsdu = CS101_ASDU_create (alParams, false , CS101_COT_PERIODIC, 0 , 1 , false , false );
278
- if (gServer ->mDataManager ->hasTag (tag))
279
- {
280
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
281
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
282
- CS101_ASDU_addInformationObject (newAsdu, io);
283
- InformationObject_destroy (io);
284
- }
246
+ }
247
+
248
+ if (gServer ->mDataManager ->hasTag (tag))
249
+ {
250
+ auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
251
+ InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
252
+ CS101_ASDU_addInformationObject (newAsdu, io);
253
+ InformationObject_destroy (io);
285
254
}
286
255
}
287
256
IMasterConnection_sendASDU (mConnection , newAsdu);
@@ -320,7 +289,7 @@ void Server::rawMessageHandler(void *parameter, IMasterConnection con, uint8_t *
320
289
*/
321
290
bool Server::interrogationHandlerSinglePoint (void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi)
322
291
{
323
- printf ( " Received interrogation for group %i \n " , qoi);
292
+ std::cout << " Received interrogation for group " << static_cast < int16_t >( qoi) << std::endl ;
324
293
325
294
if (qoi == 20 ) /* only handle station interrogation */
326
295
{
@@ -333,29 +302,20 @@ bool Server::interrogationHandlerSinglePoint(void *parameter, IMasterConnection
333
302
for (const auto &kv : gServer ->mBinaryPoints )
334
303
{
335
304
const std::string tag = kv.second .first ;
336
- if (CS101_ASDU_getPayloadSize (newAsdu) < MAX_ASDU_PAYLOAD_SIZE)
337
- {
338
- if (gServer ->mDataManager ->hasTag (tag))
339
- {
340
- auto status = gServer ->mDataManager ->getDataByTag <bool >(tag);
341
- InformationObject io = (InformationObject)SinglePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
342
- CS101_ASDU_addInformationObject (newAsdu, io);
343
- InformationObject_destroy (io);
344
- }
345
- }
346
- else
305
+ if (CS101_ASDU_getPayloadSize (newAsdu) >= MAX_ASDU_PAYLOAD_SIZE)
347
306
{
348
307
// Send current ASDU and create a new one for the remaining values
349
308
IMasterConnection_sendASDU (connection, newAsdu);
350
309
CS101_ASDU_destroy (newAsdu);
351
310
newAsdu = CS101_ASDU_create (alParams, false , CS101_COT_INTERROGATED_BY_STATION, 0 , 1 , false , false );
352
- if (gServer ->mDataManager ->hasTag (tag))
353
- {
354
- auto status = gServer ->mDataManager ->getDataByTag <bool >(tag);
355
- InformationObject io = (InformationObject)SinglePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
356
- CS101_ASDU_addInformationObject (newAsdu, io);
357
- InformationObject_destroy (io);
358
- }
311
+ }
312
+
313
+ if (gServer ->mDataManager ->hasTag (tag))
314
+ {
315
+ auto status = gServer ->mDataManager ->getDataByTag <bool >(tag);
316
+ InformationObject io = (InformationObject)SinglePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
317
+ CS101_ASDU_addInformationObject (newAsdu, io);
318
+ InformationObject_destroy (io);
359
319
}
360
320
}
361
321
IMasterConnection_sendASDU (connection, newAsdu);
@@ -367,29 +327,20 @@ bool Server::interrogationHandlerSinglePoint(void *parameter, IMasterConnection
367
327
for (const auto &kv : gServer ->mAnalogPoints )
368
328
{
369
329
const std::string tag = kv.second .first ;
370
- if (CS101_ASDU_getPayloadSize (newAsdu) < MAX_ASDU_PAYLOAD_SIZE)
371
- {
372
- if (gServer ->mDataManager ->hasTag (tag))
373
- {
374
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
375
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
376
- CS101_ASDU_addInformationObject (newAsdu, io);
377
- InformationObject_destroy (io);
378
- }
379
- }
380
- else
330
+ if (CS101_ASDU_getPayloadSize (newAsdu) >= MAX_ASDU_PAYLOAD_SIZE)
381
331
{
382
332
// Send current ASDU and create a new one for the remaining values
383
333
IMasterConnection_sendASDU (connection, newAsdu);
384
334
CS101_ASDU_destroy (newAsdu);
385
335
newAsdu = CS101_ASDU_create (alParams, false , CS101_COT_INTERROGATED_BY_STATION, 0 , 1 , false , false );
386
- if (gServer ->mDataManager ->hasTag (tag))
387
- {
388
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
389
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
390
- CS101_ASDU_addInformationObject (newAsdu, io);
391
- InformationObject_destroy (io);
392
- }
336
+ }
337
+
338
+ if (gServer ->mDataManager ->hasTag (tag))
339
+ {
340
+ auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
341
+ InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
342
+ CS101_ASDU_addInformationObject (newAsdu, io);
343
+ InformationObject_destroy (io);
393
344
}
394
345
}
395
346
IMasterConnection_sendASDU (connection, newAsdu);
@@ -409,7 +360,7 @@ bool Server::interrogationHandlerSinglePoint(void *parameter, IMasterConnection
409
360
*/
410
361
bool Server::interrogationHandlerDoublePoint (void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi)
411
362
{
412
- printf ( " Received interrogation for group %i \n " , qoi);
363
+ std::cout << " Received interrogation for group " << static_cast < int16_t >( qoi) << std::endl ;
413
364
414
365
if (qoi == 20 ) /* only handle station interrogation */
415
366
{
@@ -422,29 +373,20 @@ bool Server::interrogationHandlerDoublePoint(void *parameter, IMasterConnection
422
373
for (const auto &kv : gServer ->mBinaryPoints )
423
374
{
424
375
const std::string tag = kv.second .first ;
425
- if (CS101_ASDU_getPayloadSize (newAsdu) < MAX_ASDU_PAYLOAD_SIZE)
426
- {
427
- if (gServer ->mDataManager ->hasTag (tag))
428
- {
429
- auto status = Server::convertBoolToDPValue (gServer ->mDataManager ->getDataByTag <bool >(tag));
430
- InformationObject io = (InformationObject)DoublePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
431
- CS101_ASDU_addInformationObject (newAsdu, io);
432
- InformationObject_destroy (io);
433
- }
434
- }
435
- else
376
+ if (CS101_ASDU_getPayloadSize (newAsdu) >= MAX_ASDU_PAYLOAD_SIZE)
436
377
{
437
378
// Send current ASDU and create a new one for the remaining values
438
379
IMasterConnection_sendASDU (connection, newAsdu);
439
380
CS101_ASDU_destroy (newAsdu);
440
381
newAsdu = CS101_ASDU_create (alParams, false , CS101_COT_INTERROGATED_BY_STATION, 0 , 1 , false , false );
441
- if (gServer ->mDataManager ->hasTag (tag))
442
- {
443
- auto status = Server::convertBoolToDPValue (gServer ->mDataManager ->getDataByTag <bool >(tag));
444
- InformationObject io = (InformationObject)DoublePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
445
- CS101_ASDU_addInformationObject (newAsdu, io);
446
- InformationObject_destroy (io);
447
- }
382
+ }
383
+
384
+ if (gServer ->mDataManager ->hasTag (tag))
385
+ {
386
+ auto status = Server::convertBoolToDPValue (gServer ->mDataManager ->getDataByTag <bool >(tag));
387
+ InformationObject io = (InformationObject)DoublePointInformation_create (NULL , kv.first , status, IEC60870_QUALITY_GOOD);
388
+ CS101_ASDU_addInformationObject (newAsdu, io);
389
+ InformationObject_destroy (io);
448
390
}
449
391
}
450
392
IMasterConnection_sendASDU (connection, newAsdu);
@@ -456,29 +398,20 @@ bool Server::interrogationHandlerDoublePoint(void *parameter, IMasterConnection
456
398
for (const auto &kv : gServer ->mAnalogPoints )
457
399
{
458
400
const std::string tag = kv.second .first ;
459
- if (CS101_ASDU_getPayloadSize (newAsdu) < MAX_ASDU_PAYLOAD_SIZE)
460
- {
461
- if (gServer ->mDataManager ->hasTag (tag))
462
- {
463
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
464
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
465
- CS101_ASDU_addInformationObject (newAsdu, io);
466
- InformationObject_destroy (io);
467
- }
468
- }
469
- else
401
+ if (CS101_ASDU_getPayloadSize (newAsdu) >= MAX_ASDU_PAYLOAD_SIZE)
470
402
{
471
403
// Send current ASDU and create a new one for the remaining values
472
404
IMasterConnection_sendASDU (connection, newAsdu);
473
405
CS101_ASDU_destroy (newAsdu);
474
406
newAsdu = CS101_ASDU_create (alParams, false , CS101_COT_INTERROGATED_BY_STATION, 0 , 1 , false , false );
475
- if (gServer ->mDataManager ->hasTag (tag))
476
- {
477
- auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
478
- InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
479
- CS101_ASDU_addInformationObject (newAsdu, io);
480
- InformationObject_destroy (io);
481
- }
407
+ }
408
+
409
+ if (gServer ->mDataManager ->hasTag (tag))
410
+ {
411
+ auto val = gServer ->mDataManager ->getDataByTag <double >(tag);
412
+ InformationObject io = (InformationObject)MeasuredValueShort_create (NULL , kv.first , val, IEC60870_QUALITY_GOOD);
413
+ CS101_ASDU_addInformationObject (newAsdu, io);
414
+ InformationObject_destroy (io);
482
415
}
483
416
}
484
417
IMasterConnection_sendASDU (connection, newAsdu);
@@ -497,7 +430,7 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
497
430
{
498
431
if (CS101_ASDU_getTypeID (asdu) == C_SC_NA_1)
499
432
{
500
- printf ( " received single command\n " ) ;
433
+ std::cout << " received single command" << std::endl ;
501
434
502
435
if (CS101_ASDU_getCOT (asdu) == CS101_COT_ACTIVATION)
503
436
{
@@ -515,8 +448,8 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
515
448
}
516
449
else
517
450
{
518
- printf ( " ERROR: message has no valid information object\n " ) ;
519
- return true ;
451
+ std::cout << " ERROR: message has no valid information object" << std::endl ;
452
+ return false ;
520
453
}
521
454
}
522
455
else
@@ -528,7 +461,7 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
528
461
}
529
462
else if (CS101_ASDU_getTypeID (asdu) == C_DC_NA_1)
530
463
{
531
- printf ( " received double command\n " ) ;
464
+ std::cout << " received double command" << std::endl ;
532
465
533
466
if (CS101_ASDU_getCOT (asdu) == CS101_COT_ACTIVATION)
534
467
{
@@ -550,12 +483,14 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
550
483
}
551
484
else
552
485
{
553
- printf ( " ERROR: message has no valid information object\n " ) ;
554
- return true ;
486
+ std::cout << " ERROR: message has no valid information object" << std::endl ;
487
+ return false ;
555
488
}
556
489
}
557
490
else
491
+ {
558
492
CS101_ASDU_setCOT (asdu, CS101_COT_UNKNOWN_COT);
493
+ }
559
494
560
495
IMasterConnection_sendASDU (connection, asdu);
561
496
0 commit comments