mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
asyncip: add support for GTNET-SKT
This commit is contained in:
parent
77f6a7209f
commit
49263c4a70
3 changed files with 69 additions and 22 deletions
3
clients/opal/udp/models/send_receive/.gitignore
vendored
Normal file
3
clients/opal/udp/models/send_receive/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
*.o
|
||||||
|
*.d
|
||||||
|
AsyncIP
|
|
@ -9,8 +9,17 @@
|
||||||
#define _CONFIG_H_
|
#define _CONFIG_H_
|
||||||
|
|
||||||
#define PROGNAME "VILLASnode-OPAL-UDP"
|
#define PROGNAME "VILLASnode-OPAL-UDP"
|
||||||
#define VERSION "0.5"
|
#define VERSION "0.6"
|
||||||
|
|
||||||
#define MAX_VALUES 64
|
#define MAX_VALUES 64
|
||||||
|
|
||||||
|
/* List of protocols */
|
||||||
|
#define VILLAS 1
|
||||||
|
#define GTNET_SKT 2
|
||||||
|
|
||||||
|
/* Default protocol */
|
||||||
|
#ifndef PROTOCOL
|
||||||
|
#define PROTOCOL VILLAS
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* _CONFIG_H_ */
|
#endif /* _CONFIG_H_ */
|
|
@ -25,11 +25,14 @@
|
||||||
|
|
||||||
/* This is the message format */
|
/* This is the message format */
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "msg.h"
|
|
||||||
#include "msg_format.h"
|
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
#if PROTOCOL == VILLAS
|
||||||
|
#include "msg.h"
|
||||||
|
#include "msg_format.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This is just for initializing the shared memory access to communicate
|
/* This is just for initializing the shared memory access to communicate
|
||||||
* with the RT-LAB model. It's easier to remember the arguments like this */
|
* with the RT-LAB model. It's easier to remember the arguments like this */
|
||||||
#define ASYNC_SHMEM_NAME argv[1]
|
#define ASYNC_SHMEM_NAME argv[1]
|
||||||
|
@ -48,9 +51,13 @@ static void * SendToIPPort(void *arg)
|
||||||
double mdldata[MAX_VALUES];
|
double mdldata[MAX_VALUES];
|
||||||
int mdldata_size;
|
int mdldata_size;
|
||||||
|
|
||||||
/* Data from VILLASnode */
|
#if PROTOCOL == VILLAS
|
||||||
char buf[MSG_LEN(MAX_VALUES)];
|
char buf[MSG_LEN(MAX_VALUES)];
|
||||||
struct msg *msg = (struct msg *) buf;
|
struct msg *msg = (struct msg *) buf;
|
||||||
|
#elif PROTOCOL == GTNET_SKT
|
||||||
|
char buf[MAX_VALUES * sizeof(float)];
|
||||||
|
float *msg = (float *) buf;
|
||||||
|
#endif
|
||||||
|
|
||||||
OpalPrint("%s: SendToIPPort thread started\n", PROGNAME);
|
OpalPrint("%s: SendToIPPort thread started\n", PROGNAME);
|
||||||
|
|
||||||
|
@ -78,7 +85,8 @@ static void * SendToIPPort(void *arg)
|
||||||
|
|
||||||
/* Get the size of the data being sent by the unblocking SendID */
|
/* Get the size of the data being sent by the unblocking SendID */
|
||||||
OpalGetAsyncSendIconDataLength(&mdldata_size, SendID);
|
OpalGetAsyncSendIconDataLength(&mdldata_size, SendID);
|
||||||
if (mdldata_size / sizeof(double) > MAX_VALUES) {
|
cnt = mdldata_size / sizeof(double);
|
||||||
|
if (cnt > MAX_VALUES) {
|
||||||
OpalPrint("%s: Number of signals for SendID=%d exceeds allowed maximum (%d)\n",
|
OpalPrint("%s: Number of signals for SendID=%d exceeds allowed maximum (%d)\n",
|
||||||
PROGNAME, SendID, MAX_VALUES);
|
PROGNAME, SendID, MAX_VALUES);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -86,7 +94,8 @@ static void * SendToIPPort(void *arg)
|
||||||
|
|
||||||
/* Read data from the model */
|
/* Read data from the model */
|
||||||
OpalGetAsyncSendIconData(mdldata, mdldata_size, SendID);
|
OpalGetAsyncSendIconData(mdldata, mdldata_size, SendID);
|
||||||
|
|
||||||
|
#if PROTOCOL == VILLAS
|
||||||
/* Get current time */
|
/* Get current time */
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_REALTIME, &now);
|
clock_gettime(CLOCK_REALTIME, &now);
|
||||||
|
@ -100,6 +109,16 @@ static void * SendToIPPort(void *arg)
|
||||||
msg->data[i].f = (float) mdldata[i];
|
msg->data[i].f = (float) mdldata[i];
|
||||||
|
|
||||||
msg_hton(msg);
|
msg_hton(msg);
|
||||||
|
|
||||||
|
len = MSG_LEN(msg->length);
|
||||||
|
#elif PROTOCOL == GTNET_SKT
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
msg[i] = (float) mdldata[i];
|
||||||
|
|
||||||
|
len = mdldata_size / sizeof(double) * sizeof(float);
|
||||||
|
#else
|
||||||
|
#error Unknown protocol
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Perform the actual write to the ip port */
|
/* Perform the actual write to the ip port */
|
||||||
ret = socket_send(&skt, (char *) msg, len);
|
ret = socket_send(&skt, (char *) msg, len);
|
||||||
|
@ -135,9 +154,15 @@ static void * RecvFromIPPort(void *arg)
|
||||||
double mdldata[MAX_VALUES];
|
double mdldata[MAX_VALUES];
|
||||||
int mdldata_size;
|
int mdldata_size;
|
||||||
|
|
||||||
/* Data from VILLASnode */
|
#if PROTOCOL == VILLAS
|
||||||
char buf[MSG_LEN(MAX_VALUES)];
|
char buf[MSG_LEN(MAX_VALUES)];
|
||||||
struct msg *msg = (struct msg *) buf;
|
struct msg *msg = (struct msg *) buf;
|
||||||
|
#elif PROTOCOL == GTNET_SKT
|
||||||
|
char buf[MAX_VALUES * sizeof(float)];
|
||||||
|
float *msg = (float *) buf;
|
||||||
|
#else
|
||||||
|
#error Unknown protocol
|
||||||
|
#endif
|
||||||
|
|
||||||
OpalPrint("%s: RecvFromIPPort thread started\n", PROGNAME);
|
OpalPrint("%s: RecvFromIPPort thread started\n", PROGNAME);
|
||||||
|
|
||||||
|
@ -162,7 +187,17 @@ static void * RecvFromIPPort(void *arg)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get the number of signals to send back to the model */
|
||||||
|
OpalGetAsyncRecvIconDataLength(&mdldata_size, RecvID);
|
||||||
|
cnt = mdldata_size / sizeof(double);
|
||||||
|
if (cnt > MAX_VALUES) {
|
||||||
|
OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds allowed maximum (%d)\n",
|
||||||
|
PROGNAME, RecvID, cnt, MAX_VALUES);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if PROTOCOL == VILLAS
|
||||||
msg_ntoh(msg);
|
msg_ntoh(msg);
|
||||||
|
|
||||||
ret = msg_verify(msg);
|
ret = msg_verify(msg);
|
||||||
|
@ -170,26 +205,26 @@ static void * RecvFromIPPort(void *arg)
|
||||||
OpalPrint("%s: Skipping invalid packet\n", PROGNAME);
|
OpalPrint("%s: Skipping invalid packet\n", PROGNAME);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (cnt > msg->length) {
|
||||||
|
OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds what was received (%d)\n",
|
||||||
|
PROGNAME, RecvID, cnt, msg->length);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < msg->length; i++)
|
||||||
|
mdldata[i] = (double) msg->data[i].f;
|
||||||
|
|
||||||
/* Update OPAL model */
|
/* Update OPAL model */
|
||||||
OpalSetAsyncRecvIconStatus(msg->sequence, RecvID); /* Set the Status to the message ID */
|
OpalSetAsyncRecvIconStatus(msg->sequence, RecvID); /* Set the Status to the message ID */
|
||||||
|
#elif PROTOCOL == GTNET_SKT
|
||||||
|
for (int i = 0; i < cnt; i++)
|
||||||
|
mdldata[i] = (double) msg[i];
|
||||||
|
#else
|
||||||
|
#error Unknown protocol
|
||||||
|
#endif
|
||||||
|
|
||||||
OpalSetAsyncRecvIconError(0, RecvID); /* Set the Error to 0 */
|
OpalSetAsyncRecvIconError(0, RecvID); /* Set the Error to 0 */
|
||||||
|
|
||||||
/* Get the number of signals to send back to the model */
|
|
||||||
OpalGetAsyncRecvIconDataLength(&mdldata_size, RecvID);
|
|
||||||
if (mdldata_size / sizeof(double) > MAX_VALUES) {
|
|
||||||
OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds allowed maximum (%d)\n",
|
|
||||||
PROGNAME, RecvID, mdldata_size / sizeof(double), MAX_VALUES);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mdldata_size / sizeof(double) > msg->length)
|
|
||||||
OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds what was received (%d)\n",
|
|
||||||
PROGNAME, RecvID, mdldata_size / sizeof(double), msg->length);
|
|
||||||
|
|
||||||
for (i = 0; i < msg->length; i++)
|
|
||||||
mdldata[i] = (double) msg->data[i].f;
|
|
||||||
|
|
||||||
OpalSetAsyncRecvIconData(mdldata, mdldata_size, RecvID);
|
OpalSetAsyncRecvIconData(mdldata, mdldata_size, RecvID);
|
||||||
|
|
||||||
/* Before continuing, we make sure that the real-time model
|
/* Before continuing, we make sure that the real-time model
|
||||||
|
|
Loading…
Add table
Reference in a new issue