lpcmanager

iec60870: fix init/publish/retrieve/cleanup name generation and add test server initialization
/* iec60870 runtime C extension
* TODO: plugin-specific init/publish/retrieve/cleanup functions
* which Beremiz runtime can link and call.
*/
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "cs104_slave.h"
CS104_Slave slave;
CS101_AppLayerParameters alParams;
int __init_%(locstr)s(int argc, char **argv) {
fprintf(stderr, "iec60870 extension: __init_iec60870\n");
// TODO: multi-server/client support?
/* create a new slave/server instance with default connection parameters and
* default message queue size */
slave = CS104_Slave_create(10, 10);
CS104_Slave_setLocalAddress(slave, "0.0.0.0");
/* Set mode to a single redundancy group
* NOTE: library has to be compiled with CONFIG_CS104_SUPPORT_SERVER_MODE_SINGLE_REDUNDANCY_GROUP enabled (=1)
*/
CS104_Slave_setServerMode(slave, CS104_MODE_SINGLE_REDUNDANCY_GROUP);
/* get the connection parameters - we need them to create correct ASDUs -
* you can also modify the parameters here when default parameters are not to be used */
alParams = CS104_Slave_getAppLayerParameters(slave);
/* when you have to tweak the APCI parameters (t0-t3, k, w) you can access them here */
CS104_APCIParameters apciParams = CS104_Slave_getConnectionParameters(slave);
// printf("APCI parameters:\n");
// printf(" t0: %%i\n", apciParams->t0);
// printf(" t1: %%i\n", apciParams->t1);
// printf(" t2: %%i\n", apciParams->t2);
// printf(" t3: %%i\n", apciParams->t3);
// printf(" k: %%i\n", apciParams->k);
// printf(" w: %%i\n", apciParams->w);
// TODO: initialize resources, threads, state
return 0;
}
void __publish_%(locstr)s(void) {
// TODO: sync data from PLC to extension outputs (if needed)
fprintf(stderr, "iec60870 extension: __publish_iec60870\n");
}
void __retrieve_%(locstr)s(void) {
// TODO: sync data from extension inputs to PLC (if needed)
}
int __cleanup_%(locstr)s(void) {
fprintf(stderr, "iec60870 extension: __cleanup_iec60870\n");
// TODO: release resources, stop threads
return 0;
}