-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsocket_api.h
150 lines (105 loc) · 3.89 KB
/
socket_api.h
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
C/C++ API for socket-based programmatic access to Matlab
Written by Emo Todorov
Edited by Anton Sobinov
Copyright (C) 2017 Roboti LLC
Modifications copyright (C) 2017 Anton Sobinov
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
// this is a C API
#if defined(__cplusplus)
extern "C" {
#endif
// API return codes
typedef enum
{
saOK = 0, // success
saERROR // error; call sa_last_result for description
} saResult;
// message codes
typedef enum
{
// client-to-server, standard API
mjCOM_INFO = 1,
mjCOM_CLOSE,
// get dynamic data
mjCOM_GETSQUARES,
} mjtComCode;
//--------------------------- API functions ---------------------------------------------
// change default port - workaround for sa_connect
saResult sa_change_port(const char* port);
// connect to specified host (name or IP address, NULL: local host); port is ignored
saResult sa_connect(const char* host, const char* port);
// connect to specified host (name or IP address, NULL: local host); port is ignored
saResult sa_connect_server(const char* host, const char* port);
// close connection to simulator
saResult sa_close(void);
// text description of last saResult returned by any API function call
const char* sa_last_result(void);
//-------------------------------- constants --------------------------------------------
// predefined size for array allocation
#define mjMAXSZ 1000
// API return codes
typedef enum
{
mjCOM_OK = 0, // success
// server-to-client errors
mjCOM_BADSIZE = -1, // data has invalid size
mjCOM_BADINDEX = -2, // object has invalid index
mjCOM_BADTYPE = -3, // invalid object type
mjCOM_BADCOMMAND = -4, // unknown command
mjCOM_CANNOTSEND = -5, // could not send data
mjCOM_CANNOTRECV = -6, // could not receive data
mjCOM_TIMEOUT = -7, // receive timeout
mjCOM_BADPORT = -8, // bad port specified
// client-side errors
mjCOM_NOCONNECTION = -9, // connection not established
mjCOM_CONNECTED = -10, // already connected
} mjtResult;
//------------------------------- mj api
mjtResult mj_connect(const char* host);
mjtResult mj_close(void);
mjtResult mj_result(void);
mjtResult mj_respond(void);
//------------------------- Data structures -----------------
// Info about build number ??
struct _mjInfo
{
int n;
};
typedef struct _mjInfo mjInfo;
// data that is sent as a request from Matlab side
struct _mjRequestSquares
{
int n; // number of elements
float dat[mjMAXSZ];
};
typedef struct _mjRequestSquares mjRequestSquares;
// data that the server is replying to Matlab with
struct _mjReplySquares
{
int n; // number of elements
float dat[mjMAXSZ];
};
typedef struct _mjReplySquares mjReplySquares;
//--------------------------- API request/reply functions ----------------------
// requests the server, is called on client
mjtResult mj_request_squares(const mjRequestSquares* rqs, mjReplySquares* res);
// reply to a request by server
mjtResult mj_respond_squares(void);
// request information from server
mjtResult mj_request_info(mjInfo* res);
// reply with information
mjtResult mj_respond_info(void);
#if defined(__cplusplus)
}
#endif