1 | /*
|
2 | * sfuntmpl_basic.c: Basic 'C' template for a level 2 S-function.
|
3 | *
|
4 | * Copyright 1990-2013 The MathWorks, Inc.
|
5 | */
|
6 |
|
7 |
|
8 | /*
|
9 | * You must specify the S_FUNCTION_NAME as the name of your S-function
|
10 | * (i.e. replace sfuntmpl_basic with the name of your S-function).
|
11 | */
|
12 |
|
13 | #define S_FUNCTION_NAME odometrie
|
14 | #define S_FUNCTION_LEVEL 2
|
15 |
|
16 | /*
|
17 | * Need to include simstruc.h for the definition of the SimStruct and
|
18 | * its associated macro definitions.
|
19 | */
|
20 | #include "simstruc.h"
|
21 |
|
22 | #include <sys/types.h>
|
23 | #include <sys/stat.h>
|
24 | #include <fcntl.h>
|
25 | //#include <termios.h>
|
26 | #include <stdio.h>
|
27 | #include <stdlib.h>
|
28 | #include <string.h>
|
29 | //#include <unistd.h>
|
30 | #include <math.h>
|
31 |
|
32 |
|
33 |
|
34 | static void mdlInitializeSizes(SimStruct *S)
|
35 | {
|
36 | int_T nInputPorts = 0; /* number of input ports */
|
37 | int_T nOutputPorts = 1; /* number of output ports */
|
38 | int_T needsInput = 0; /* direct feed through */
|
39 |
|
40 | int_T inputPortIdx = 0;
|
41 | int_T outputPortIdx = 0;
|
42 |
|
43 | FILE *fmouse;
|
44 | char b[3];
|
45 |
|
46 | ssSetNumSFcnParams(S, 2); /* Number of expected parameters */
|
47 | if (ssGetNumSFcnParams(S) != ssGetSFcnParamsCount(S))
|
48 | return;
|
49 | }
|
50 |
|
51 |
|
52 | ssSetNumContStates( S, 0); /* number of continuous states */
|
53 | ssSetNumDiscStates( S, 0); /* number of discrete states */
|
54 |
|
55 |
|
56 | if (!ssSetNumInputPorts(S, nInputPorts)) return;
|
57 |
|
58 | if(!ssSetInputPortDimensionInfo(S, inputPortIdx, DYNAMIC_DIMENSION)) return;
|
59 |
|
60 | ssSetInputPortDirectFeedThrough(S, inputPortIdx, needsInput);
|
61 |
|
62 |
|
63 | if (!ssSetNumOutputPorts(S, nOutputPorts)) return;
|
64 |
|
65 | if(!ssSetOutputPortDimensionInfo(S,outputPortIdx,DYNAMIC_DIMENSION)) return;
|
66 |
|
67 |
|
68 | ssSetNumSampleTimes( S, 1); /* number of sample times */
|
69 |
|
70 | /*
|
71 | * Set size of the work vectors.
|
72 | */
|
73 | ssSetNumRWork( S, 0); /* number of real work vector elements */
|
74 | ssSetNumIWork( S, 0); /* number of integer work vector elements*/
|
75 | ssSetNumPWork( S, 0); /* number of pointer work vector elements*/
|
76 | ssSetNumModes( S, 0); /* number of mode work vector elements */
|
77 | ssSetNumNonsampledZCs( S, 0); /* number of nonsampled zero crossings */
|
78 |
|
79 | ssSetSimStateCompliance(S, USE_DEFAULT_SIM_STATE);
|
80 |
|
81 | ssSetOptions( S, 0); /* general options (SS_OPTION_xx) */
|
82 |
|
83 | } /* end mdlInitializeSizes */
|
84 |
|
85 |
|
86 |
|
87 | static void mdlInitializeSampleTimes(SimStruct *S)
|
88 | {
|
89 | ssSetSampleTime(S, 0, CONTINUOUS_SAMPLE_TIME);
|
90 | ssSetOffsetTime(S, 0, 0.0);
|
91 |
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 | #define MDL_INITIALIZE_CONDITIONS /* Change to #undef to remove function */
|
97 | #if defined(MDL_INITIALIZE_CONDITIONS)
|
98 |
|
99 | static void mdlInitializeConditions(SimStruct *S)
|
100 | {
|
101 | }
|
102 | #endif /* MDL_INITIALIZE_CONDITIONS */
|
103 |
|
104 |
|
105 |
|
106 | #define MDL_START /* Change to #undef to remove function */
|
107 | #if defined(MDL_START)
|
108 |
|
109 | static void mdlStart(SimStruct *S)
|
110 | {
|
111 | FILE *fmouse;
|
112 | char b[3];
|
113 | }
|
114 | #endif /* MDL_START */
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | static void mdlOutputs(SimStruct *S, int_T tid)
|
120 | {
|
121 | b[1] = u[0];
|
122 | }
|
123 |
|
124 |
|
125 |
|
126 | #define MDL_UPDATE /* Change to #undef to remove function */
|
127 | #if defined(MDL_UPDATE)
|
128 |
|
129 | static void mdlUpdate(SimStruct *S, int_T tid)
|
130 | {
|
131 | fread(b,sizeof(char),3,fmouse);
|
132 | }
|
133 | #endif /* MDL_UPDATE */
|
134 |
|
135 |
|
136 |
|
137 | #define MDL_DERIVATIVES /* Change to #undef to remove function */
|
138 | #if defined(MDL_DERIVATIVES)
|
139 | static void mdlDerivatives(SimStruct *S)
|
140 | {
|
141 | }
|
142 | #endif /* MDL_DERIVATIVES */
|
143 |
|
144 |
|
145 |
|
146 | static void mdlTerminate(SimStruct *S)
|
147 | {
|
148 | }
|
149 |
|
150 |
|
151 | /*=============================*
|
152 | * Required S-function trailer *
|
153 | *=============================*/
|
154 |
|
155 | #ifdef MATLAB_MEX_FILE /* Is this file being compiled as a MEX-file? */
|
156 | #include "simulink.c" /* MEX-file interface mechanism */
|
157 | #else
|
158 | #include "cg_sfun.h" /* Code generation registration function */
|
159 | #endif
|