1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

several bugfixes

git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@156 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
Steffen Vogel 2014-07-14 17:51:29 +00:00
parent c2516799ee
commit 604ce6724a
7 changed files with 62 additions and 42 deletions

View file

@ -8,6 +8,6 @@
#ifndef _INTERFACE_H_
#define _INTERFACE_H_
int if_setup(const char *op, const char *iface, const char *addr)
int if_setup(const char *op, const char *iface, const char *addr);
#endif /* _INTERFACE_H_ */

View file

@ -10,6 +10,8 @@
#ifndef _SCHED_H_
#define _SCHED_H_
#define EOK 0
int AssignProcToCpu0(void);
#endif /* _SCHED_H_ */

View file

@ -15,9 +15,6 @@
#ifndef _SOCKET_H_
#define _SOCKET_H_
/* Modify this version line if you make changes to this file */
#define VERSION "Opal-RT_20060524"
#define RT
#include "OpalGenAsyncParamCtrl.h"

View file

@ -12,8 +12,6 @@
* @file
*/
#define PROGNAME "AsyncIP"
/* Standard ANSI C headers needed for this program */
#include <errno.h>
#include <fcntl.h>
@ -40,6 +38,7 @@
#include "AsyncApi.h"
/* This is the message format */
#include "config.h"
#include "MsgFormat.h"
#include "Socket.h"
#include "Interface.h"
@ -50,22 +49,18 @@
#define ASYNC_SHMEM_SIZE atoi(argv[2])
#define PRINT_SHMEM_NAME argv[3]
/* This defines the maximum number of signals (doubles) that can be sent
* or received by any individual Send or Recv block in the model. This
* only applies to the "model <-> asynchronous process" communication. */
#define MAX_SEND_SIZE 64
#define MAX_RECV_SIZE 64
static void *SendToIPPort(void *arg)
{
int SendID = 1;
int i, n;
unsigned SendID = 1;
unsigned i, n;
int nbSend = 0;
int ModelState;
unsigned ModelState;
double mdldata[MAXSENDSIZE];
/* Data from OPAL-RT model */
double mdldata[MSG_VALUES];
int mdldata_size;
/* Data from the S2SS server */
struct msg msg = MSG_INIT(0);
int msg_size;
@ -90,9 +85,9 @@ static void *SendToIPPort(void *arg)
/* Get the size of the data being sent by the unblocking SendID */
OpalGetAsyncSendIconDataLength(&mdldata_size, SendID);
if (mdldata_size / sizeof(double) > MAXSENDSIZE) {
if (mdldata_size / sizeof(double) > MSG_VALUES) {
OpalPrint("%s: Number of signals for SendID=%d exceeds allowed maximum (%d)\n",
PROGNAME, SendID, MAXSENDSIZE);
PROGNAME, SendID, MSG_VALUES);
return NULL;
}
@ -107,6 +102,8 @@ static void *SendToIPPort(void *arg)
for (i = 0; i < msg.length; i++)
msg.data[i] = (float) mdldata[i];
msg_size = 4 * (msg.length + 1);
/**********************************************************************/
/* Perform the actual write to the ip port */
@ -139,16 +136,18 @@ static void *SendToIPPort(void *arg)
static void *RecvFromIPPort(void *arg)
{
int RecvID = 1;
int i, n;
unsigned RecvID = 1;
unsigned i, n;
int nbRecv = 0;
int ModelState;
unsigned ModelState;
double mdldata[MAXRECVSIZE];
/* Data from OPAL-RT model */
double mdldata[MSG_VALUES];
int mdldata_size;
struct msg msg;
int msg_size;
/* Data from the S2SS server */
struct msg msg = MSG_INIT(0);
unsigned msg_size;
OpalPrint("%s: RecvFromIPPort thread started\n", PROGNAME);
@ -192,16 +191,15 @@ static void *RecvFromIPPort(void *arg)
}
/******* FORMAT TO SPECIFIC PROTOCOL HERE *******************************/
RecvID = 0; // msg.dev_id; /* Use the deviceID as the RecvID */
OpalSetAsyncRecvIconStatus(msg.sequence, RecvID); /* Set the Status to the message ID */
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_RECV_VALUES) {
if (mdldata_size / sizeof(double) > MSG_VALUES) {
OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds allowed maximum (%d)\n",
PROGNAME, RecvID, mdldata_size / sizeof(double), MAX_RECV_SIZE);
PROGNAME, RecvID, mdldata_size / sizeof(double), MSG_VALUES);
return NULL;
}
@ -238,6 +236,8 @@ int main(int argc, char *argv[])
pthread_t tid_send, tid_recv;
pthread_attr_t attr_send, attr_recv;
OpalPrint("%s: This is a S2SS client\n", PROGNAME);
/* Check for the proper arguments to the program */
if (argc < 4) {

View file

@ -5,6 +5,7 @@
* @file
*/
#include "config.h"
#include "Interface.h"
int if_setup(const char *op, const char *iface, const char *addr)
@ -19,7 +20,7 @@ int if_setup(const char *op, const char *iface, const char *addr)
/* Setup route for single IP address */
snprintf(cmd, 256, "ip route %s %s/32 dev %s", op, addr, iface);
if (system(cmd))
OpalPrint("Failed to add route for remote address")
OpalPrint("Failed to add route for remote address");
return 0;
}

