|
|
@ -2,7 +2,6 @@
|
|
|
|
* beagle_demo.c
|
|
|
|
* beagle_demo.c
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This demo shows how to connect the libiec61850 server stack to a real device.
|
|
|
|
* This demo shows how to connect the libiec61850 server stack to a real device.
|
|
|
|
*
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "iec61850_server.h"
|
|
|
|
#include "iec61850_server.h"
|
|
|
@ -39,13 +38,16 @@ connectionIndicationHandler(IedServer server, ClientConnection connection, bool
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const char *clientAddress = ClientConnection_getPeerAddress(connection);
|
|
|
|
const char *clientAddress = ClientConnection_getPeerAddress(connection);
|
|
|
|
|
|
|
|
|
|
|
|
if (connected) {
|
|
|
|
if (connected)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("BeagleDemoServer: new client connection from %s\n", clientAddress);
|
|
|
|
printf("BeagleDemoServer: new client connection from %s\n", clientAddress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("BeagleDemoServer: client connection from %s closed\n", clientAddress);
|
|
|
|
printf("BeagleDemoServer: client connection from %s closed\n", clientAddress);
|
|
|
|
|
|
|
|
|
|
|
|
if (controllingClient == connection) {
|
|
|
|
if (controllingClient == connection)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("Controlling client has closed connection -> switch to automatic operation mode\n");
|
|
|
|
printf("Controlling client has closed connection -> switch to automatic operation mode\n");
|
|
|
|
controllingClient = NULL;
|
|
|
|
controllingClient = NULL;
|
|
|
|
automaticOperationMode = true;
|
|
|
|
automaticOperationMode = true;
|
|
|
@ -56,7 +58,8 @@ connectionIndicationHandler(IedServer server, ClientConnection connection, bool
|
|
|
|
static CheckHandlerResult
|
|
|
|
static CheckHandlerResult
|
|
|
|
performCheckHandler(ControlAction action, void *parameter, MmsValue *ctlVal, bool test, bool interlockCheck, ClientConnection connection)
|
|
|
|
performCheckHandler(ControlAction action, void *parameter, MmsValue *ctlVal, bool test, bool interlockCheck, ClientConnection connection)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (controllingClient == NULL) {
|
|
|
|
if (controllingClient == NULL)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("Client takes control -> switch to remote control operation mode\n");
|
|
|
|
printf("Client takes control -> switch to remote control operation mode\n");
|
|
|
|
controllingClient = connection;
|
|
|
|
controllingClient = connection;
|
|
|
|
automaticOperationMode = false;
|
|
|
|
automaticOperationMode = false;
|
|
|
@ -74,7 +77,8 @@ performCheckHandler(ControlAction action, void* parameter, MmsValue* ctlVal, boo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
static void
|
|
|
|
updateLED1stVal(bool newLedState, uint64_t timeStamp) {
|
|
|
|
updateLED1stVal(bool newLedState, uint64_t timeStamp)
|
|
|
|
|
|
|
|
{
|
|
|
|
switchLED(LED1, newLedState);
|
|
|
|
switchLED(LED1, newLedState);
|
|
|
|
|
|
|
|
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO1_t, timeStamp);
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO1_t, timeStamp);
|
|
|
@ -83,7 +87,8 @@ updateLED1stVal(bool newLedState, uint64_t timeStamp) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
static void
|
|
|
|
updateLED2stVal(bool newLedState, uint64_t timeStamp) {
|
|
|
|
updateLED2stVal(bool newLedState, uint64_t timeStamp)
|
|
|
|
|
|
|
|
{
|
|
|
|
switchLED(LED2, newLedState);
|
|
|
|
switchLED(LED2, newLedState);
|
|
|
|
|
|
|
|
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO2_t, timeStamp);
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO2_t, timeStamp);
|
|
|
@ -92,7 +97,8 @@ updateLED2stVal(bool newLedState, uint64_t timeStamp) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
static void
|
|
|
|
updateLED3stVal(bool newLedState, uint64_t timeStamp) {
|
|
|
|
updateLED3stVal(bool newLedState, uint64_t timeStamp)
|
|
|
|
|
|
|
|
{
|
|
|
|
switchLED(LED3, newLedState);
|
|
|
|
switchLED(LED3, newLedState);
|
|
|
|
|
|
|
|
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO3_t, timeStamp);
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_SPCSO3_t, timeStamp);
|
|
|
@ -119,28 +125,30 @@ controlHandlerForBinaryOutput(ControlAction action, void* parameter, MmsValue* v
|
|
|
|
if (parameter == IEDMODEL_GenericIO_GGIO1_SPCSO3)
|
|
|
|
if (parameter == IEDMODEL_GenericIO_GGIO1_SPCSO3)
|
|
|
|
updateLED3stVal(newState, timeStamp);
|
|
|
|
updateLED3stVal(newState, timeStamp);
|
|
|
|
|
|
|
|
|
|
|
|
if (parameter == IEDMODEL_GenericIO_GGIO1_DPCSO1) { /* example for Double Point Control - DPC */
|
|
|
|
if (parameter == IEDMODEL_GenericIO_GGIO1_DPCSO1) /* example for Double Point Control - DPC */
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Dbpos dpcState = DBPOS_INTERMEDIATE_STATE;
|
|
|
|
|
|
|
|
|
|
|
|
dpcState = 0; /* DPC_STATE_INTERMEDIATE */
|
|
|
|
IedServer_updateDbposValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_stVal, dpcState);
|
|
|
|
IedServer_updateBitStringAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_stVal, dpcState);
|
|
|
|
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_t, timeStamp);
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_t, timeStamp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (newState)
|
|
|
|
if (newState) {
|
|
|
|
{
|
|
|
|
flashLED(LED4);
|
|
|
|
flashLED(LED4);
|
|
|
|
Thread_sleep(3000);
|
|
|
|
Thread_sleep(3000);
|
|
|
|
switchLED(LED4, 1);
|
|
|
|
switchLED(LED4, 1);
|
|
|
|
dpcState = 2; /* DPC_STATE_ON */
|
|
|
|
dpcState = DBPOS_ON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
flashLED(LED4);
|
|
|
|
flashLED(LED4);
|
|
|
|
Thread_sleep(3000);
|
|
|
|
Thread_sleep(3000);
|
|
|
|
switchLED(LED4, 0);
|
|
|
|
switchLED(LED4, 0);
|
|
|
|
dpcState = 1; /* DPC_STATE_OFF */
|
|
|
|
dpcState = DBPOS_OFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IedServer_updateBitStringAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_stVal, dpcState);
|
|
|
|
IedServer_updateDbposValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_stVal, dpcState);
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_t, timeStamp);
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1_t, Hal_getTimeInMs());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return CONTROL_RESULT_OK;
|
|
|
|
return CONTROL_RESULT_OK;
|
|
|
@ -156,7 +164,8 @@ controlHandlerForInt32Controls(ControlAction action, void* parameter, MmsValue*
|
|
|
|
if (test)
|
|
|
|
if (test)
|
|
|
|
return CONTROL_RESULT_OK;
|
|
|
|
return CONTROL_RESULT_OK;
|
|
|
|
|
|
|
|
|
|
|
|
if (parameter == IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs) {
|
|
|
|
if (parameter == IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs)
|
|
|
|
|
|
|
|
{
|
|
|
|
int32_t newValue = MmsValue_toInt32(value);
|
|
|
|
int32_t newValue = MmsValue_toInt32(value);
|
|
|
|
|
|
|
|
|
|
|
|
opCnt = newValue;
|
|
|
|
opCnt = newValue;
|
|
|
@ -170,8 +179,6 @@ controlHandlerForInt32Controls(ControlAction action, void* parameter, MmsValue*
|
|
|
|
return CONTROL_RESULT_OK;
|
|
|
|
return CONTROL_RESULT_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static MmsDataAccessError
|
|
|
|
static MmsDataAccessError
|
|
|
|
int32WriteAccessHandler(DataAttribute *dataAttribute, MmsValue *value, ClientConnection connection, void *parameter)
|
|
|
|
int32WriteAccessHandler(DataAttribute *dataAttribute, MmsValue *value, ClientConnection connection, void *parameter)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -181,8 +188,8 @@ int32WriteAccessHandler (DataAttribute* dataAttribute, MmsValue* value, ClientCo
|
|
|
|
if (newValue < 0)
|
|
|
|
if (newValue < 0)
|
|
|
|
return DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
|
|
|
|
return DATA_ACCESS_ERROR_OBJECT_VALUE_INVALID;
|
|
|
|
|
|
|
|
|
|
|
|
if (dataAttribute == IEDMODEL_GenericIO_TIM_GAPC1_OpDlTmms_setVal) {
|
|
|
|
if (dataAttribute == IEDMODEL_GenericIO_TIM_GAPC1_OpDlTmms_setVal)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("New value for TIM_GAPC1.OpDlTmms.setVal = %i\n", newValue);
|
|
|
|
printf("New value for TIM_GAPC1.OpDlTmms.setVal = %i\n", newValue);
|
|
|
|
|
|
|
|
|
|
|
|
ledOffTimeMs = newValue;
|
|
|
|
ledOffTimeMs = newValue;
|
|
|
@ -190,8 +197,8 @@ int32WriteAccessHandler (DataAttribute* dataAttribute, MmsValue* value, ClientCo
|
|
|
|
return DATA_ACCESS_ERROR_SUCCESS;
|
|
|
|
return DATA_ACCESS_ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dataAttribute == IEDMODEL_GenericIO_TIM_GAPC1_RsDlTmms_setVal) {
|
|
|
|
if (dataAttribute == IEDMODEL_GenericIO_TIM_GAPC1_RsDlTmms_setVal)
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("New value for TIM_GAPC1.RsDlTmms.setVal = %i\n", newValue);
|
|
|
|
printf("New value for TIM_GAPC1.RsDlTmms.setVal = %i\n", newValue);
|
|
|
|
|
|
|
|
|
|
|
|
ledOnTimeMs = newValue;
|
|
|
|
ledOnTimeMs = newValue;
|
|
|
@ -202,9 +209,8 @@ int32WriteAccessHandler (DataAttribute* dataAttribute, MmsValue* value, ClientCo
|
|
|
|
return DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
|
|
|
|
return DATA_ACCESS_ERROR_OBJECT_ACCESS_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
initLEDs();
|
|
|
|
initLEDs();
|
|
|
|
|
|
|
|
|
|
|
|
iedServer = IedServer_create(&iedModel);
|
|
|
|
iedServer = IedServer_create(&iedModel);
|
|
|
@ -236,7 +242,6 @@ int main(int argc, char** argv) {
|
|
|
|
IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1, (ControlHandler)controlHandlerForBinaryOutput,
|
|
|
|
IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_GGIO1_DPCSO1, (ControlHandler)controlHandlerForBinaryOutput,
|
|
|
|
IEDMODEL_GenericIO_GGIO1_DPCSO1);
|
|
|
|
IEDMODEL_GenericIO_GGIO1_DPCSO1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs, (ControlHandler)controlHandlerForInt32Controls,
|
|
|
|
IedServer_setControlHandler(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs, (ControlHandler)controlHandlerForInt32Controls,
|
|
|
|
IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs);
|
|
|
|
IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs);
|
|
|
|
|
|
|
|
|
|
|
@ -252,11 +257,11 @@ int main(int argc, char** argv) {
|
|
|
|
IedServer_handleWriteAccess(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpDlTmms_setVal, int32WriteAccessHandler, NULL);
|
|
|
|
IedServer_handleWriteAccess(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpDlTmms_setVal, int32WriteAccessHandler, NULL);
|
|
|
|
IedServer_handleWriteAccess(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_RsDlTmms_setVal, int32WriteAccessHandler, NULL);
|
|
|
|
IedServer_handleWriteAccess(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_RsDlTmms_setVal, int32WriteAccessHandler, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* MMS server will be instructed to start listening to client connections. */
|
|
|
|
/* MMS server will be instructed to start listening to client connections. */
|
|
|
|
IedServer_start(iedServer, 102);
|
|
|
|
IedServer_start(iedServer, 102);
|
|
|
|
|
|
|
|
|
|
|
|
if (!IedServer_isRunning(iedServer)) {
|
|
|
|
if (!IedServer_isRunning(iedServer))
|
|
|
|
|
|
|
|
{
|
|
|
|
printf("Starting server failed! Exit.\n");
|
|
|
|
printf("Starting server failed! Exit.\n");
|
|
|
|
IedServer_destroy(iedServer);
|
|
|
|
IedServer_destroy(iedServer);
|
|
|
|
exit(-1);
|
|
|
|
exit(-1);
|
|
|
@ -272,13 +277,14 @@ int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t nextLedToggleTime = Hal_getTimeInMs() + 1000;
|
|
|
|
uint64_t nextLedToggleTime = Hal_getTimeInMs() + 1000;
|
|
|
|
|
|
|
|
|
|
|
|
while (running) {
|
|
|
|
while (running)
|
|
|
|
|
|
|
|
{
|
|
|
|
uint64_t currentTime = Hal_getTimeInMs();
|
|
|
|
uint64_t currentTime = Hal_getTimeInMs();
|
|
|
|
|
|
|
|
|
|
|
|
if (automaticOperationMode) {
|
|
|
|
if (automaticOperationMode)
|
|
|
|
if (nextLedToggleTime <= currentTime) {
|
|
|
|
{
|
|
|
|
|
|
|
|
if (nextLedToggleTime <= currentTime)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (ledStateValue)
|
|
|
|
if (ledStateValue)
|
|
|
|
nextLedToggleTime = currentTime + ledOffTimeMs;
|
|
|
|
nextLedToggleTime = currentTime + ledOffTimeMs;
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -286,7 +292,8 @@ int main(int argc, char** argv) {
|
|
|
|
|
|
|
|
|
|
|
|
ledStateValue = !ledStateValue;
|
|
|
|
ledStateValue = !ledStateValue;
|
|
|
|
|
|
|
|
|
|
|
|
if (ledStateValue) {
|
|
|
|
if (ledStateValue)
|
|
|
|
|
|
|
|
{
|
|
|
|
opCnt++;
|
|
|
|
opCnt++;
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs_t, currentTime);
|
|
|
|
IedServer_updateUTCTimeAttributeValue(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs_t, currentTime);
|
|
|
|
IedServer_updateInt32AttributeValue(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs_stVal, opCnt);
|
|
|
|
IedServer_updateInt32AttributeValue(iedServer, IEDMODEL_GenericIO_TIM_GAPC1_OpCntRs_stVal, opCnt);
|
|
|
|