-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfunDefinitions.h
239 lines (216 loc) · 7.58 KB
/
sfunDefinitions.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
* This file is part of EasyLink Library.
*
* Copyright (c) 2014 FEMTO-ST, ENSMM, UFC, CNRS.
*
* License: GNU General Public License 3
*
* Author: Guillaume J. Laurent
*
*/
//------------------------------------------------------------------------------
#define MDL_CHECK_PARAMETERS
static void mdlCheckParameters(SimStruct *S) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlCheckParameters ------------------------------\n");
#endif
try {
Block::setSimStruct(S);
Block::checkParametersSizes();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_INITIALIZE_SIZES
static void mdlInitializeSizes(SimStruct *S) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlInitializeSizes ------------------------------\n");
#endif
try {
Block::setSimStruct(S);
//Block::initializeParameterPortSizes();
Block::checkParametersSizes();
Block::initializeInputPortSizes();
Block::initializeOutputPortSizes();
Block::initializeStatePortSizes();
ssSetNumRWork(S, 0);
ssSetNumIWork(S, 0);
ssSetNumPWork(S, 1);
Block::initializeNumberSampleTimes();
Block::initializeOptions();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//---------------------------------------------------------------------------
#define MDL_SET_INPUT_PORT_DIMENSION_INFO
static void mdlSetInputPortDimensionInfo(SimStruct *S, int port, const DimsInfo_T *dimsInfo) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlSetInputPortDimensionInfo --------------------\n");
#endif
try {
Block::setSimStruct(S);
if (dimsInfo->numDims == 1) {
Block::checkInputPortFinalSizes(port, dimsInfo->width, 1);
} else if (dimsInfo->numDims == 2) {
Block::checkInputPortFinalSizes(port, dimsInfo->dims[0], dimsInfo->dims[1]);
} else {
throw std::runtime_error("Input port dimensions greater than two are not supported by easylink.");
}
if (!ssSetInputPortDimensionInfo(S, port, dimsInfo)) return;
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//---------------------------------------------------------------------------
#define MDL_SET_OUTPUT_PORT_DIMENSION_INFO
static void mdlSetOutputPortDimensionInfo(SimStruct *S, int port, const DimsInfo_T *dimsInfo) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlSetOutputPortDimensionInfo -------------------\n");
#endif
try {
Block::setSimStruct(S);
if (dimsInfo->numDims == 1) {
Block::checkOutputPortFinalSizes(port, dimsInfo->width, 1);
} else if (dimsInfo->numDims == 2) {
Block::checkOutputPortFinalSizes(port, dimsInfo->dims[0], dimsInfo->dims[1]);
} else {
throw std::runtime_error("Output port dimensions greater than two are not supported by easylink.");
}
if (!ssSetOutputPortDimensionInfo(S, port, dimsInfo)) return;
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_INITIALIZE_SAMPLE_TIME
static void mdlInitializeSampleTimes(SimStruct *S) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlInitializeSampleTimes ------------------------\n");
#endif
try {
Block::setSimStruct(S);
Block::initializeSampleTimes();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_START
static void mdlStart(SimStruct *S) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlStart ----------------------------------------\n");
#endif
Block *block = new Block;
ssGetPWork(S)[0] = (void *) block;
try {
Block::setSimStruct(S);
block->start();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_OUTPUTS
static void mdlOutputs(SimStruct *S, int tid) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlOutputs at time %f ---------------------------\n", Block::getSimulationTime());
#endif
Block *block = (Block *) ssGetPWork(S)[0];
try {
Block::setSimStruct(S);
block->outputs();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_DERIVATIVES
static void mdlDerivatives(SimStruct *S) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlDerivatives ----------------------------------\n");
#endif
Block *block = (Block *) ssGetPWork(S)[0];
try {
Block::setSimStruct(S);
block->derivatives();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_ZERO_CROSSINGS
static void mdlZeroCrossings(SimStruct *S) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlZeroCrossings --------------------------------\n");
#endif
Block *block = (Block *) ssGetPWork(S)[0];
try {
Block::setSimStruct(S);
block->zeroCrossings();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_UPDATE
static void mdlUpdate(SimStruct *S, int tid) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlUpdate ---------------------------------------\n");
#endif
Block *block = (Block *) ssGetPWork(S)[0];
try {
Block::setSimStruct(S);
block->update();
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
}
//------------------------------------------------------------------------------
#define MDL_TERMINATE
static void mdlTerminate(SimStruct *S) {
#ifdef __TEST__
printf("EasyLink test message: entering mdlTerminate ------------------------------------\n");
#endif
Block *block = (Block *) ssGetPWork(S)[0];
try {
Block::setSimStruct(S);
block->terminate();
delete block;
} catch (std::exception const& e) {
strcpy(ERROR_MSG_BUFFER, e.what());
ssSetErrorStatus(S, ERROR_MSG_BUFFER);
return;
}
#ifdef __TEST__
printf("EasyLink test message: allocation number = %i.\n", Array<double>::allocationNumber);
#endif
}
//------------------------------------------------------------------------------
#ifdef MATLAB_MEX_FILE
#include "simulink.c"
#else
#include "cg_sfun.h"
#endif
//------------------------------------------------------------------------------