mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
a lot of cleanup and renames
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@146 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
fee6978139
commit
4f3bacb5be
9 changed files with 106 additions and 47 deletions
|
@ -33,29 +33,30 @@
|
|||
# define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* This is the message format */
|
||||
#include "msg_types.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 "AsyncApi.h"
|
||||
#include "AsyncIPUtils.h"
|
||||
|
||||
/* This is the message format */
|
||||
#include "MsgFormat.h"
|
||||
#include "Socket.h"
|
||||
#include "Interface.h"
|
||||
|
||||
/* 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 */
|
||||
#define ASYNC_SHMEM_NAME argv[1]
|
||||
#define ASYNC_SHMEM_SIZE atoi(argv[2])
|
||||
#define PRINT_SHMEM_NAME argv[3]
|
||||
#define ASYNC_SHMEM_NAME argv[1]
|
||||
#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 MAXSENDSIZE 64
|
||||
#define MAXRECVSIZE 64
|
||||
#define MAX_SEND_SIZE 64
|
||||
#define MAX_RECV_SIZE 64
|
||||
|
||||
void *SendToIPPort(void * arg)
|
||||
static void *SendToIPPort(void *arg)
|
||||
{
|
||||
int SendID = 1;
|
||||
int i, n;
|
||||
|
@ -106,14 +107,12 @@ void *SendToIPPort(void * arg)
|
|||
OpalGetAsyncSendIconData(mdldata, mdldata_size, SendID);
|
||||
|
||||
/******* FORMAT TO SPECIFIC PROTOCOL HERE *****************************/
|
||||
|
||||
// msg.dev_id = SendID; /* Use the SendID as a device ID here */
|
||||
msg.sequence++;
|
||||
msg.length = mdldata_size / sizeof(double);
|
||||
|
||||
for (i = 0; i < msg.length; i++)
|
||||
msg.data[i] = (float) mdldata[i];
|
||||
|
||||
/**********************************************************************/
|
||||
|
||||
/* Perform the actual write to the ip port */
|
||||
|
@ -144,7 +143,7 @@ void *SendToIPPort(void * arg)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void *RecvFromIPPort(void * arg)
|
||||
static void *RecvFromIPPort(void *arg)
|
||||
{
|
||||
int RecvID = 1;
|
||||
int i, n;
|
||||
|
@ -162,14 +161,21 @@ void *RecvFromIPPort(void * arg)
|
|||
OpalGetNbAsyncRecvIcon(&nbRecv);
|
||||
if (nbRecv >= 1) {
|
||||
do {
|
||||
memset(&msg, 0, sizeof(msg));
|
||||
|
||||
/******* FORMAT TO SPECIFIC PROTOCOL HERE ******************************
|
||||
* Modify this section if your protocol needs to receive more than one
|
||||
* packet to process the data */
|
||||
/******* FORMAT TO SPECIFIC PROTOCOL HERE ******************************/
|
||||
msg_size = sizeof(msg);
|
||||
n = RecvPacket((char *) &msg, msg_size, 1.0);
|
||||
|
||||
if (msg.version != MSG_VERSION) {
|
||||
OpalPrint("%s: Received message with unknown version. Skipping..\n", PROGNAME);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (msg.type != MSG_TYPE_DATA) {
|
||||
OpalPrint("%s: Received no data. Skipping..\n", PROGNAME);
|
||||
continue;
|
||||
}
|
||||
|
||||
msg_size = 4 * (msg.length + 1);
|
||||
/***********************************************************************/
|
||||
|
||||
|
@ -199,13 +205,13 @@ void *RecvFromIPPort(void * arg)
|
|||
/* Get the number of signals to send back to the model */
|
||||
OpalGetAsyncRecvIconDataLength(&mdldata_size, RecvID);
|
||||
|
||||
if (mdldata_size / sizeof(double) > MAX_VALUES) {
|
||||
if (mdldata_size / sizeof(double) > MAX_RECV_VALUES) {
|
||||
OpalPrint("%s: Number of signals for RecvID=%d (%d) exceeds allowed maximum (%d)\n",
|
||||
PROGNAME, RecvID, mdldata_size/sizeof(double), MAXRECVSIZE);
|
||||
PROGNAME, RecvID, mdldata_size / sizeof(double), MAX_RECV_SIZE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mdldata_size > msg.length * sizeof(float)) {
|
||||
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);
|
||||
}
|
||||
|
@ -232,9 +238,11 @@ void *RecvFromIPPort(void * arg)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Opal_GenAsyncParam_Ctrl IconCtrlStruct;
|
||||
int err;
|
||||
pthread_t tid_send, tid_recv;
|
||||
|
||||
Opal_GenAsyncParam_Ctrl IconCtrlStruct;
|
||||
|
||||
pthread_t tid_send, tid_recv;
|
||||
pthread_attr_t attr_send, attr_recv;
|
||||
|
||||
/* Check for the proper arguments to the program */
|
|
@ -6,11 +6,9 @@ TARGET_OPALRT_ROOT = /usr/opalrt
|
|||
|
||||
# QNX v6.x
|
||||
ifeq "$(SYSNAME)" "nto"
|
||||
|
||||
CC = gcc
|
||||
LD = $(CC)
|
||||
TARGET_LIB = -lsocket
|
||||
|
||||
TARGET_LIB = -lsocket
|
||||
endif
|
||||
|
||||
# RedHawk Linux
|
||||
|
@ -38,7 +36,6 @@ ifeq "$(shell uname)" "Linux"
|
|||
endif
|
||||
|
||||
TARGET_LIB = -lpthread -lm -ldl -lutil -lrt $(RH_LIBS) $(INTEL_LIBS)
|
||||
|
||||
endif
|
||||
|
||||
# Support for debugging symbols
|
||||
|
@ -50,12 +47,11 @@ else
|
|||
LD_DEBUG_OPTS=
|
||||
endif
|
||||
|
||||
|
||||
INCLUDES = -I.
|
||||
LIBPATH = -L.
|
||||
CC_OPTS =
|
||||
LD_OPTS =
|
||||
OBJS = ${PROGRAM}.o
|
||||
OBJS = ${PROGRAM}.o Sched.o Interface.o Socket.o
|
||||
|
||||
ADDLIB = -lOpalCore -lOpalUtils
|
||||
LIBS = -lOpalAsyncApiCore $(ADDLIB) $(TARGET_LIB)
|
|
@ -1,4 +1,11 @@
|
|||
/** OPAL Interface setup
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @file
|
||||
*/
|
||||
|
||||
#include "Interface.h"
|
||||
|
||||
int if_setup(const char *op, const char *iface, const char *addr)
|
||||
{
|
13
clients/opal/models/AsyncIP_sl/src/Interface.h
Normal file
13
clients/opal/models/AsyncIP_sl/src/Interface.h
Normal file
|
@ -0,0 +1,13 @@
|
|||
/** OPAL Interface setup
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @file
|
||||
*/
|
||||
|
||||
#ifndef _INTERFACE_H_
|
||||
#define _INTERFACE_H_
|
||||
|
||||
int if_setup(const char *op, const char *iface, const char *addr)
|
||||
|
||||
#endif /* _INTERFACE_H_ */
|
|
@ -7,6 +7,7 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
#include "Sched.h"
|
||||
|
||||
#if defined(__QNXNTO__)
|
||||
# include <process.h>
|
15
clients/opal/models/AsyncIP_sl/src/Sched.h
Normal file
15
clients/opal/models/AsyncIP_sl/src/Sched.h
Normal file
|
@ -0,0 +1,15 @@
|
|||
/** Configure Scheduler
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @author Mathieu Dubé-Dallaire
|
||||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @copyright 2003, OPAL-RT Technologies inc
|
||||
* @file
|
||||
*/
|
||||
|
||||
#ifndef _SCHED_H_
|
||||
#define _SCHED_H_
|
||||
|
||||
int AssignProcToCpu0(void);
|
||||
|
||||
#endif /* _SCHED_H_ */
|
|
@ -12,15 +12,6 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
#ifndef OPAL_IP_H
|
||||
#define OPAL_IP_H
|
||||
|
||||
#ifndef PROGNAME
|
||||
#define PROGNAME "AsyncIPUtils"
|
||||
#endif
|
||||
/* Modify this version line if you make changes to this file */
|
||||
#define VERSION "Opal-RT_20060524"
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -29,15 +20,9 @@
|
|||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#define RT
|
||||
#include "Socket.c"
|
||||
#include "OpalPrint.h"
|
||||
#include "AsyncApi.h"
|
||||
#include "OpalGenAsyncParamCtrl.h"
|
||||
#pragma pack()
|
||||
|
||||
#define UDP_PROTOCOL 1
|
||||
#define TCP_PROTOCOL 2
|
||||
#define EOK 0
|
||||
|
||||
/* Globals variables */
|
||||
struct sockaddr_in send_ad; /* Send address */
|
||||
|
@ -98,7 +83,7 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
return EIO;
|
||||
}
|
||||
else
|
||||
OpalPrint("%s: Local Port : %d\n", PROGNAME, (int)IconCtrlStruct.FloatParam[2]);
|
||||
OpalPrint("%s: Local Port : %d\n", PROGNAME, (int) IconCtrlStruct.FloatParam[2]);
|
||||
|
||||
switch (proto) {
|
||||
case UDP_PROTOCOL: /* Communication using UDP/IP protocol */
|
||||
|
@ -224,5 +209,3 @@ int CloseSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* OPAL_IP_H */
|
36
clients/opal/models/AsyncIP_sl/src/Socket.h
Normal file
36
clients/opal/models/AsyncIP_sl/src/Socket.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/** Helper functions for socket
|
||||
*
|
||||
* Code example of an asynchronous program. This program is started
|
||||
* by the asynchronous controller and demonstrates how to send and
|
||||
* receive data to and from the asynchronous icons and a UDP or TCP
|
||||
* port.
|
||||
*
|
||||
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
* @author Mathieu Dubé-Dallaire
|
||||
* @copyright 2014, Institute for Automation of Complex Power Systems, EONERC
|
||||
* @copyright 2003, OPAL-RT Technologies inc
|
||||
* @file
|
||||
*/
|
||||
|
||||
#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"
|
||||
|
||||
#define UDP_PROTOCOL 1
|
||||
#define TCP_PROTOCOL 2
|
||||
#define EOK 0
|
||||
|
||||
int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct);
|
||||
|
||||
int SendPacket(char* DataSend, int datalength);
|
||||
|
||||
int RecvPacket(char* DataRecv, int datalength, double timeout);
|
||||
|
||||
int CloseSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct);
|
||||
|
||||
#endif /* _SOCKET_H_ */
|
Loading…
Add table
Reference in a new issue