View file

@ -7,6 +7,14 @@
* @file
*/
#include <errno.h>
/* Define RTLAB before including OpalPrint.h for messages to be sent
* to the OpalDisplay. Otherwise stdout will be used. */
#define RTLAB
#include "OpalPrint.h"
#include "config.h"
#include "Sched.h"
#if defined(__QNXNTO__)
@ -27,13 +35,13 @@ int AssignProcToCpu0(void)
{
#if defined(__linux__)
#if defined(__redhawk__)
int rc;
pid_t pid = getpid();
cpuset_t *pCpuset;
int rc;
pid_t pid = getpid();
cpuset_t *pCpuset;
pCpuset = cpuset_alloc();
if (NULL == pCpuset) {
fprintf(stderr, "Error allocating a cpuset\n");
OpalPrint("Error allocating a cpuset\n");
return ENOMEM;
}
@ -43,13 +51,12 @@ int AssignProcToCpu0(void)
rc = mpadvise(MPA_PRC_SETBIAS, MPA_TID, pid, pCpuset);
if (MPA_FAILURE == rc) {
rc = errno;
fprintf(stderr, "Error from mpadvise, %d %s, for pid %d\n", errno, strerror(errno), pid);
OpalPrint("Error from mpadvise, %d %s, for pid %d\n", errno, strerror(errno), pid);
cpuset_free(pCpuset);
return rc;
}
cpuset_free(pCpuset);
return EOK;
#else
cpu_set_t bindSet;
CPU_ZERO(&bindSet);
@ -57,10 +64,11 @@ int AssignProcToCpu0(void)
/* changing process cpu affinity */
if (sched_setaffinity(0, sizeof(cpu_set_t), &bindSet) != 0) {
fprintf(stderr, "Unable to bind the process to CPU 0. (sched_setaffinity errno %d)\n", errno );
OpalPrint("Unable to bind the process to CPU 0. (sched_setaffinity errno %d)\n", errno);
return EINVAL;
}
return EOK;
#endif
return EOK;
#endif /* __linux__ */
}

View file

@ -20,15 +20,20 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include "Socket.c"
/* Define RTLAB before including OpalPrint.h for messages to be sent
* to the OpalDisplay. Otherwise stdout will be used. */
#define RTLAB
#include "OpalPrint.h"
#include "AsyncApi.h"
#include "config.h"
#include "Socket.h"
/* Globals variables */
struct sockaddr_in send_ad; /* Send address */
struct sockaddr_in recv_ad; /* Recveive address */
struct sockaddr_in recv_ad; /* Receive address */
int sd = -1; /* socket descriptor */
int proto = 1;
int proto = UDP_PROTOCOL;
int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
{
@ -47,11 +52,15 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
socket_proto = IPPROTO_UDP;
socket_type = SOCK_DGRAM;
OpalPrint("%s: Protocol : UDP/IP\n", PROGNAME);
break;
case TCP_PROTOCOL: /* Communication using TCP/IP protocol */
socket_proto = IPPROTO_IP;
socket_type = SOCK_STREAM;
OpalPrint("%s: Protocol : TCP/IP\n", PROGNAME);
case default: /* Protocol is not recognized */
break;
default: /* Protocol is not recognized */
OpalPrint("%s: ERROR: Protocol (%d) not supported!\n", PROGNAME, proto);
return EINVAL;
}
@ -121,6 +130,8 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
PROGNAME);
}
}
break;
case TCP_PROTOCOL: /* Communication using TCP/IP protocol */
OpalPrint("%s: Calling connect()\n", PROGNAME);
@ -130,6 +141,7 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
OpalPrint("%s: ERROR: Call to connect() failed\n", PROGNAME);
return EIO;
}
break;
}
return EOK;
@ -163,8 +175,8 @@ int RecvPacket(char* DataRecv, int datalength, double timeout)
return -1;
/* Set the descriptor set for the select() call */
FD_ZERO (&sd_set);
FD_SET (sd, &sd_set);
FD_ZERO(&sd_set);
FD_SET(sd, &sd_set);
/* Set the tv structure to the correct timeout value */
tv.tv_sec = (int) timeout;