Skip to content

Commit 17e6cb3

Browse files
committed
Edits and cleanup for merge
1 parent 1a6ba34 commit 17e6cb3

File tree

2 files changed

+74
-139
lines changed

2 files changed

+74
-139
lines changed

src/bennu/devices/modules/comms/iec60870-5/module/ClientConnection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ bool ClientConnection::asduReceivedHandler(void* parameter, int address, CS101_A
229229
}
230230
else
231231
{
232-
printf("IOA: %i- Double point value is in indetrminate state..defaulting to 0\n", addr);
232+
printf("IOA: %i- Double point value is in indeterminate state..defaulting to 0\n", addr);
233233
status = 0;
234234
}
235235
printf(" IOA: %i value: %i\n", addr, status);

src/bennu/devices/modules/comms/iec60870-5/module/Server.cpp

+73-138
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,12 @@ DoublePointValue Server::convertIntToDPValue(int value)
113113
{
114114
case 0:
115115
return IEC60870_DOUBLE_POINT_INTERMEDIATE;
116-
break;
117116
case 1:
118117
return IEC60870_DOUBLE_POINT_OFF;
119-
break;
120118
case 2:
121119
return IEC60870_DOUBLE_POINT_ON;
122-
break;
123120
case 3:
124121
return IEC60870_DOUBLE_POINT_INDETERMINATE;
125-
break;
126122
default:
127123
return IEC60870_DOUBLE_POINT_INTERMEDIATE;
128124
}
@@ -162,29 +158,20 @@ void Server::reversePollSinglePoint()
162158
for (const auto &kv : gServer->mBinaryPoints)
163159
{
164160
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)
176162
{
177163
// Send current ASDU and create a new one for the remaining values
178164
IMasterConnection_sendASDU(mConnection, newAsdu);
179165
CS101_ASDU_destroy(newAsdu);
180166
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);
188175
}
189176
}
190177
IMasterConnection_sendASDU(mConnection, newAsdu);
@@ -196,29 +183,20 @@ void Server::reversePollSinglePoint()
196183
for (const auto &kv : gServer->mAnalogPoints)
197184
{
198185
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)
210187
{
211188
// Send current ASDU and create a new one for the remaining values
212189
IMasterConnection_sendASDU(mConnection, newAsdu);
213190
CS101_ASDU_destroy(newAsdu);
214191
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);
222200
}
223201
}
224202
IMasterConnection_sendASDU(mConnection, newAsdu);
@@ -259,29 +237,20 @@ void Server::reversePollDoublePoint()
259237
for (const auto &kv : gServer->mAnalogPoints)
260238
{
261239
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)
273241
{
274242
// Send current ASDU and create a new one for the remaining values
275243
IMasterConnection_sendASDU(mConnection, newAsdu);
276244
CS101_ASDU_destroy(newAsdu);
277245
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);
285254
}
286255
}
287256
IMasterConnection_sendASDU(mConnection, newAsdu);
@@ -320,7 +289,7 @@ void Server::rawMessageHandler(void *parameter, IMasterConnection con, uint8_t *
320289
*/
321290
bool Server::interrogationHandlerSinglePoint(void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi)
322291
{
323-
printf("Received interrogation for group %i\n", qoi);
292+
std::cout << "Received interrogation for group " << static_cast<int16_t>(qoi) << std::endl;
324293

325294
if (qoi == 20) /* only handle station interrogation */
326295
{
@@ -333,29 +302,20 @@ bool Server::interrogationHandlerSinglePoint(void *parameter, IMasterConnection
333302
for (const auto &kv : gServer->mBinaryPoints)
334303
{
335304
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)
347306
{
348307
// Send current ASDU and create a new one for the remaining values
349308
IMasterConnection_sendASDU(connection, newAsdu);
350309
CS101_ASDU_destroy(newAsdu);
351310
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);
359319
}
360320
}
361321
IMasterConnection_sendASDU(connection, newAsdu);
@@ -367,29 +327,20 @@ bool Server::interrogationHandlerSinglePoint(void *parameter, IMasterConnection
367327
for (const auto &kv : gServer->mAnalogPoints)
368328
{
369329
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)
381331
{
382332
// Send current ASDU and create a new one for the remaining values
383333
IMasterConnection_sendASDU(connection, newAsdu);
384334
CS101_ASDU_destroy(newAsdu);
385335
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);
393344
}
394345
}
395346
IMasterConnection_sendASDU(connection, newAsdu);
@@ -409,7 +360,7 @@ bool Server::interrogationHandlerSinglePoint(void *parameter, IMasterConnection
409360
*/
410361
bool Server::interrogationHandlerDoublePoint(void *parameter, IMasterConnection connection, CS101_ASDU asdu, uint8_t qoi)
411362
{
412-
printf("Received interrogation for group %i\n", qoi);
363+
std::cout << "Received interrogation for group " << static_cast<int16_t>(qoi) << std::endl;
413364

414365
if (qoi == 20) /* only handle station interrogation */
415366
{
@@ -422,29 +373,20 @@ bool Server::interrogationHandlerDoublePoint(void *parameter, IMasterConnection
422373
for (const auto &kv : gServer->mBinaryPoints)
423374
{
424375
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)
436377
{
437378
// Send current ASDU and create a new one for the remaining values
438379
IMasterConnection_sendASDU(connection, newAsdu);
439380
CS101_ASDU_destroy(newAsdu);
440381
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);
448390
}
449391
}
450392
IMasterConnection_sendASDU(connection, newAsdu);
@@ -456,29 +398,20 @@ bool Server::interrogationHandlerDoublePoint(void *parameter, IMasterConnection
456398
for (const auto &kv : gServer->mAnalogPoints)
457399
{
458400
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)
470402
{
471403
// Send current ASDU and create a new one for the remaining values
472404
IMasterConnection_sendASDU(connection, newAsdu);
473405
CS101_ASDU_destroy(newAsdu);
474406
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);
482415
}
483416
}
484417
IMasterConnection_sendASDU(connection, newAsdu);
@@ -497,7 +430,7 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
497430
{
498431
if (CS101_ASDU_getTypeID(asdu) == C_SC_NA_1)
499432
{
500-
printf("received single command\n");
433+
std::cout << "received single command" << std::endl;
501434

502435
if (CS101_ASDU_getCOT(asdu) == CS101_COT_ACTIVATION)
503436
{
@@ -515,8 +448,8 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
515448
}
516449
else
517450
{
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;
520453
}
521454
}
522455
else
@@ -528,7 +461,7 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
528461
}
529462
else if (CS101_ASDU_getTypeID(asdu) == C_DC_NA_1)
530463
{
531-
printf("received double command\n");
464+
std::cout << "received double command" << std::endl;
532465

533466
if (CS101_ASDU_getCOT(asdu) == CS101_COT_ACTIVATION)
534467
{
@@ -550,12 +483,14 @@ bool Server::asduHandler(void *parameter, IMasterConnection connection, CS101_AS
550483
}
551484
else
552485
{
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;
555488
}
556489
}
557490
else
491+
{
558492
CS101_ASDU_setCOT(asdu, CS101_COT_UNKNOWN_COT);
493+
}
559494

560495
IMasterConnection_sendASDU(connection, asdu);
561496

0 commit comments

Comments
 (0)