diff --git a/examples/iec61850_client_example_async/client_example_async.c b/examples/iec61850_client_example_async/client_example_async.c index 6284a130..0e06e5ed 100644 --- a/examples/iec61850_client_example_async/client_example_async.c +++ b/examples/iec61850_client_example_async/client_example_async.c @@ -28,12 +28,14 @@ printValue(char* name, MmsValue* value) static void readObjectHandler (uint32_t invokeId, void* parameter, IedClientError err, MmsValue* value) { - if (err == IED_ERROR_OK) { + if (err == IED_ERROR_OK) + { printValue((char*) parameter, value); MmsValue_delete(value); } - else { + else + { printf("Failed to read object %s (err=%i)\n", (char*) parameter, err); } } @@ -41,22 +43,26 @@ readObjectHandler (uint32_t invokeId, void* parameter, IedClientError err, MmsVa static void readDataSetHandler(uint32_t invokeId, void* parameter, IedClientError err, ClientDataSet dataSet) { - if (err == IED_ERROR_OK) { + if (err == IED_ERROR_OK) + { clientDataSet = dataSet; printf("Data set has %d entries\n", ClientDataSet_getDataSetSize(dataSet)); MmsValue* values = ClientDataSet_getValues(dataSet); - if (MmsValue_getType(values) == MMS_ARRAY) { + if (MmsValue_getType(values) == MMS_ARRAY) + { int i; - for (i = 0; i < MmsValue_getArraySize(values); i++) { + for (i = 0; i < MmsValue_getArraySize(values); i++) + { printf(" [%i]", i); printValue("", MmsValue_getElement(values, i)); } } } - else { + else + { printf("Failed to read data set (err=%i)\n", err); } } @@ -64,15 +70,16 @@ readDataSetHandler(uint32_t invokeId, void* parameter, IedClientError err, Clien static void writeDataSetHandler(uint32_t invokeId, void* parameter, IedClientError err, LinkedList /* */accessResults) { - if (err == IED_ERROR_OK) { - - if (accessResults) { - + if (err == IED_ERROR_OK) + { + if (accessResults) + { int i = 0; LinkedList element = LinkedList_getNext(accessResults); - while (element) { + while (element) + { MmsValue* accessResultValue = (MmsValue*) LinkedList_getData(element); printf(" access-result[%i]", i); @@ -84,10 +91,10 @@ writeDataSetHandler(uint32_t invokeId, void* parameter, IedClientError err, Link } LinkedList_destroyDeep(accessResults, (LinkedListValueDeleteFunction) MmsValue_delete); - } } - else { + else + { printf("Failed to write data set (err=%i)\n", err); } } @@ -100,10 +107,12 @@ reportCallbackFunction(void* parameter, ClientReport report) printf("received report for %s\n", ClientReport_getRcbReference(report)); int i; - for (i = 0; i < 4; i++) { + for (i = 0; i < 4; i++) + { ReasonForInclusion reason = ClientReport_getReasonForInclusion(report, i); - if (reason != IEC61850_REASON_NOT_INCLUDED) { + if (reason != IEC61850_REASON_NOT_INCLUDED) + { printf(" GGIO1.SPCSO%i.stVal: %i (included for reason %i)\n", i, MmsValue_getBoolean(MmsValue_getElement(dataSetValues, i)), reason); } @@ -113,12 +122,14 @@ reportCallbackFunction(void* parameter, ClientReport report) static void getVarSpecHandler (uint32_t invokeId, void* parameter, IedClientError err, MmsVariableSpecification* spec) { - if (err == IED_ERROR_OK) { + if (err == IED_ERROR_OK) + { printf("variable: %s has type %d\n", (char*) parameter, MmsVariableSpecification_getType(spec)); MmsVariableSpecification_destroy(spec); } - else { + else + { printf("Failed to get variable specification for object %s (err=%i)\n", (char*) parameter, err); } } @@ -126,17 +137,18 @@ getVarSpecHandler (uint32_t invokeId, void* parameter, IedClientError err, MmsVa static void getNameListHandler(uint32_t invokeId, void* parameter, IedClientError err, LinkedList nameList, bool moreFollows) { - if (err != IED_ERROR_OK) { + if (err != IED_ERROR_OK) + { printf("Get name list error: %d\n", err); } - else { - + else + { char* ldName = (char*) parameter; LinkedList element = LinkedList_getNext(nameList); - while (element) { - + while (element) + { char* variableName = (char*) LinkedList_getData(element); printf(" %s/%s\n", ldName, variableName); @@ -155,15 +167,17 @@ getServerDirectoryHandler(uint32_t invokeId, void* parameter, IedClientError err { IedConnection con = (IedConnection) parameter; - if (err != IED_ERROR_OK) { + if (err != IED_ERROR_OK) + { printf("Get server directory error: %d\n", err); } - else { + else + { LinkedList element = LinkedList_getNext(nameList); /* Call logical device variables for each logical node */ - while (element) { - + while (element) + { char* ldName = (char*) LinkedList_getData(element); IedClientError cerr; @@ -189,8 +203,8 @@ controlActionHandler(uint32_t invokeId, void* parameter, IedClientError err, Con printf("control: ID: %d type: %i err: %d success: %i\n", invokeId, type, err, success); } -int main(int argc, char** argv) { - +int main(int argc, char** argv) +{ char* hostname; int tcpPort = 102; @@ -208,13 +222,14 @@ int main(int argc, char** argv) { IedConnection_connectAsync(con, &error, hostname, tcpPort); - if (error == IED_ERROR_OK) { - + if (error == IED_ERROR_OK) + { bool success = true; - while (IedConnection_getState(con) != IED_STATE_CONNECTED) { - - if (IedConnection_getState(con) == IED_STATE_CLOSED) { + while (IedConnection_getState(con) != IED_STATE_CONNECTED) + { + if (IedConnection_getState(con) == IED_STATE_CLOSED) + { success = false; break; } @@ -222,38 +237,42 @@ int main(int argc, char** argv) { Thread_sleep(10); } - if (success) { - + if (success) + { IedConnection_getServerDirectoryAsync(con, &error, NULL, NULL, getServerDirectoryHandler, con); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("read server directory error %i\n", error); } Thread_sleep(1000); - IedConnection_readObjectAsync(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX, readObjectHandler, "simpleIOGenericIO/GGIO1.AnIn1.mag.f"); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("read object error %i\n", error); } IedConnection_readObjectAsync(con, &error, "simpleIOGenericIO/GGIO1.AnIn2.mag.f", IEC61850_FC_MX, readObjectHandler, "simpleIOGenericIO/GGIO1.AnIn2.mag.f"); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("read object error %i\n", error); } IedConnection_getVariableSpecificationAsync(con, &error, "simpleIOGenericIO/GGIO1.AnIn1", IEC61850_FC_MX, getVarSpecHandler, "simpleIOGenericIO/GGIO1.AnIn1"); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("get variable specification error %i\n", error); } IedConnection_readDataSetValuesAsync(con, &error, "simpleIOGenericIO/LLN0.Events", NULL, readDataSetHandler, NULL); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("read data set error %i\n", error); } @@ -265,7 +284,8 @@ int main(int argc, char** argv) { IedConnection_writeDataSetValuesAsync(con, &error, "simpleIOGenericIO/LLN0.Events", values, writeDataSetHandler, NULL); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("write data set error %i\n", error); } @@ -275,40 +295,44 @@ int main(int argc, char** argv) { ControlObjectClient controlClient = ControlObjectClient_create("simpleIOGenericIO/GGIO1.SPCSO1", con); - if (controlClient != NULL) { - + if (controlClient != NULL) + { ControlObjectClient_setOrigin(controlClient, "test1", CONTROL_ORCAT_AUTOMATIC_REMOTE); MmsValue* ctlVal = MmsValue_newBoolean(true); ControlObjectClient_operateAsync(controlClient, &error, ctlVal, 0, controlActionHandler, NULL); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("Failed to send operate %i\n", error); } } - else { + else + { printf("Failed to connect to control object\n"); } - } Thread_sleep(1000); IedConnection_releaseAsync(con, &error); - if (error != IED_ERROR_OK) { + if (error != IED_ERROR_OK) + { printf("Release returned error: %d\n", error); } - else { - - while (IedConnection_getState(con) != IED_STATE_CLOSED) { + else + { + while (IedConnection_getState(con) != IED_STATE_CLOSED) + { Thread_sleep(10); } } } - else { + else + { printf("Failed to connect to %s:%i\n", hostname, tcpPort); } @@ -318,5 +342,3 @@ int main(int argc, char** argv) { IedConnection_destroy(con); return 0; } - - diff --git a/examples/server_example_basic_io/server_example_basic_io.c b/examples/server_example_basic_io/server_example_basic_io.c index 3f1ca077..850a2d94 100644 --- a/examples/server_example_basic_io/server_example_basic_io.c +++ b/examples/server_example_basic_io/server_example_basic_io.c @@ -66,7 +66,6 @@ controlHandlerForBinaryOutput(ControlAction action, void* parameter, MmsValue* v return CONTROL_RESULT_OK; } - static void connectionHandler (IedServer self, ClientConnection connection, bool connected, void* parameter) { @@ -81,12 +80,14 @@ rcbEventHandler(void* parameter, ReportControlBlock* rcb, ClientConnection conne { printf("RCB: %s event: %i\n", ReportControlBlock_getName(rcb), event); - if ((event == RCB_EVENT_SET_PARAMETER) || (event == RCB_EVENT_GET_PARAMETER)) { + if ((event == RCB_EVENT_SET_PARAMETER) || (event == RCB_EVENT_GET_PARAMETER)) + { printf(" param: %s\n", parameterName); printf(" result: %i\n", serviceError); } - if (event == RCB_EVENT_ENABLE) { + if (event == RCB_EVENT_ENABLE) + { char* rptId = ReportControlBlock_getRptID(rcb); printf(" rptID: %s\n", rptId); char* dataSet = ReportControlBlock_getDataSet(rcb); @@ -139,7 +140,7 @@ main(int argc, char** argv) IedServerConfig_destroy(config); /* set the identity values for MMS identify service */ - IedServer_setServerIdentity(iedServer, "MZ", "basic io", "1.4.2"); + IedServer_setServerIdentity(iedServer, "MZ", "basic io", "1.6.0"); /* Install handler for operate command */ IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO1, @@ -171,7 +172,8 @@ main(int argc, char** argv) /* MMS server will be instructed to start listening for client connections. */ IedServer_start(iedServer, tcpPort); - if (!IedServer_isRunning(iedServer)) { + if (!IedServer_isRunning(iedServer)) + { printf("Starting server failed (maybe need root permissions or another server is already using the port)! Exit.\n"); IedServer_destroy(iedServer); exit(-1); @@ -183,7 +185,8 @@ main(int argc, char** argv) float t = 0.f; - while (running) { + while (running) + { uint64_t timestamp = Hal_getTimeInMs(); t += 0.1f;