mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
fixed whitespaces
git-svn-id: https://zerberus.eonerc.rwth-aachen.de:8443/svn/s2ss/trunk@138 8ec27952-4edc-4aab-86aa-e87bb2611832
This commit is contained in:
parent
6efe8e810f
commit
7de076e7ea
2 changed files with 34 additions and 35 deletions
|
@ -119,11 +119,11 @@ void *SendToIPPort(void * arg)
|
|||
struct data_out comdata;
|
||||
int comdata_size;
|
||||
int count = 0;
|
||||
|
||||
|
||||
OpalPrint("%s: SendToIPPort thread started\n", PROGNAME);
|
||||
|
||||
|
||||
OpalGetNbAsyncSendIcon(&nbSend);
|
||||
|
||||
|
||||
if (nbSend >= 1) {
|
||||
do {
|
||||
/* This call unblocks when the 'Data Ready' line of a send icon is asserted. */
|
||||
|
@ -135,7 +135,7 @@ void *SendToIPPort(void * arg)
|
|||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/* No errors encountered yet */
|
||||
OpalSetAsyncSendIconError(0, SendID);
|
||||
|
||||
|
@ -158,7 +158,7 @@ void *SendToIPPort(void * arg)
|
|||
comdata.msg_id++; /* The message ID is just incremented */
|
||||
comdata.msg_len = mdldata_size;
|
||||
// comdata.msg_len = (mdldata_size/sizeof(double)) * sizeof(int); /* If comdata.data was an "int" */
|
||||
|
||||
|
||||
/* In our case, because the data in the packet is in double format
|
||||
* we don't need to cast the data from the model to another format */
|
||||
for (i=0; i < (mdldata_size / sizeof(double)); i++)
|
||||
|
@ -211,11 +211,11 @@ void *RecvFromIPPort (void * arg)
|
|||
int mdldata_size;
|
||||
struct data_in comdata;
|
||||
int comdata_size;
|
||||
|
||||
|
||||
OpalPrint("%s: RecvFromIPPort thread started\n", PROGNAME);
|
||||
|
||||
|
||||
OpalGetNbAsyncRecvIcon(&nbRecv);
|
||||
|
||||
|
||||
if (nbRecv >= 1) {
|
||||
do {
|
||||
memset (&comdata, 0, sizeof(comdata));
|
||||
|
@ -291,38 +291,38 @@ void *RecvFromIPPort (void * arg)
|
|||
else {
|
||||
OpalPrint("%s: RecvFromIPPort: No reception block for this controller. Stopping thread.\n", PROGNAME);
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Opal_GenAsyncParam_Ctrl IconCtrlStruct;
|
||||
int err;
|
||||
pthread_t tid_send, tid_recv;
|
||||
pthread_attr_t attr_send, attr_recv;
|
||||
|
||||
|
||||
/* Check for the proper arguments to the program */
|
||||
if (argc < 4) {
|
||||
printf("Invalid Arguments: 1-AsyncShmemName 2-AsyncShmemSize 3-PrintShmemName\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/* Enable the OpalPrint function. This prints to the OpalDisplay. */
|
||||
if (OpalSystemCtrl_Register(PRINT_SHMEM_NAME) != EOK) {
|
||||
printf("%s: ERROR: OpalPrint() access not available\n", PROGNAME);
|
||||
exit(EXIT_FAILURE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
/* Open Share Memory created by the model. */
|
||||
if ((OpalOpenAsyncMem(ASYNC_SHMEM_SIZE, ASYNC_SHMEM_NAME)) != EOK) {
|
||||
OpalPrint("%s: ERROR: Model shared memory not available\n", PROGNAME);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
/* For Redhawk, Assign this process to CPU 0 in order to support partial XHP */
|
||||
AssignProcToCpu0();
|
||||
|
||||
AssignProcToCpu0();
|
||||
|
||||
/* Get IP Controler Parameters (ie: ip address, port number...) and
|
||||
* initialize the device on the QNX node. */
|
||||
memset(&IconCtrlStruct, 0, sizeof(IconCtrlStruct));
|
||||
|
@ -330,7 +330,7 @@ int main(int argc, char *argv[])
|
|||
OpalPrint("%s: ERROR: Could not get controller parameters (%d).\n", PROGNAME, err);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
if (InitSocket(IconCtrlStruct) != EOK) {
|
||||
OpalPrint("%s: ERROR: Initialization failed.\n", PROGNAME);
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -355,4 +355,3 @@ int main(int argc, char *argv[])
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
OpalPrint("%s: ERROR: Protocol (%d) not supported!\n", PROGNAME, proto);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
|
||||
OpalPrint("%s: Remote Address : %s\n", PROGNAME, IconCtrlStruct.StringParam[0]);
|
||||
OpalPrint("%s: Remote Port : %d\n", PROGNAME, (int)IconCtrlStruct.FloatParam[1]);
|
||||
|
||||
|
@ -76,19 +76,19 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
OpalPrint("%s: ERROR: Could not open socket\n", PROGNAME);
|
||||
return EIO;
|
||||
}
|
||||
|
||||
|
||||
/* Set the structure for the remote port and address */
|
||||
memset(&send_ad, 0, sizeof(send_ad));
|
||||
send_ad.sin_family = AF_INET;
|
||||
send_ad.sin_addr.s_addr = inet_addr(IconCtrlStruct.StringParam[0]);
|
||||
send_ad.sin_port = htons((u_short)IconCtrlStruct.FloatParam[1]);
|
||||
|
||||
|
||||
/* Set the structure for the local port and address */
|
||||
memset(&recv_ad, 0, sizeof(recv_ad));
|
||||
recv_ad.sin_family = AF_INET;
|
||||
recv_ad.sin_addr.s_addr = INADDR_ANY;
|
||||
recv_ad.sin_port = htons((u_short)IconCtrlStruct.FloatParam[2]);
|
||||
|
||||
|
||||
/* Bind local port and address to socket. */
|
||||
if (bind(sd, (struct sockaddr *)&recv_ad, sizeof(struct sockaddr_in)) == -1) {
|
||||
OpalPrint("%s: ERROR: Could not bind local port to socket\n", PROGNAME);
|
||||
|
@ -96,7 +96,7 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
}
|
||||
else
|
||||
OpalPrint("%s: Local Port : %d\n", PROGNAME, (int)IconCtrlStruct.FloatParam[2]);
|
||||
|
||||
|
||||
switch (proto) {
|
||||
case UDP_PROTOCOL: /* Communication using UDP/IP protocol */
|
||||
/* If sending to a multicast address */
|
||||
|
@ -118,7 +118,7 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
if ((inet_addr(IconCtrlStruct.StringParam[1]) & inet_addr("240.0.0.0")) == inet_addr("224.0.0.0")) {
|
||||
mreq.imr_multiaddr.s_addr = inet_addr(IconCtrlStruct.StringParam[1]);
|
||||
mreq.imr_interface.s_addr = INADDR_ANY;
|
||||
|
||||
|
||||
/* Have the multicast socket join the multicast group */
|
||||
if (setsockopt(sd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq, sizeof(mreq)) == -1) {
|
||||
OpalPrint("%s: ERROR: Could not join multicast group (%d)\n", PROGNAME, errno);
|
||||
|
@ -138,10 +138,10 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
|
||||
/* Connect to server to start data transmission */
|
||||
rc = connect(sd, (struct sockaddr *)&send_ad, sizeof(send_ad));
|
||||
if (rc < 0) {
|
||||
if (rc < 0) {
|
||||
OpalPrint("%s: ERROR: Call to connect() failed\n", PROGNAME);
|
||||
return EIO;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EOK;
|
||||
|
@ -150,7 +150,7 @@ int InitSocket(Opal_GenAsyncParam_Ctrl IconCtrlStruct)
|
|||
int SendPacket (char* DataSend, int datalength)
|
||||
{
|
||||
int err;
|
||||
|
||||
|
||||
if(sd < 0)
|
||||
return -1;
|
||||
|
||||
|
@ -159,7 +159,7 @@ int SendPacket (char* DataSend, int datalength)
|
|||
err = send (sd, DataSend, datalength, 0);
|
||||
else
|
||||
err = sendto (sd, DataSend, datalength, 0, (struct sockaddr *)&send_ad, sizeof(send_ad));
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -170,14 +170,14 @@ int RecvPacket (char* DataRecv, int datalength, double timeout)
|
|||
socklen_t client_ad_size = sizeof(client_ad);
|
||||
fd_set sd_set;
|
||||
struct timeval tv;
|
||||
|
||||
|
||||
if (sd < 0)
|
||||
return -1;
|
||||
|
||||
|
||||
/* Set the descriptor set for the select() call */
|
||||
FD_ZERO (&sd_set);
|
||||
FD_SET (sd, &sd_set);
|
||||
|
||||
|
||||
/* Set the tv structure to the correct timeout value */
|
||||
tv.tv_sec = (int)(timeout);
|
||||
tv.tv_usec = (int)((timeout - tv.tv_sec)*1000000);
|
||||
|
@ -199,16 +199,16 @@ int RecvPacket (char* DataRecv, int datalength, double timeout)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Clear the DataRecv array (in case we receive an incomplete packet) */
|
||||
memset (DataRecv, 0, datalength);
|
||||
|
||||
|
||||
/* Perform the reception */
|
||||
if (proto == TCP_PROTOCOL)
|
||||
len = recv (sd, DataRecv, datalength, 0);
|
||||
else
|
||||
len = recvfrom (sd, DataRecv, datalength, 0, (struct sockaddr *)&client_ad, &client_ad_size);
|
||||
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue