updated server substitution example

pull/179/head
Michael Zillgith 6 years ago
parent 88849e1663
commit 74d78d0618

@ -25,6 +25,10 @@ static IedServer iedServer = NULL;
static bool subsAnIn1 = false; static bool subsAnIn1 = false;
static bool subsInd1 = false; static bool subsInd1 = false;
static float an1 = 0.f;
static uint64_t timestamp = 0;
static bool ind1 = true;
void void
sigint_handler(int signalId) sigint_handler(int signalId)
{ {
@ -41,6 +45,28 @@ connectionHandler (IedServer self, ClientConnection connection, bool connected,
printf("Connection closed\n"); printf("Connection closed\n");
} }
static void
updateProcessValues()
{
Timestamp iecTimestamp;
Timestamp_clearFlags(&iecTimestamp);
Timestamp_setTimeInMilliseconds(&iecTimestamp, timestamp);
Timestamp_setLeapSecondKnown(&iecTimestamp, true);
if (subsAnIn1 == false) {
IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_t, &iecTimestamp);
IedServer_updateQuality(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_q, QUALITY_VALIDITY_GOOD);
IedServer_updateFloatAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_mag_f, an1);
}
if (subsInd1 == false) {
IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_Ind1_t, &iecTimestamp);
IedServer_updateQuality(iedServer, IEDMODEL_LD1_GGIO1_Ind1_q, QUALITY_VALIDITY_GOOD);
IedServer_updateBooleanAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_Ind1_stVal, ind1);
}
}
static MmsDataAccessError static MmsDataAccessError
writeAccessHandler (DataAttribute* dataAttribute, MmsValue* value, ClientConnection connection, void* parameter) writeAccessHandler (DataAttribute* dataAttribute, MmsValue* value, ClientConnection connection, void* parameter)
{ {
@ -64,7 +90,11 @@ writeAccessHandler (DataAttribute* dataAttribute, MmsValue* value, ClientConnect
IedServer_getAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_subMag_f)); IedServer_getAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_subMag_f));
} }
else { else {
IedServer_updateVisibleStringAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_subID, "");
subsAnIn1 = false; subsAnIn1 = false;
updateProcessValues();
} }
} }
@ -105,7 +135,11 @@ writeAccessHandler (DataAttribute* dataAttribute, MmsValue* value, ClientConnect
IedServer_getAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_Ind1_subVal)); IedServer_getAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_Ind1_subVal));
} }
else { else {
IedServer_updateVisibleStringAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_Ind1_subID, "");
subsInd1 = false; subsInd1 = false;
updateProcessValues();
} }
} }
else if (dataAttribute == IEDMODEL_LD1_GGIO1_Ind1_subVal) { else if (dataAttribute == IEDMODEL_LD1_GGIO1_Ind1_subVal) {
@ -135,9 +169,6 @@ main(int argc, char** argv)
{ {
printf("Using libIEC61850 version %s\n", LibIEC61850_getVersionString()); printf("Using libIEC61850 version %s\n", LibIEC61850_getVersionString());
/* Create a new IEC 61850 server instance */ /* Create a new IEC 61850 server instance */
iedServer = IedServer_create(&iedModel); iedServer = IedServer_create(&iedModel);
@ -167,44 +198,22 @@ main(int argc, char** argv)
signal(SIGINT, sigint_handler); signal(SIGINT, sigint_handler);
float t = 0.f; float t = 0.f;
bool ind1 = true;
while (running) { while (running) {
uint64_t timestamp = Hal_getTimeInMs(); timestamp = Hal_getTimeInMs();
t += 0.1f; t += 0.1f;
float an1 = sinf(t); an1 = sinf(t);
if (ind1) if (ind1)
ind1 = false; ind1 = false;
else else
ind1 = true; ind1 = true;
Timestamp iecTimestamp;
Timestamp_clearFlags(&iecTimestamp);
Timestamp_setTimeInMilliseconds(&iecTimestamp, timestamp);
Timestamp_setLeapSecondKnown(&iecTimestamp, true);
/* toggle clock-not-synchronized flag in timestamp */
if (((int) t % 2) == 0)
Timestamp_setClockNotSynchronized(&iecTimestamp, true);
IedServer_lockDataModel(iedServer); IedServer_lockDataModel(iedServer);
if (subsAnIn1 == false) { updateProcessValues();
IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_t, &iecTimestamp);
IedServer_updateQuality(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_q, QUALITY_VALIDITY_GOOD);
IedServer_updateFloatAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_AnIn1_mag_f, an1);
}
if (subsInd1 == false) {
IedServer_updateTimestampAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_Ind1_t, &iecTimestamp);
IedServer_updateQuality(iedServer, IEDMODEL_LD1_GGIO1_Ind1_q, QUALITY_VALIDITY_GOOD);
IedServer_updateBooleanAttributeValue(iedServer, IEDMODEL_LD1_GGIO1_Ind1_stVal, ind1);
}
IedServer_unlockDataModel(iedServer); IedServer_unlockDataModel(iedServer);

@ -1102,7 +1102,7 @@ typedef enum {
/** the element is included due to a general interrogation by the client */ /** the element is included due to a general interrogation by the client */
IEC61850_REASON_GI = 5, IEC61850_REASON_GI = 5,
/** the reason for inclusion is unknown */ /** the reason for inclusion is unknown (e.g. report is not configured to include reason-for-inclusion) */
IEC61850_REASON_UNKNOWN = 6 IEC61850_REASON_UNKNOWN = 6
} ReasonForInclusion; } ReasonForInclusion;

Loading…
Cancel
Save