-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveDynamicBodies.c
More file actions
58 lines (45 loc) · 1.18 KB
/
moveDynamicBodies.c
File metadata and controls
58 lines (45 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "connectToServer.h"
#include <stdio.h>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#endif
#define MAXLENGTH 500
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
char buf[MAXLENGTH];
double time;
double *pind;
int sockd;
/* Check for proper number of arguments */
if (nrhs > 1) {
mexErrMsgTxt("moveDynamicBodies takes at most one argument.");
} else if (nlhs > 1) {
mexErrMsgTxt("moveDynamicBodies takes at most one output argument.");
}
sockd = ConnectTo("localhost",4765);
if (sockd < 0)
mexErrMsgTxt("Could not connect");
if (nrhs == 1) {
sprintf(buf,"moveDynamicBodies %le\n",mxGetScalar(prhs[0]));
Writeline(sockd,buf,strlen(buf));
}
else Writeline(sockd,"moveDynamicBodies\n",18);
Readline(sockd,buf,MAXLENGTH);
if (!strncmp(buf,"Error",5)) {
CloseConnection(sockd);
mexErrMsgTxt(buf);
}
sscanf(buf,"%lf\n",&time);
plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
pind = mxGetPr(plhs[0]);
pind[0] = time;
CloseConnection(sockd);
return;
}