- IEC 61850 client: added async versions for connect, abort, release, get variable specification, write object
parent
a5e15003ce
commit
54d8fb74d7
@ -0,0 +1,17 @@
|
||||
|
||||
set(iec61850_client_async_SRCS
|
||||
client_example_async.c
|
||||
)
|
||||
|
||||
IF(WIN32)
|
||||
set_source_files_properties(${iec61850_client_async_SRCS}
|
||||
PROPERTIES LANGUAGE CXX)
|
||||
ENDIF(WIN32)
|
||||
|
||||
add_executable(iec61850_client_async
|
||||
${iec61850_client_async_SRCS}
|
||||
)
|
||||
|
||||
target_link_libraries(iec61850_client_async
|
||||
iec61850
|
||||
)
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* client_example_async.c
|
||||
*
|
||||
* Shows how to use the asynchronous client API
|
||||
*
|
||||
* This example is intended to be used with server_example_basic_io or server_example_goose.
|
||||
*/
|
||||
|
||||
#include "iec61850_client.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "hal_thread.h"
|
||||
|
||||
void
|
||||
reportCallbackFunction(void* parameter, ClientReport report)
|
||||
{
|
||||
MmsValue* dataSetValues = ClientReport_getDataSetValues(report);
|
||||
|
||||
printf("received report for %s\n", ClientReport_getRcbReference(report));
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 4; i++) {
|
||||
ReasonForInclusion reason = ClientReport_getReasonForInclusion(report, i);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
printValue(char* name, MmsValue* value)
|
||||
{
|
||||
char buf[1000];
|
||||
|
||||
MmsValue_printToBuffer(value, buf, 1000);
|
||||
|
||||
printf("Received value for %s: %s\n", name, buf);
|
||||
}
|
||||
|
||||
static void
|
||||
readObjectHandler (int invokeId, void* parameter, IedClientError err, MmsValue* value)
|
||||
{
|
||||
if (err == IED_ERROR_OK) {
|
||||
printValue((char*) parameter, value);
|
||||
|
||||
MmsValue_delete(value);
|
||||
}
|
||||
else {
|
||||
printf("Failed to read object %s (err=%i)\n", parameter, err);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
getVarSpecHandler (int invokeId, void* parameter, IedClientError err, MmsVariableSpecification* spec)
|
||||
{
|
||||
if (err == IED_ERROR_OK) {
|
||||
printf("variable: %s has type %d\n", (char*) parameter, MmsVariableSpecification_getType(spec));
|
||||
|
||||
MmsVariableSpecification_destroy(spec);
|
||||
}
|
||||
else {
|
||||
printf("Failed to get variable specification for object %s (err=%i)\n", parameter, err);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
char* hostname;
|
||||
int tcpPort = 102;
|
||||
|
||||
if (argc > 1)
|
||||
hostname = argv[1];
|
||||
else
|
||||
hostname = "localhost";
|
||||
|
||||
if (argc > 2)
|
||||
tcpPort = atoi(argv[2]);
|
||||
|
||||
IedClientError error;
|
||||
|
||||
IedConnection con = IedConnection_create();
|
||||
|
||||
IedConnection_connectAsync(con, &error, hostname, tcpPort);
|
||||
|
||||
if (error == IED_ERROR_OK) {
|
||||
|
||||
bool success = true;
|
||||
|
||||
while (IedConnection_getState(con) != IED_STATE_CONNECTED) {
|
||||
|
||||
if (IedConnection_getState(con) == IED_STATE_CLOSED) {
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
Thread_sleep(10);
|
||||
}
|
||||
|
||||
if (success) {
|
||||
|
||||
IedConnection_readObjectAsync(con, &error, "simpleIOGenericIO/GGIO1.AnIn1.mag.f", IEC61850_FC_MX, readObjectHandler, "simpleIOGenericIO/GGIO1.AnIn1.mag.f");
|
||||
|
||||
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) {
|
||||
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) {
|
||||
printf("get variable specification error %i\n", error);
|
||||
}
|
||||
}
|
||||
|
||||
Thread_sleep(1000);
|
||||
|
||||
IedConnection_releaseAsync(con, &error);
|
||||
|
||||
if (error != IED_ERROR_OK) {
|
||||
printf("Release returned error: %d\n", error);
|
||||
}
|
||||
else {
|
||||
|
||||
while (IedConnection_getState(con) != IED_STATE_CLOSED) {
|
||||
Thread_sleep(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("Failed to connect to %s:%i\n", hostname, tcpPort);
|
||||
}
|
||||
|
||||
IedConnection_destroy(con);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue