Building Controls Virtual Test Bed
simulinkSocket.c
Go to the documentation of this file.
1 
21 #include "simulinkSocket.h"
22 
23 int16_T establishBSDSocket(int16_T* flag){
24  int retVal;
25  if ( *flag == 0 ){
26  retVal = establishclientsocket("socket.cfg");
27  }
28  else
29  retVal = *flag;
30  return retVal;
31 }
32 
34  int16_T* flaWri,
35  int16_T* flaRea,
36  int16_T* nDblWri,
37  double* simTimWri,
38  double dblValWri[],
39  double* simTimRea,
40  double dblValRea[]){
41  int mySockfd = *sockfd;
42  int myFlaWri = *flaWri;
43  int myFlaRea = 0;
44  int myNDblWri = *nDblWri;
45  int nDblRea;
46  int retVal = exchangedoubleswithsocket(&mySockfd,
47  &myFlaWri, &myFlaRea,
48  &myNDblWri,
49  &nDblRea,
50  simTimWri,
51  dblValWri,
52  simTimRea,
53  dblValRea);
54  /* NDBLMAX is defined in lib/defines.h */
55  if ( nDblRea > NDBLMAX ){
56  fprintf(stderr, "simulinkSocket: Read too many double values.\n");
57  fprintf(stderr, " Received nDblRea = %d, maximum is %d\n", nDblRea, NDBLMAX);
58  fprintf(stderr, " To fix, change NDBLMAX in lib/defines.h and recompile simulink interface.\n");
59  retVal = -1;
60  }
61  *flaRea = myFlaRea;
62  return retVal;
63 }
64 
65 int16_T closeBSDSocket(int16_T* sockfd, int16_T* doClose){
66  if ( (0 == *doClose) || (*sockfd < 0) ){ /* do not close socket */
67  return 0;
68  }
69  else{
70  int mySockfd = *sockfd;
71  return closeipc(&mySockfd);
72  }
73 }
function sockfd
int exchangedoubleswithsocket(const int *sockfd, const int *flaWri, int *flaRea, const int *nDblWri, int *nDblRea, double *simTimWri, double dblValWri[], double *simTimRea, double dblValRea[])
Exchanges data with the socket.
int16_T closeBSDSocket(int16_T *sockfd, int16_T *doClose)
int16_T exchangeDoublesWithBSDSocket(int16_T *sockfd, int16_T *flaWri, int16_T *flaRea, int16_T *nDblWri, double *simTimWri, double dblValWri[], double *simTimRea, double dblValRea[])
int establishclientsocket(const char *const docname)
Establishes a connection to the socket.
function retVal
Definition: closeIPC.m:1
fprintf([' ', 'Trying to send client error from MATLAB to the BCVTB.'])
end Get return values from pointers flaRea
int closeipc(int *sockfd)
Closes the inter process communication socket.
Methods for interfacing Simulink using BSD sockets.
int16_T establishBSDSocket(int16_T *flag)
#define NDBLMAX
Maximum number of double values that can be exchanged by Simulink.
Definition: defines.h:33